2017 © Pedro Peláez
 

library mixin

mixin for php

image

chenqd/mixin

mixin for php

  • Tuesday, April 11, 2017
  • by chenqd
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

mixin

这是一个php的简单mixin实现 参考yii中behavior中的实现其实没能避免多继承的缺陷: 优先顺序模糊、继承方法不明确。 其实就技术实现来说并没有太大的难点,这里提供的就是给mixin别名并通过别名调用的方式。, (*1)

为开发便利引入了一些laravel的组件,感谢laravel作者的优良设计, (*2)

使用

main class, (*3)

use chenqd\mixin\HasMixin;

class User {    
    use HasMixin;
    public $name ='shoal';

    public function mixinMap()
    {
        return [            
            'cook' => Cook::class,
            'aa'=> [
                'bb' => Cook::class,
            ],
            'aa.cc'=> [
                Cook2::class, 
                'food'=>'大饼'
            ],
        ];
    }
}

mixin class, (*4)

use chenqd\mixin\MixinTrait;

class Cook {
    use MixinTrait;
    public function done(){
        echo $this->name . " cook a lot of delicious food!\n";
    }
}

class Cook2 {
    use MixinTrait;
    public $food;
    public function __construct($entity, $food){
        $this->entity = $entity;
        $this->food = $food;
    }

    public function done(){
        //do something
        echo $this->name . ' cook a '.$this->food."!\n";
        //do something
    }
}

调用, (*5)

$user = new User();
$user->mixinCall('cook')->done();
$user->mixinCall('aa.bb', 'done');
$user->mixinCall('aa.cc', 'done');

The Versions

11/04 2017

dev-master

9999999-dev

mixin for php

  Sources   Download

The Requires

 

by asmodai

11/04 2017

0.3.1

0.3.1.0

mixin for php

  Sources   Download

The Requires

 

by asmodai

22/03 2017

0.3.0

0.3.0.0

mixin for php

  Sources   Download

The Requires

 

by asmodai