1 | <?php |
||
10 | class MethodInvoker implements InvokerInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | private $method; |
||
16 | |||
17 | public function __construct($args) |
||
18 | { |
||
19 | if (!is_array($args)) { |
||
20 | throw new \InvalidArgumentException( |
||
21 | sprintf("Parameter 1 of %s must be an array.", __METHOD__) |
||
22 | ); |
||
23 | } |
||
24 | |||
25 | if (sizeof($args) !== 2) { |
||
26 | throw new ArrayPairLengthAwareException( |
||
27 | sprintf("Parameter 1 of %s must be an array with length === 2.", __METHOD__) |
||
28 | ); |
||
29 | } |
||
30 | |||
31 | if (!isset($args['instance'])) { |
||
32 | throw new ClassInstanceException("\$args index key 'instance' must exists."); |
||
33 | } |
||
34 | |||
35 | if (!isset($args['method'])) { |
||
36 | throw new ClassMethodException("\$args index key 'method' must exists."); |
||
37 | } |
||
38 | |||
39 | $args['instance'] = (!is_object($args['instance']) |
||
40 | ? (class_exists($args['instance']) |
||
41 | ? (new Container)->make($args['instance']) |
||
42 | : null) |
||
43 | : $args['instance']); |
||
44 | |||
45 | $this->method = $args; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | public function invoke() |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | public function invokeWithArgs($args) |
||
73 | } |
||
74 |