1 | <?php |
||
7 | trait Macroable |
||
8 | { |
||
9 | /** |
||
10 | * @var callable[] |
||
11 | */ |
||
12 | protected static $macros = []; |
||
13 | |||
14 | /** |
||
15 | * @param string $method |
||
16 | * @param callable|null $callback |
||
17 | */ |
||
18 | 4 | public static function macro($method, callable $callback = null) |
|
19 | { |
||
20 | 4 | if (!is_callable($callback)) { |
|
21 | 1 | throw new InvalidArgumentException('Fluent builder should be extended with a closure argument, none given'); |
|
22 | } |
||
23 | |||
24 | 3 | self::$macros[$method] = $callback; |
|
25 | 3 | } |
|
26 | |||
27 | /** |
||
28 | * @param string $method |
||
29 | * |
||
30 | * @return bool |
||
31 | */ |
||
32 | 4 | public function hasMacro($method) |
|
36 | |||
37 | /** |
||
38 | * @param string $method |
||
39 | * |
||
40 | * @return callable |
||
41 | */ |
||
42 | 3 | public function getMacro($method) |
|
46 | |||
47 | /** |
||
48 | * @param string $method |
||
49 | * @param array $params |
||
50 | * |
||
51 | * @return mixed |
||
52 | */ |
||
53 | 3 | public function callMacro($method, array $params = []) |
|
60 | } |
||
61 |