承接 b2r/property-method-delegator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

b2r/property-method-delegator

Composer 安装命令:

composer require b2r/property-method-delegator

包简介

README 文档

README

Build Status

Delegate method to property instance

Features

  • Delegate methods to target property
  • Resolve method automatically
  • Define method alias

$propertyMethodDelegator structure

  • Key: strign Property name
  • Value: array Method definitions
    • Key: string Method name in LOWER case
    • Value: string|bool Delegate target method name or bool
      • true: Use same name
      • false: DO NOT resolve method if target has public metdhod

Usage

Simple

use b2r\Component\PropertyMethodDelegator\PropertyMethodDelegator;

class ArrayObjectWrapper
{
    use PropertyMethodDelegator;

    protected static $propertyMethodDelegator = [
        'arrayObject' => [],
    ];

    private $arrayObject;

    public function __construct()
    {
        $this->arrayObject = new ArrayObject();
    }
}

$a = new ArrayObjectWrapper();
$a->append(1);
var_dump($a->getArrayCopy()); #=>[1]

Mixed

use b2r\Component\PropertyMethodDelegator\PropertyMethodDelegator;

class Foo
{
    public function doFoo()
    {
        return __METHOD__;
    }

    public function execute()
    {
        return __METHOD__;
    }

    public function run()
    {
        return __METHOD__;
    }

    public function hello() {
        return __METHOD__;
    }

    public function publicHidden()
    {
        return __METHOD__;
    }

    protected function protectedMethod()
    {
        return __METHOD__;
    }
}

class Bar
{
    public function doBar()
    {
        return __METHOD__;
    }

    public function execute()
    {
        return __METHOD__;
    }

    public function run()
    {
        return __METHOD__;
    }

    public function hello() {
        return __METHOD__;
    }

    public function publicHidden()
    {
        return __METHOD__;
    }

    protected function protectedMethod()
    {
        return __METHOD__;
    }
}

class FooBar
{
    use PropertyMethodDelegator;

    protected static $propertyMethodDelegator = [
        'foo' => [
            'execute' => true, // FooBar::execute invoke FooBar::$foo::execute
            'foo' => 'doFoo',  // FooBar::foo invoke FooBar::$foo::doFoo
            'publichidden' => false, // DO NOT invoke FooBar::$foo::publicHidden
        ],
        'bar' => [
            'run' => true, // FooBar::run invoke FooBar::$bar::run
            'bar' => 'doBar', // FooBar::bar invoke FooBar::$bar::doBar
            'publichidden' => false,  // DO NOT invoke FooBar::$bar::publicHidden
        ],
    ];

    protected $foo;
    protected $bar;

    public function __construct()
    {
        $this->foo = new Foo();
        $this->bar = new Bar();
    }
}


$foobar = new FooBar();

echo $foobar->execute(),"\n"; #=>'Foo::execute'
echo $foobar->run(),"\n"; #=>'Bar::run'
echo $foobar->foo(),"\n"; #=>'Foo::doFoo'
echo $foobar->bar(),"\n"; #=>'Bar::doBar'
echo $foobar->doFoo(),"\n"; #=>'Foo::doFoo' Automatically resolved
echo $foobar->doBar(),"\n"; #=>'Bar::doBar' Automatically resolved
echo $foobar->hello(),"\n"; #=>'Foo::hello' Automatically resolved(foo is first)

// `protectedMethod` is protected, cannot resolve delegate method
var_dump($foobar->resolveDelegateMethod('protectedMethod')); #=> false

// `publicHidden` is hidden both foo and bar, cannot resolve delegate method
var_dump($foobar->resolveDelegateMethod('publicHidden')); #=> false

#------------------------------------------------------------

/**
 * Change delegate method resolving order: bar, foo
 */
class BarFoo extends FooBar
{
    protected static $propertyMethodDelegator = [
        'bar' => [],
        'foo' => [],
    ];
}

$barfoo = new BarFoo();
echo $barfoo->hello(),"\n"; #=>'Bar::hello' Automatically resolved(bar is first)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固