\Piko\BehaviorTrait
An instance using this trait can attach dynamically custom methods to itself.
Properties summary
Name | Description |
---|---|
public $behaviors |
Behaviors container. |
Methods summary
Name | Description |
---|---|
public __call |
Magic method to call a behavior. |
public attachBehavior |
Attach a behavior to the class instance. |
public detachBehavior |
Detach a behavior. |
Properties
public $behaviors : callable[]
Behaviors container.
Methods
public __call(): mixed
public __call(string $name, array<int,mixed> $args): mixed
Magic method to call a behavior.
Parameters
$name : The name of the behavior.
$args : The behavior arguments.
throws \RuntimeException
Return:
mixed
public attachBehavior(): void
public attachBehavior(string $name, callable $callback): void
Attach a behavior to the class instance.
Parameters
$name : The behavior name.
$callback : The behavior implementation. Must be one of the following:
- A Closure (function(){ … })
- An object method ([$object, ‘methodName’])
- A static class method (‘MyClass::myMethod’)
- A global function (‘myFunction’)
- An object implementing __invoke()
public detachBehavior(): void
public detachBehavior(string $name): void
Detach a behavior.
Parameters
$name : The behavior name.