1 | <?php |
||
2 | |||
3 | namespace ElfSundae\Apps; |
||
4 | |||
5 | use Illuminate\Contracts\Container\Container; |
||
6 | |||
7 | class MacroRegistrar |
||
8 | { |
||
9 | /** |
||
10 | * Register needed macros. |
||
11 | * |
||
12 | * @param \Illuminate\Contracts\Container\Container $container |
||
13 | * @return void |
||
14 | */ |
||
15 | 28 | public function registerMacros(Container $container) |
|
16 | { |
||
17 | 28 | $this->register( |
|
18 | 28 | $container['url'], |
|
19 | 28 | 'getRootControllerNamespace', |
|
20 | 7 | function () { |
|
21 | /* @var $this \Illuminate\Routing\UrlGenerator */ |
||
22 | 8 | return $this->rootNamespace; |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
23 | 21 | } |
|
24 | ); |
||
25 | |||
26 | 28 | $this->register( |
|
27 | 28 | $container['router'], |
|
28 | 28 | 'hasMiddlewareGroup', |
|
29 | 7 | function ($name) { |
|
30 | /* @var $this \Illuminate\Routing\Router */ |
||
31 | return array_key_exists($name, $this->middlewareGroups); |
||
0 ignored issues
–
show
|
|||
32 | 21 | } |
|
33 | ); |
||
34 | 21 | } |
|
35 | |||
36 | /** |
||
37 | * Register a macro to the class. |
||
38 | * |
||
39 | * @param string|object $class |
||
40 | * @param string $method |
||
41 | * @param object|callable $macro |
||
42 | * @return void |
||
43 | */ |
||
44 | 32 | public function register($class, $method, $macro) |
|
45 | { |
||
46 | 32 | if (! method_exists($class, $method)) { |
|
47 | 32 | $class = is_object($class) ? get_class($class) : $class; |
|
48 | |||
49 | 32 | call_user_func([$class, 'macro'], $method, $macro); |
|
50 | } |
||
51 | 24 | } |
|
52 | } |
||
53 |