Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NAMESPACE Bob
- trait testTrait
- {
- protected int _foo = 0;
- }
- NAMESPACE Bla
- trait anotherTrait
- {
- protected int _foo = 5;
- }
- NAMESPACE Baz
- class baz
- {
- use \Bob\testTrait, \Bla\anotherTrait; <- collision @ _foo
- }
- solution:
- NAMESPACE ILLI\Base\Component\Delegate\Hook;
- TRAIT tAdapter
- {
- protected $__Base_Component_Delegate_Hook_tAdapter_registry = [];
- protected function Base_Component_Delegate_Hook_tAdapter_defineInvoke($__triggerMethod, $__targetFunction, $__Instance, $__localScope = FALSE)
- {
- $this->Base_Component_Delegate_Hook_tAdapter_register($__triggerMethod, [$__Instance, $__targetFunction], $__localScope);
- return $this;
- }
- protected function Base_Component_Delegate_Hook_tAdapter_defineDelegate($__triggerMethod, $__targetFunction, $__Instance, $__localScope = FALSE)
- {
- $config = new sConfigConstructMethod;
- $config->Context = $__Instance;
- $config->functionName = $__targetFunction;
- $adapter = new sConcreteAdapter;
- $adapter->triggerMethodName = $__triggerMethod;
- $adapter->Delegate = new Method($config);
- $this->Base_Component_Delegate_Hook_tAdapter_register($adapter->triggerMethodName, $adapter->Delegate, $__localScope);
- return $this;
- }
- protected function Base_Component_Delegate_Hook_tAdapter_defineConcrete(sConcreteAdapter $__Adapter, $__localScope = FALSE)
- {
- $this->Base_Component_Delegate_Hook_tAdapter_register($__Adapter->triggerMethodName, $__Adapter->Delegate, $__localScope);
- return $this;
- }
- protected function Base_Component_Delegate_Hook_tAdapter_register($__triggerMethod, $__delegate, $__localScope)
- {
- $__triggerMethod = (TRUE === $__localScope ? __CLASS__ : get_called_class()).'::'.$__triggerMethod;
- $this->__Base_Component_Delegate_Hook_tAdapter_registry[$__triggerMethod] = $__delegate;
- return $this;
- }
- protected function Base_Component_Delegate_Hook_tAdapter_unregister($__triggerMethod)
- {
- if(isset($this->__Base_Component_Delegate_Hook_tAdapter_registry[$__triggerMethod]))
- unset($this->__Base_Component_Delegate_Hook_tAdapter_registry[$__triggerMethod]);
- return $this;
- }
- protected function Base_Component_Delegate_Hook_tAdapter_exists($__triggerMethod)
- {
- return isset($this->__Base_Component_Delegate_Hook_tAdapter_registry[$__triggerMethod]);
- }
- protected function Base_Component_Delegate_Hook_tAdapter_emit($__triggerMethod, array $__parameters = [])
- {
- if(FALSE === $this->Base_Component_Delegate_Hook_tAdapter_exists($__triggerMethod))
- return NULL;
- $Delegate = & $this->__Base_Component_Delegate_Hook_tAdapter_registry[$__triggerMethod];
- return (TRUE === ($Delegate instanceOf aMethodDelegate))
- ? $Delegate->emit($__parameters)
- : Invoke::callMethod($Delegate[0], $Delegate[1], $__parameters);;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement