wiidoo/support

类支持的例程和方法

0.1.1 2016-04-08 00:00 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:58:39 UTC


README

类支持

安装

通过composer

composer required wiidoo/support

流畅接口

只需将您的类扩展到 Wiidoo\Support\FluentInterface,您就会得到一个使用“流畅接口”方法论的类。

示例

<?php 

use Wiidoo\Support\FluentInterface;

class Example extends FluentInterface
{
    public $foo;
    
    public $bar;
    
    public $active = false;
    
    private $result;
    
    public function join(){
        $this->result = $this->foo . ' ' . $this->bar;
        
        return $this;
    }
    
    public function clear(){
        $this->result = '';
                
        return $this;
    }
    
    public function result(){
        return $this->result;
    }
}

使用上述模型,我们将应用这个类

示例

$example = new Example();
echo $example->foo('I Love')->bar('coffee.')->join()->result()

//saida: 'I love coffee.'

$join = $example->foo('I Love')->bar('coffee.')->join();
echo $join->clear()->result();

//saída ''

布尔属性

如果您想修改一个布尔属性,也就是 bool,只需将其声明为 true 或使用否定前缀来将其声明为 false,例如

$example->active();

dump($example->active); // true;

$example->noActive();

dump($example->active); // false;

否定前缀

以下是否定前缀

no, not, disable

/*
...
    public $active = false;
    public $published = true;
    public $alert = true;
...
*/

$example->active();// true
$example->noPublished();// false
$example->notPublished();// false
$example->disableAlert();// false

实用工具