Skip to content

Commit

Permalink
Improving the event decorator code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Krämer committed May 20, 2016
1 parent 5b61250 commit 9c4291b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Expand Up @@ -14,7 +14,7 @@
*/
namespace Cake\Event\Decorator;

class BaseDecorator
abstract class AbstractDecorator
{

/**
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/Event/Decorator/ConditionDecorator.php
Expand Up @@ -20,7 +20,7 @@
/**
* Event Condition Decorator
*/
class ConditionDecorator extends BaseDecorator
class ConditionDecorator extends AbstractDecorator
{

/**
Expand All @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Event/Decorator/SubjectFilterDecorator.php
Expand Up @@ -20,7 +20,7 @@
/**
* Event Subject Filter Decorator
*/
class SubjectFilterDecorator extends BaseDecorator
class SubjectFilterDecorator extends AbstractDecorator
{

/**
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 9c4291b

Please sign in to comment.