Skip to content

Commit 5b77313

Browse files
committed
configure the kernel similar to how symfony services are defined.
this could make the module support more than just Symfony Kernels.
1 parent 930490c commit 5b77313

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

kernel.api.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ function hook_kernel_info() {
88
$info = array(
99
'app' => array(
1010
'kernel class' => 'AppKernel',
11-
'environment' => 'prod',
12-
'debug' => false,
11+
'arguments' => array('prod', false),
1312
'calls' => array(
1413
'loadClassCache' => array(),
1514
),
16-
'autoload' => $path .'/app/autoload.php',
17-
'bootstrap cache' => $path .'/app/bootstrap.php.cache',
15+
'require_once' => array(
16+
$path .'/app/bootstrap.php.cache',
17+
$path .'/app/AppKernel.php',
18+
),
1819
'console list' => $path .'/app.drush.json',
1920
),
2021
);

kernel.module

+26-9
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,39 @@ function kernel_info($name = 'app') {
4343
function kernel_app($name = 'app') {
4444
static $kernel;
4545
$info = kernel_info($name);
46-
if ((!$kernel) && (class_exists($info['kernel class']))) {
47-
if (file_exists($info['autoload'])) {
48-
require_once $info['autoload'];
46+
if (!$kernel) {
47+
48+
if (is_array($info['require_once'])) {
49+
$files = array_filter($info['require_once'], 'file_exists');
50+
if (!empty($files)) {
51+
foreach ($files as $file) {
52+
require_once $file;
53+
}
54+
}
4955
}
50-
if ($info['debug']) {
56+
57+
if ($info['arguments'][1]) {
5158
\Symfony\Component\Debug\Debug::enable();
5259
}
5360

54-
/** @var \Symfony\Component\HttpKernel\KernelInterface $kernel */
55-
$kernel = new $info['kernel class']($info['environment'], $info['debug']);
61+
if (class_exists($info['kernel class'])) {
62+
63+
/* @var \Symfony\Component\HttpKernel\HttpKernelInterface $kernel */
64+
if (!empty($info['arguments']) && is_array($info['arguments'])) {
65+
$reflect = new ReflectionClass($info['kernel class']);
66+
$kernel = $reflect->newInstanceArgs($info['arguments']);
67+
}
68+
else {
69+
$kernel = new $info['kernel class']();
70+
}
71+
72+
foreach ($info['calls'] as $method => $args) {
73+
call_user_func_array(array($kernel, $method), $args);
74+
}
5675

57-
foreach ($info['calls'] as $method => $args) {
58-
call_user_func_array(array($kernel, $method), $args);
76+
return $kernel;
5977
}
6078
}
61-
return $kernel;
6279
}
6380

6481
/**

0 commit comments

Comments
 (0)