1: <?php
2: /**
3: * CakePHP : Rapid Development Framework (https://cakephp.org)
4: * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * For full copyright and license information, please see the LICENSE.txt
8: * Redistributions of files must retain the above copyright notice.
9: *
10: * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
11: * @link https://cakephp.org CakePHP Project
12: * @since 3.3.0
13: * @license https://opensource.org/licenses/mit-license.php MIT License
14: */
15: namespace Cake\Event\Decorator;
16:
17: /**
18: * Common base class for event decorator subclasses.
19: */
20: abstract class AbstractDecorator
21: {
22: /**
23: * Callable
24: *
25: * @var callable
26: */
27: protected $_callable;
28:
29: /**
30: * Decorator options
31: *
32: * @var array
33: */
34: protected $_options = [];
35:
36: /**
37: * Constructor.
38: *
39: * @param callable $callable Callable.
40: * @param array $options Decorator options.
41: */
42: public function __construct(callable $callable, array $options = [])
43: {
44: $this->_callable = $callable;
45: $this->_options = $options;
46: }
47:
48: /**
49: * Invoke
50: *
51: * @link https://secure.php.net/manual/en/language.oop5.magic.php#object.invoke
52: * @return mixed
53: */
54: public function __invoke()
55: {
56: return $this->_call(func_get_args());
57: }
58:
59: /**
60: * Calls the decorated callable with the passed arguments.
61: *
62: * @param array $args Arguments for the callable.
63: * @return mixed
64: */
65: protected function _call($args)
66: {
67: $callable = $this->_callable;
68:
69: return $callable(...$args);
70: }
71: }
72: