定制 m1lt0n/delegator 二次开发

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

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

m1lt0n/delegator

最新稳定版本:1.1.0

Composer 安装命令:

composer require m1lt0n/delegator

包简介

Simple Delegator for PHP 5.4+

README 文档

README

Build Status

Delegator

A simple delegation mechanism for objects.

Delegator is a simple library that allows delegation of methods from an object to others. It can be useful in combination with implementing Delegators, where one can partly decorate an object and partly delegate to the original, undecorated object.

Εxample

<?php

use Delegator\DelegatorInterface;

// Assume we have a Person class
class Person implements DelegatorInterface
{
    use \Delegator\DelegatorTrait;

    // Implement the delegateMap method. This is the only requirement
    // of the DelegatorInterface
    public function delegateMap()
    {
        return [
            'address' => [ 'fullAddress' ],
            'settings' => static::ANY,
        ];
    }

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

class Address
{
    protected $street;
    protected $number;
    protected $city;

    public function __construct($street, $number, $city)
    {
        $this->street = $street;
        $this->number = $number;
        $this->city = $city;
    }

    public function fullAddress()
    {
        return "{$this->number}, {$this->street}, {$this->city}";
    }
}

class Settings
{
    public function all()
    {
        return 'all settings';
    }

    public function something()
    {
        return 'some setting';
    }
}

// Simply by using the DelegatorTrait and implementing the delegateMap method,
// we can now delegate calls to the mapped delegates.
$address = new Address('Percy str.', 9, 'London');
$settings = new Settings();
$me = new Person($address, $settings);

echo $me->fullAddress(); // this will be delegated to $me->address->fullAddress();
echo $me->all(); // this will be delegated to $me->settings->all();

// this is equivalent to $me->address->fullAddress, but we have simplified
// our API and hide the internals, while ensuring separation of concerns and
// limited responsibility for each class.

Note: Several delegates can be assigned in the mapping.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固