PHP code example of chenqd / mixin

1. Go to this page and download the library: Download chenqd/mixin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chenqd / mixin example snippets


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'=>'大饼'
            ],
        ];
    }
}


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
    }
}

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