|
4 | 4 |
|
5 | 5 | class DrupalKernelServiceProvider implements ServiceProviderInterface
|
6 | 6 | {
|
7 |
| - /** |
8 |
| - * Registers services on the given container. |
9 |
| - * |
10 |
| - * This method should only be used to configure services and parameters. |
11 |
| - * It should not get services. |
12 |
| - * |
13 |
| - * @param \Pimple\Container $pimple An Container instance |
14 |
| - */ |
15 |
| - public function register(\Pimple\Container $pimple) |
16 |
| - { |
17 |
| - $pimple['kernel.name'] = 'app'; |
18 |
| - $pimple['kernel.info'] = function ($c) { |
19 |
| - return kernel_info($c['kernel.name']); |
20 |
| - }; |
21 |
| - |
22 |
| - $pimple['kernel'] = function ($c) { |
23 |
| - $info = $c['kernel.info']; |
24 |
| - if (is_array($info['require_once'])) { |
25 |
| - $files = array_filter($info['require_once'], 'file_exists'); |
26 |
| - if (!empty($files)) { |
27 |
| - foreach ($files as $file) { |
28 |
| - require_once $file; |
29 |
| - } |
30 |
| - } |
31 |
| - } |
| 7 | + /** |
| 8 | + * Registers services on the given container. |
| 9 | + * |
| 10 | + * This method should only be used to configure services and parameters. |
| 11 | + * It should not get services. |
| 12 | + * |
| 13 | + * @param \Pimple\Container $pimple An Container instance |
| 14 | + */ |
| 15 | + public function register(\Pimple\Container $pimple) |
| 16 | + { |
| 17 | + $pimple['kernel.name'] = 'app'; |
| 18 | + $pimple['kernel.info'] = function ($c) { |
| 19 | + return kernel_info($c['kernel.name']); |
| 20 | + }; |
32 | 21 |
|
33 |
| - if ($info['arguments'][1]) { |
34 |
| - \Symfony\Component\Debug\Debug::enable(); |
35 |
| - } |
| 22 | + $pimple['kernel'] = function ($c) { |
| 23 | + $info = $c['kernel.info']; |
| 24 | + if (is_array($info['require_once'])) { |
| 25 | + $files = array_filter($info['require_once'], 'file_exists'); |
| 26 | + if (!empty($files)) { |
| 27 | + foreach ($files as $file) { |
| 28 | + require_once $file; |
| 29 | + } |
| 30 | + } |
| 31 | + } |
36 | 32 |
|
37 |
| - if (class_exists($info['kernel class'])) { |
| 33 | + if ($info['arguments'][1]) { |
| 34 | + \Symfony\Component\Debug\Debug::enable(); |
| 35 | + } |
38 | 36 |
|
39 |
| - /* @var \Symfony\Component\HttpKernel\KernelInterface $kernel */ |
40 |
| - if (!empty($info['arguments']) && is_array($info['arguments'])) { |
41 |
| - $reflect = new ReflectionClass($info['kernel class']); |
42 |
| - $kernel = $reflect->newInstanceArgs($info['arguments']); |
43 |
| - } else { |
44 |
| - $kernel = new $info['kernel class'](); |
45 |
| - } |
| 37 | + if (class_exists($info['kernel class'])) { |
| 38 | + /* @var \Symfony\Component\HttpKernel\KernelInterface $kernel */ |
| 39 | + if (!empty($info['arguments']) && is_array($info['arguments'])) { |
| 40 | + $reflect = new ReflectionClass($info['kernel class']); |
| 41 | + $kernel = $reflect->newInstanceArgs($info['arguments']); |
| 42 | + } else { |
| 43 | + $kernel = new $info['kernel class'](); |
| 44 | + } |
46 | 45 |
|
47 |
| - foreach ($info['calls'] as $method => $args) { |
48 |
| - call_user_func_array(array($kernel, $method), $args); |
49 |
| - } |
| 46 | + foreach ($info['calls'] as $method => $args) { |
| 47 | + call_user_func_array(array($kernel, $method), $args); |
| 48 | + } |
50 | 49 |
|
51 |
| - return $kernel; |
52 |
| - } else { |
53 |
| - throw new \ErrorException($info['kernel class'] .' is not found'); |
54 |
| - } |
| 50 | + return $kernel; |
| 51 | + } else { |
| 52 | + throw new \ErrorException($info['kernel class'].' is not found'); |
| 53 | + } |
55 | 54 |
|
56 |
| - }; |
| 55 | + }; |
57 | 56 |
|
58 |
| - $pimple['container'] = function ($c) { |
59 |
| - $c['kernel']->boot(); |
| 57 | + $pimple['container'] = function ($c) { |
| 58 | + $c['kernel']->boot(); |
60 | 59 |
|
61 |
| - return $c['kernel']->getContainer(); |
62 |
| - }; |
| 60 | + return $c['kernel']->getContainer(); |
| 61 | + }; |
63 | 62 |
|
64 |
| - $pimple['router'] = function ($c) { |
65 |
| - return $c['container']->get('router'); |
66 |
| - }; |
67 |
| - $pimple['router.transformer'] = $pimple->protect( |
68 |
| - /** |
69 |
| - * @param $path |
70 |
| - * |
71 |
| - * @return array |
72 |
| - */ |
73 |
| - function ($path) { |
74 |
| - return array( |
75 |
| - 'path' => $path, |
76 |
| - 'page_callback' => 'kernel_callback', |
77 |
| - 'page_arguments' => array(\Symfony\Component\HttpFoundation\Request::createFromGlobals()), |
78 |
| - 'delivery_callback' => '', |
79 |
| - 'tab_parent' => '', |
80 |
| - 'tab_root' => $path, |
81 |
| - 'title' => '', |
82 |
| - 'type' => MENU_CALLBACK, |
83 |
| - 'include_file' => drupal_get_path('module', 'kernel') . '/kernel.pages.inc', |
84 |
| - 'href' => $path, |
85 |
| - 'tab_root_href' => $path, |
86 |
| - 'tab_parent_href' => '', |
87 |
| - 'access' => TRUE, |
88 |
| - 'original_map' => arg(NULL, $path), |
89 |
| - 'map' => arg(NULL, $path), |
| 63 | + $pimple['router'] = function ($c) { |
| 64 | + return $c['container']->get('router'); |
| 65 | + }; |
| 66 | + $pimple['router.transformer'] = $pimple->protect( |
| 67 | + /** |
| 68 | + * @param $path |
| 69 | + * |
| 70 | + * @return array |
| 71 | + */ |
| 72 | + function ($path) { |
| 73 | + return array( |
| 74 | + 'path' => $path, |
| 75 | + 'page_callback' => 'kernel_callback', |
| 76 | + 'page_arguments' => array(\Symfony\Component\HttpFoundation\Request::createFromGlobals()), |
| 77 | + 'delivery_callback' => '', |
| 78 | + 'tab_parent' => '', |
| 79 | + 'tab_root' => $path, |
| 80 | + 'title' => '', |
| 81 | + 'type' => MENU_CALLBACK, |
| 82 | + 'include_file' => drupal_get_path('module', 'kernel').'/kernel.pages.inc', |
| 83 | + 'href' => $path, |
| 84 | + 'tab_root_href' => $path, |
| 85 | + 'tab_parent_href' => '', |
| 86 | + 'access' => true, |
| 87 | + 'original_map' => arg(null, $path), |
| 88 | + 'map' => arg(null, $path), |
| 89 | + ); |
| 90 | + } |
90 | 91 | );
|
91 |
| - }); |
92 |
| - } |
| 92 | + } |
93 | 93 | }
|
0 commit comments