dev-master
9999999-dev
MIT
The Requires
- php >=7.0.0
The Development Requires
1.0
1.0.0.0
MIT
The Requires
- php >=7.0.0
The Development Requires
Wallogit.com
2017 © Pedro Peláez
Delegate is a simple way to make property calls chainable when they otherwise wouldn't be., (*2)
Via Composer:, (*3)
composer require aviator/delegate
Via Composer:, (*4)
composer test
Use a magic __get to set up a delegate:, (*5)
public function __get ($name)
{
if ($name === 'foo') {
return $this->getFooDelegate()
}
}
which will return the delegate when $instance->foo is called., (*6)
Since Delegate accepts anything as its first parameter and a Closure as its second, you can do anything:, (*7)
private function getFooDelegate ()
{
return new Delegate($this->someMember, function ($collection, $name) {
return $collection->get($name);
}
}
This allows you to call $instance->foo->bar, which will call your function against someMember., (*8)
MIT
MIT