1 | <?php |
||
8 | class Manager |
||
9 | { |
||
10 | private $client; |
||
11 | private $queries; |
||
12 | |||
13 | 19 | public function __construct(Client $client) |
|
18 | |||
19 | 17 | public function addQuery($name, callable $query = null) |
|
20 | { |
||
21 | 17 | if ($query === null) { |
|
22 | 15 | list($name, $query) = $this->fromObjectToNameCallableList($name); |
|
23 | } |
||
24 | |||
25 | 15 | $this->queries[$name] = $query; |
|
26 | 15 | } |
|
27 | |||
28 | 15 | private function fromObjectToNameCallableList($name) |
|
29 | { |
||
30 | 15 | if (is_object($name) && is_callable($name)) { |
|
31 | 14 | if (method_exists($name, "__toString")) { |
|
32 | 13 | return [(string)$name, $name]; |
|
33 | } |
||
34 | } |
||
35 | |||
36 | 2 | throw new InvalidArgumentException("Your command should implements '__toString' method and should be a callable thing"); |
|
37 | } |
||
38 | |||
39 | 17 | public function __call($name, $args) |
|
52 | } |
||
53 |