|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nyholm\BundleTest; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; |
|
6
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
|
9
|
|
|
use Symfony\Component\Routing\RouteCollectionBuilder; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @author Tobias Nyholm <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class AppKernel extends Kernel |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var string[] |
|
18
|
|
|
*/ |
|
19
|
|
|
private $bundlesToRegister = []; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
private $configFiles = []; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $cachePrefix = ''; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string|null; |
|
33
|
|
|
*/ |
|
34
|
|
|
private $fakedProjectDir; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $cachePrefix |
|
38
|
|
|
*/ |
|
39
|
1 |
|
public function __construct($cachePrefix) |
|
40
|
|
|
{ |
|
41
|
1 |
|
parent::__construct($cachePrefix, true); |
|
42
|
1 |
|
$this->cachePrefix = $cachePrefix; |
|
43
|
|
|
$this->addBundle(FrameworkBundle::class); |
|
44
|
|
|
$this->addConfigFile(__DIR__.'/config/framework.yml'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param string $bundle |
|
|
|
|
|
|
49
|
|
|
*/ |
|
50
|
|
|
public function addBundle($bundleClassName) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->bundlesToRegister[] = $bundleClassName; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param string $configFile path to config file |
|
57
|
|
|
*/ |
|
58
|
|
|
public function addConfigFile($configFile) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->configFiles[] = $configFile; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function getCacheDir() |
|
64
|
|
|
{ |
|
65
|
|
|
return sys_get_temp_dir().'/NyholmBundleTest/'.$this->cachePrefix; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getLogDir() |
|
69
|
|
|
{ |
|
70
|
|
|
return sys_get_temp_dir().'/NyholmBundleTest/log'; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function getProjectDir() |
|
74
|
|
|
{ |
|
75
|
|
|
if (null === $this->fakedProjectDir) { |
|
76
|
|
|
return realpath(__DIR__.'/../../../../'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return $this->fakedProjectDir; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param string|null $rootDir |
|
84
|
|
|
*/ |
|
85
|
|
|
public function setRootDir($rootDir) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->rootDir = $rootDir; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param string|null $projectDir |
|
92
|
|
|
*/ |
|
93
|
|
|
public function setProjectDir($projectDir) |
|
94
|
|
|
{ |
|
95
|
|
|
$this->fakedProjectDir = $projectDir; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function registerBundles() |
|
99
|
|
|
{ |
|
100
|
|
|
$this->bundlesToRegister = array_unique($this->bundlesToRegister); |
|
101
|
|
|
$bundles = []; |
|
102
|
|
|
foreach ($this->bundlesToRegister as $bundle) { |
|
103
|
|
|
$bundles[] = new $bundle(); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $bundles; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* (From MicroKernelTrait) |
|
111
|
|
|
* {@inheritdoc} |
|
112
|
|
|
*/ |
|
113
|
|
|
public function registerContainerConfiguration(LoaderInterface $loader) |
|
114
|
|
|
{ |
|
115
|
|
|
$loader->load(function (ContainerBuilder $container) use ($loader) { |
|
116
|
|
|
$container->loadFromExtension('framework', [ |
|
117
|
|
|
'router' => [ |
|
118
|
|
|
'resource' => 'kernel:loadRoutes', |
|
119
|
|
|
'type' => 'service', |
|
120
|
|
|
], |
|
121
|
|
|
]); |
|
122
|
|
|
|
|
123
|
|
|
$this->configFiles = array_unique($this->configFiles); |
|
124
|
|
|
foreach ($this->configFiles as $path) { |
|
125
|
|
|
$loader->load($path); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
$container->addObjectResource($this); |
|
129
|
|
|
}); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* (From MicroKernelTrait). |
|
134
|
|
|
* |
|
135
|
|
|
* @internal |
|
136
|
|
|
*/ |
|
137
|
|
|
public function loadRoutes(LoaderInterface $loader) |
|
138
|
|
|
{ |
|
139
|
|
|
$routes = new RouteCollectionBuilder($loader); |
|
140
|
|
|
$routes->import(__DIR__.'/config/routing.yml'); |
|
141
|
|
|
|
|
142
|
|
|
return $routes->build(); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.