定制 ailixter/gears-overloading 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ailixter/gears-overloading

Composer 安装命令:

composer require ailixter/gears-overloading

包简介

The project, which Gears Overloading.

README 文档

README

install

composer require ailixter/gears-overloading

howtos

How to provide getter/setter overriding for properties

use Ailixter\Gears\Props;

class TestProps
{
    use Props;
    
    private $myPri = 'my private';
    
    public function getMyPri() {
        return '*' . $this->myPri;
    }
}

$test = new TestProps;
echo $test->myPri;
$test->myPri = 'new'; // PropertyException

or, for real (defined) props:

class TestRealProps
{
    use Props;
    
    private $myPri = 'my private';

    protected function propertyGet($prop)
    {
        return $this->{$prop};
    }

    protected function propertySet($prop, $value)
    {
        $this->{$prop} = $value;
    }
}

$test = new TestRealProps;
echo $test->myPri;
$test->myPri = 'new';
echo $test->undefined;     // Notice
$test->undefined = 'some'; // perfectly ok

How to support explicitely defined properties only

use Ailixter\Gears\StrictProps;

class TestStrictProps
{
    use StrictProps;

    private $myPri = 'my private';
}

$test = new TestStrictProps;
echo $test->myPri;
$test->myPri = 'new';
echo $test->undefined;     // PropertyException
$test->undefined = 'some'; // PropertyException

How to create getters and fluent setters for all defined props

use Ailixter\Gears\AutoGetSetProps;

class TestAutoGetSetProps
{
    use AutoGetSetProps;

    private $myPri;
}

$test = TestAutoGetSetProps;
echo $test->setMyPri('new')->getMyPri();

it's also possible to specify defaults in getters:

class TestAutoGetPropsWithDefaults
{
    use Props, AutoGetSetProps;

    private   $myPri;
    protected $myPro;

    public function getMyPro($default = 'static default')
    {
        return $this->existingProperty('myPro', $default);
    }
}

$test = TestAutoGetSetProps;
echo $test->myPro;                       // static default
echo $test->getMyPri('dynamic default'); // dynamic default

How to implement property binding

This enables you to delegate procedural property getting/setting.

use Ailixter\Gears\BoundProps;

class TestBoundProps
{
    use BoundProps;

    /** @var BoundPropsInterface */
    private $myBoundPri;
}

$test = new TestBoundProps;
$test->myBoundPri = new TestPropsBinding;
$test->myBoundPri = 'new';
echo $test->myBoundPri;

How to proxy your objects

use Ailixter\Gears\AbstractProxy;

class TestProxy extends AbstractProxy {}

class TestObject {
    public $myPub = 'my public';
    public function myFn () {
        return __function__;
    }
}

$test = new TestProxy(new TestObject);
echo $test->myPub;
$test->myPub = 'new';
echo $this->myFn();

or

class CustomProxy
{
    use Proxy;

    private $proxiedObject;

    public function __construct($proxiedObject)
    {
        $this->proxiedObject = $proxiedObject;
    }
}

or

class LazyProxy
{
    use Proxy;

    private $obj;

    protected function getProxiedObject()
    {
        if (!$this->obj instanceof ProxiedObject) {
            $this->obj = new ProxiedObject;
        }
        return $this->obj;
    }
}

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-01-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固