Skip to content
Permalink
Browse files

Improving the event decorator code.

  • Loading branch information...
burzum committed May 20, 2016
1 parent 5b61250 commit 9c4291b2707ec82ef3590c3594a0fb63a126e65e
@@ -14,7 +14,7 @@
*/
namespace Cake\Event\Decorator;
class BaseDecorator
abstract class AbstractDecorator
{
/**
@@ -51,18 +51,19 @@ public function __construct(callable $callable, array $options = [])
*/
public function __invoke()
{
return $this->call($this->_callable, func_get_args());
return $this->_call($this->_callable, func_get_args());
}
/**
* Calls a callable with the passed arguments.
* Calls the decorated callable with the passed arguments.
*
* @param callable $callable The callable.
* @param array $args Arguments for the callable.
* @return mixed
*/
public function call(callable $callable, $args)
protected function _call($args)
{
$callable = $this->_callable;
switch (count($args)) {
case 0:
return $callable();
@@ -20,7 +20,7 @@
/**
* Event Condition Decorator
*/
class ConditionDecorator extends BaseDecorator
class ConditionDecorator extends AbstractDecorator
{
/**
@@ -33,7 +33,7 @@ public function __invoke()
if (!$this->canTrigger($args[0])) {
return false;
}
return call_user_func_array('parent::__invoke', $args);
return $this->_call($args);
}
/**
@@ -20,7 +20,7 @@
/**
* Event Subject Filter Decorator
*/
class SubjectFilterDecorator extends BaseDecorator
class SubjectFilterDecorator extends AbstractDecorator
{
/**
@@ -33,7 +33,7 @@ public function __invoke()
if (!$this->canTrigger($args[0])) {
return false;
}
return call_user_func_array('parent::__invoke', $args);
return $this->_call($args);
}
/**

0 comments on commit 9c4291b

Please sign in to comment.
You can’t perform that action at this time.