|
0
|
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace { require_once __DIR__.'/autoload.php'; }
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
namespace Symfony\Component\DependencyInjection
|
|
|
10 |
{
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
interface ContainerAwareInterface
|
|
|
14 |
{
|
|
|
15 |
|
|
|
16 |
function setContainer(ContainerInterface $container = null);
|
|
|
17 |
}
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
namespace Symfony\Component\DependencyInjection
|
|
|
24 |
{
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
interface ContainerInterface
|
|
|
28 |
{
|
|
|
29 |
const EXCEPTION_ON_INVALID_REFERENCE = 1;
|
|
|
30 |
const NULL_ON_INVALID_REFERENCE = 2;
|
|
|
31 |
const IGNORE_ON_INVALID_REFERENCE = 3;
|
|
|
32 |
const SCOPE_CONTAINER = 'container';
|
|
|
33 |
const SCOPE_PROTOTYPE = 'prototype';
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
function set($id, $service, $scope = self::SCOPE_CONTAINER);
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
function has($id);
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
function getParameter($name);
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
function hasParameter($name);
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
function setParameter($name, $value);
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
function enterScope($name);
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
function leaveScope($name);
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
function addScope(ScopeInterface $scope);
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
function hasScope($name);
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
function isScopeActive($name);
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
namespace Symfony\Component\DependencyInjection
|
|
|
74 |
{
|
|
|
75 |
|
|
|
76 |
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
|
|
77 |
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
|
|
|
78 |
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
|
|
79 |
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
|
|
80 |
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
class Container implements ContainerInterface
|
|
|
84 |
{
|
|
|
85 |
protected $parameterBag;
|
|
|
86 |
protected $services;
|
|
|
87 |
protected $scopes;
|
|
|
88 |
protected $scopeChildren;
|
|
|
89 |
protected $scopedServices;
|
|
|
90 |
protected $scopeStacks;
|
|
|
91 |
protected $loading = array();
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
public function __construct(ParameterBagInterface $parameterBag = null)
|
|
|
95 |
{
|
|
|
96 |
$this->parameterBag = null === $parameterBag ? new ParameterBag() : $parameterBag;
|
|
|
97 |
|
|
|
98 |
$this->services = array();
|
|
|
99 |
$this->scopes = array();
|
|
|
100 |
$this->scopeChildren = array();
|
|
|
101 |
$this->scopedServices = array();
|
|
|
102 |
$this->scopeStacks = array();
|
|
|
103 |
|
|
|
104 |
$this->set('service_container', $this);
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
public function compile()
|
|
|
109 |
{
|
|
|
110 |
$this->parameterBag->resolve();
|
|
|
111 |
|
|
|
112 |
$this->parameterBag = new FrozenParameterBag($this->parameterBag->all());
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
public function isFrozen()
|
|
|
117 |
{
|
|
|
118 |
return $this->parameterBag instanceof FrozenParameterBag;
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
public function getParameterBag()
|
|
|
123 |
{
|
|
|
124 |
return $this->parameterBag;
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
public function getParameter($name)
|
|
|
129 |
{
|
|
|
130 |
return $this->parameterBag->get($name);
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
public function hasParameter($name)
|
|
|
135 |
{
|
|
|
136 |
return $this->parameterBag->has($name);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
public function setParameter($name, $value)
|
|
|
141 |
{
|
|
|
142 |
$this->parameterBag->set($name, $value);
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
public function set($id, $service, $scope = self::SCOPE_CONTAINER)
|
|
|
147 |
{
|
|
|
148 |
if (self::SCOPE_PROTOTYPE === $scope) {
|
|
|
149 |
throw new \InvalidArgumentException('You cannot set services of scope "prototype".');
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
$id = strtolower($id);
|
|
|
153 |
|
|
|
154 |
if (self::SCOPE_CONTAINER !== $scope) {
|
|
|
155 |
if (!isset($this->scopedServices[$scope])) {
|
|
|
156 |
throw new \RuntimeException('You cannot set services of inactive scopes.');
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
$this->scopedServices[$scope][$id] = $service;
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
$this->services[$id] = $service;
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
|
|
|
166 |
public function has($id)
|
|
|
167 |
{
|
|
|
168 |
$id = strtolower($id);
|
|
|
169 |
|
|
|
170 |
return isset($this->services[$id]) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service');
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
|
|
|
175 |
{
|
|
|
176 |
$id = strtolower($id);
|
|
|
177 |
|
|
|
178 |
if (isset($this->services[$id])) {
|
|
|
179 |
return $this->services[$id];
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
if (isset($this->loading[$id])) {
|
|
|
183 |
throw new ServiceCircularReferenceException($id, array_keys($this->loading));
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
if (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')) {
|
|
|
187 |
$this->loading[$id] = true;
|
|
|
188 |
|
|
|
189 |
try {
|
|
|
190 |
$service = $this->$method();
|
|
|
191 |
} catch (\Exception $e) {
|
|
|
192 |
unset($this->loading[$id]);
|
|
|
193 |
throw $e;
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
unset($this->loading[$id]);
|
|
|
197 |
|
|
|
198 |
return $service;
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
|
|
|
202 |
throw new ServiceNotFoundException($id);
|
|
|
203 |
}
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
|
|
|
207 |
public function getServiceIds()
|
|
|
208 |
{
|
|
|
209 |
$ids = array();
|
|
|
210 |
$r = new \ReflectionClass($this);
|
|
|
211 |
foreach ($r->getMethods() as $method) {
|
|
|
212 |
if (preg_match('/^get(.+)Service$/', $method->getName(), $match)) {
|
|
|
213 |
$ids[] = self::underscore($match[1]);
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
return array_unique(array_merge($ids, array_keys($this->services)));
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
public function enterScope($name)
|
|
|
222 |
{
|
|
|
223 |
if (!isset($this->scopes[$name])) {
|
|
|
224 |
throw new \InvalidArgumentException(sprintf('The scope "%s" does not exist.', $name));
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
if (self::SCOPE_CONTAINER !== $this->scopes[$name] && !isset($this->scopedServices[$this->scopes[$name]])) {
|
|
|
228 |
throw new \RuntimeException(sprintf('The parent scope "%s" must be active when entering this scope.', $this->scopes[$name]));
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
if (isset($this->scopedServices[$name])) {
|
|
|
232 |
$services = array($this->services, $name => $this->scopedServices[$name]);
|
|
|
233 |
unset($this->scopedServices[$name]);
|
|
|
234 |
|
|
|
235 |
foreach ($this->scopeChildren[$name] as $child) {
|
|
|
236 |
$services[$child] = $this->scopedServices[$child];
|
|
|
237 |
unset($this->scopedServices[$child]);
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
$this->services = call_user_func_array('array_diff_key', $services);
|
|
|
241 |
array_shift($services);
|
|
|
242 |
|
|
|
243 |
if (!isset($this->scopeStacks[$name])) {
|
|
|
244 |
$this->scopeStacks[$name] = new \SplStack();
|
|
|
245 |
}
|
|
|
246 |
$this->scopeStacks[$name]->push($services);
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
$this->scopedServices[$name] = array();
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
|
|
|
253 |
public function leaveScope($name)
|
|
|
254 |
{
|
|
|
255 |
if (!isset($this->scopedServices[$name])) {
|
|
|
256 |
throw new \InvalidArgumentException(sprintf('The scope "%s" is not active.', $name));
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
$services = array($this->services, $this->scopedServices[$name]);
|
|
|
260 |
unset($this->scopedServices[$name]);
|
|
|
261 |
foreach ($this->scopeChildren[$name] as $child) {
|
|
|
262 |
if (!isset($this->scopedServices[$child])) {
|
|
|
263 |
continue;
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
$services[] = $this->scopedServices[$child];
|
|
|
267 |
unset($this->scopedServices[$child]);
|
|
|
268 |
}
|
|
|
269 |
$this->services = call_user_func_array('array_diff_key', $services);
|
|
|
270 |
|
|
|
271 |
if (isset($this->scopeStacks[$name]) && count($this->scopeStacks[$name]) > 0) {
|
|
|
272 |
$services = $this->scopeStacks[$name]->pop();
|
|
|
273 |
$this->scopedServices += $services;
|
|
|
274 |
|
|
|
275 |
array_unshift($services, $this->services);
|
|
|
276 |
$this->services = call_user_func_array('array_merge', $services);
|
|
|
277 |
}
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
|
|
|
281 |
public function addScope(ScopeInterface $scope)
|
|
|
282 |
{
|
|
|
283 |
$name = $scope->getName();
|
|
|
284 |
$parentScope = $scope->getParentName();
|
|
|
285 |
|
|
|
286 |
if (self::SCOPE_CONTAINER === $name || self::SCOPE_PROTOTYPE === $name) {
|
|
|
287 |
throw new \InvalidArgumentException(sprintf('The scope "%s" is reserved.', $name));
|
|
|
288 |
}
|
|
|
289 |
if (isset($this->scopes[$name])) {
|
|
|
290 |
throw new \InvalidArgumentException(sprintf('A scope with name "%s" already exists.', $name));
|
|
|
291 |
}
|
|
|
292 |
if (self::SCOPE_CONTAINER !== $parentScope && !isset($this->scopes[$parentScope])) {
|
|
|
293 |
throw new \InvalidArgumentException(sprintf('The parent scope "%s" does not exist, or is invalid.', $parentScope));
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
$this->scopes[$name] = $parentScope;
|
|
|
297 |
$this->scopeChildren[$name] = array();
|
|
|
298 |
|
|
|
299 |
while ($parentScope !== self::SCOPE_CONTAINER) {
|
|
|
300 |
$this->scopeChildren[$parentScope][] = $name;
|
|
|
301 |
$parentScope = $this->scopes[$parentScope];
|
|
|
302 |
}
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
|
|
|
306 |
public function hasScope($name)
|
|
|
307 |
{
|
|
|
308 |
return isset($this->scopes[$name]);
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
|
|
|
312 |
public function isScopeActive($name)
|
|
|
313 |
{
|
|
|
314 |
return isset($this->scopedServices[$name]);
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
|
|
|
318 |
static public function camelize($id)
|
|
|
319 |
{
|
|
|
320 |
return preg_replace_callback('/(^|_|\.)+(.)/', function ($match) { return ('.' === $match[1] ? '_' : '').strtoupper($match[2]); }, $id);
|
|
|
321 |
}
|
|
|
322 |
|
|
|
323 |
|
|
|
324 |
static public function underscore($id)
|
|
|
325 |
{
|
|
|
326 |
return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($id, '_', '.')));
|
|
|
327 |
}
|
|
|
328 |
}
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
namespace Symfony\Component\HttpKernel
|
|
|
335 |
{
|
|
|
336 |
|
|
|
337 |
use Symfony\Component\HttpFoundation\Request;
|
|
|
338 |
use Symfony\Component\HttpFoundation\Response;
|
|
|
339 |
|
|
|
340 |
|
|
|
341 |
interface HttpKernelInterface
|
|
|
342 |
{
|
|
|
343 |
const MASTER_REQUEST = 1;
|
|
|
344 |
const SUB_REQUEST = 2;
|
|
|
345 |
|
|
|
346 |
|
|
|
347 |
function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
|
|
|
348 |
}
|
|
|
349 |
}
|
|
|
350 |
|
|
|
351 |
|
|
|
352 |
|
|
|
353 |
|
|
|
354 |
namespace Symfony\Component\HttpKernel
|
|
|
355 |
{
|
|
|
356 |
|
|
|
357 |
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
358 |
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
|
|
359 |
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
|
|
360 |
use Symfony\Component\Config\Loader\LoaderInterface;
|
|
|
361 |
|
|
|
362 |
|
|
|
363 |
interface KernelInterface extends HttpKernelInterface, \Serializable
|
|
|
364 |
{
|
|
|
365 |
|
|
|
366 |
function registerBundles();
|
|
|
367 |
|
|
|
368 |
|
|
|
369 |
function registerContainerConfiguration(LoaderInterface $loader);
|
|
|
370 |
|
|
|
371 |
|
|
|
372 |
function boot();
|
|
|
373 |
|
|
|
374 |
|
|
|
375 |
function shutdown();
|
|
|
376 |
|
|
|
377 |
|
|
|
378 |
function getBundles();
|
|
|
379 |
|
|
|
380 |
|
|
|
381 |
function isClassInActiveBundle($class);
|
|
|
382 |
|
|
|
383 |
|
|
|
384 |
function getBundle($name, $first = true);
|
|
|
385 |
|
|
|
386 |
|
|
|
387 |
function locateResource($name, $dir = null, $first = true);
|
|
|
388 |
|
|
|
389 |
|
|
|
390 |
function getName();
|
|
|
391 |
|
|
|
392 |
|
|
|
393 |
function getEnvironment();
|
|
|
394 |
|
|
|
395 |
|
|
|
396 |
function isDebug();
|
|
|
397 |
|
|
|
398 |
|
|
|
399 |
function getRootDir();
|
|
|
400 |
|
|
|
401 |
|
|
|
402 |
function getContainer();
|
|
|
403 |
|
|
|
404 |
|
|
|
405 |
function getStartTime();
|
|
|
406 |
|
|
|
407 |
|
|
|
408 |
function getCacheDir();
|
|
|
409 |
|
|
|
410 |
|
|
|
411 |
function getLogDir();
|
|
|
412 |
}
|
|
|
413 |
}
|
|
|
414 |
|
|
|
415 |
|
|
|
416 |
|
|
|
417 |
|
|
|
418 |
namespace Symfony\Component\HttpKernel
|
|
|
419 |
{
|
|
|
420 |
|
|
|
421 |
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
422 |
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
423 |
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
|
|
424 |
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
|
|
425 |
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
|
|
426 |
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
|
|
427 |
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
|
|
|
428 |
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
|
|
|
429 |
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
|
|
|
430 |
use Symfony\Component\HttpFoundation\Request;
|
|
|
431 |
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
|
|
432 |
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
|
|
433 |
use Symfony\Component\HttpKernel\Config\FileLocator;
|
|
|
434 |
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
|
|
|
435 |
use Symfony\Component\HttpKernel\DependencyInjection\AddClassesToCachePass;
|
|
|
436 |
use Symfony\Component\HttpKernel\DependencyInjection\Extension as DIExtension;
|
|
|
437 |
use Symfony\Component\HttpKernel\Debug\ErrorHandler;
|
|
|
438 |
use Symfony\Component\HttpKernel\Debug\ExceptionHandler;
|
|
|
439 |
use Symfony\Component\Config\Loader\LoaderResolver;
|
|
|
440 |
use Symfony\Component\Config\Loader\DelegatingLoader;
|
|
|
441 |
use Symfony\Component\Config\ConfigCache;
|
|
|
442 |
use Symfony\Component\ClassLoader\ClassCollectionLoader;
|
|
|
443 |
use Symfony\Component\ClassLoader\DebugUniversalClassLoader;
|
|
|
444 |
|
|
|
445 |
|
|
|
446 |
abstract class Kernel implements KernelInterface
|
|
|
447 |
{
|
|
|
448 |
protected $bundles;
|
|
|
449 |
protected $bundleMap;
|
|
|
450 |
protected $container;
|
|
|
451 |
protected $rootDir;
|
|
|
452 |
protected $environment;
|
|
|
453 |
protected $debug;
|
|
|
454 |
protected $booted;
|
|
|
455 |
protected $name;
|
|
|
456 |
protected $startTime;
|
|
|
457 |
protected $classes;
|
|
|
458 |
|
|
|
459 |
const VERSION = '2.0.1';
|
|
|
460 |
|
|
|
461 |
|
|
|
462 |
public function __construct($environment, $debug)
|
|
|
463 |
{
|
|
|
464 |
$this->environment = $environment;
|
|
|
465 |
$this->debug = (Boolean) $debug;
|
|
|
466 |
$this->booted = false;
|
|
|
467 |
$this->rootDir = $this->getRootDir();
|
|
|
468 |
$this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
|
|
|
469 |
$this->classes = array();
|
|
|
470 |
|
|
|
471 |
if ($this->debug) {
|
|
|
472 |
$this->startTime = microtime(true);
|
|
|
473 |
}
|
|
|
474 |
|
|
|
475 |
$this->init();
|
|
|
476 |
}
|
|
|
477 |
|
|
|
478 |
public function init()
|
|
|
479 |
{
|
|
|
480 |
if ($this->debug) {
|
|
|
481 |
ini_set('display_errors', 1);
|
|
|
482 |
error_reporting(-1);
|
|
|
483 |
|
|
|
484 |
DebugUniversalClassLoader::enable();
|
|
|
485 |
ErrorHandler::register();
|
|
|
486 |
if ('cli' !== php_sapi_name()) {
|
|
|
487 |
ExceptionHandler::register();
|
|
|
488 |
}
|
|
|
489 |
} else {
|
|
|
490 |
ini_set('display_errors', 0);
|
|
|
491 |
}
|
|
|
492 |
}
|
|
|
493 |
|
|
|
494 |
public function __clone()
|
|
|
495 |
{
|
|
|
496 |
if ($this->debug) {
|
|
|
497 |
$this->startTime = microtime(true);
|
|
|
498 |
}
|
|
|
499 |
|
|
|
500 |
$this->booted = false;
|
|
|
501 |
$this->container = null;
|
|
|
502 |
}
|
|
|
503 |
|
|
|
504 |
|
|
|
505 |
public function boot()
|
|
|
506 |
{
|
|
|
507 |
if (true === $this->booted) {
|
|
|
508 |
return;
|
|
|
509 |
}
|
|
|
510 |
|
|
|
511 |
$this->initializeBundles();
|
|
|
512 |
|
|
|
513 |
$this->initializeContainer();
|
|
|
514 |
|
|
|
515 |
foreach ($this->getBundles() as $bundle) {
|
|
|
516 |
$bundle->setContainer($this->container);
|
|
|
517 |
$bundle->boot();
|
|
|
518 |
}
|
|
|
519 |
|
|
|
520 |
$this->booted = true;
|
|
|
521 |
}
|
|
|
522 |
|
|
|
523 |
|
|
|
524 |
public function shutdown()
|
|
|
525 |
{
|
|
|
526 |
if (false === $this->booted) {
|
|
|
527 |
return;
|
|
|
528 |
}
|
|
|
529 |
|
|
|
530 |
$this->booted = false;
|
|
|
531 |
|
|
|
532 |
foreach ($this->getBundles() as $bundle) {
|
|
|
533 |
$bundle->shutdown();
|
|
|
534 |
$bundle->setContainer(null);
|
|
|
535 |
}
|
|
|
536 |
|
|
|
537 |
$this->container = null;
|
|
|
538 |
}
|
|
|
539 |
|
|
|
540 |
|
|
|
541 |
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
|
|
|
542 |
{
|
|
|
543 |
if (false === $this->booted) {
|
|
|
544 |
$this->boot();
|
|
|
545 |
}
|
|
|
546 |
|
|
|
547 |
return $this->getHttpKernel()->handle($request, $type, $catch);
|
|
|
548 |
}
|
|
|
549 |
|
|
|
550 |
|
|
|
551 |
protected function getHttpKernel()
|
|
|
552 |
{
|
|
|
553 |
return $this->container->get('http_kernel');
|
|
|
554 |
}
|
|
|
555 |
|
|
|
556 |
|
|
|
557 |
public function getBundles()
|
|
|
558 |
{
|
|
|
559 |
return $this->bundles;
|
|
|
560 |
}
|
|
|
561 |
|
|
|
562 |
|
|
|
563 |
public function isClassInActiveBundle($class)
|
|
|
564 |
{
|
|
|
565 |
foreach ($this->getBundles() as $bundle) {
|
|
|
566 |
if (0 === strpos($class, $bundle->getNamespace())) {
|
|
|
567 |
return true;
|
|
|
568 |
}
|
|
|
569 |
}
|
|
|
570 |
|
|
|
571 |
return false;
|
|
|
572 |
}
|
|
|
573 |
|
|
|
574 |
|
|
|
575 |
public function getBundle($name, $first = true)
|
|
|
576 |
{
|
|
|
577 |
if (!isset($this->bundleMap[$name])) {
|
|
|
578 |
throw new \InvalidArgumentException(sprintf('Bundle "%s" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() function of your %s.php file?', $name, get_class($this)));
|
|
|
579 |
}
|
|
|
580 |
|
|
|
581 |
if (true === $first) {
|
|
|
582 |
return $this->bundleMap[$name][0];
|
|
|
583 |
}
|
|
|
584 |
|
|
|
585 |
return $this->bundleMap[$name];
|
|
|
586 |
}
|
|
|
587 |
|
|
|
588 |
|
|
|
589 |
public function locateResource($name, $dir = null, $first = true)
|
|
|
590 |
{
|
|
|
591 |
if ('@' !== $name[0]) {
|
|
|
592 |
throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
|
|
|
593 |
}
|
|
|
594 |
|
|
|
595 |
if (false !== strpos($name, '..')) {
|
|
|
596 |
throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
|
|
|
597 |
}
|
|
|
598 |
|
|
|
599 |
$bundleName = substr($name, 1);
|
|
|
600 |
$path = '';
|
|
|
601 |
if (false !== strpos($bundleName, '/')) {
|
|
|
602 |
list($bundleName, $path) = explode('/', $bundleName, 2);
|
|
|
603 |
}
|
|
|
604 |
|
|
|
605 |
$isResource = 0 === strpos($path, 'Resources') && null !== $dir;
|
|
|
606 |
$overridePath = substr($path, 9);
|
|
|
607 |
$resourceBundle = null;
|
|
|
608 |
$bundles = $this->getBundle($bundleName, false);
|
|
|
609 |
$files = array();
|
|
|
610 |
|
|
|
611 |
foreach ($bundles as $bundle) {
|
|
|
612 |
if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
|
|
|
613 |
if (null !== $resourceBundle) {
|
|
|
614 |
throw new \RuntimeException(sprintf('"%s" resource is hidden by a resource from the "%s" derived bundle. Create a "%s" file to override the bundle resource.',
|
|
|
615 |
$file,
|
|
|
616 |
$resourceBundle,
|
|
|
617 |
$dir.'/'.$bundles[0]->getName().$overridePath
|
|
|
618 |
));
|
|
|
619 |
}
|
|
|
620 |
|
|
|
621 |
if ($first) {
|
|
|
622 |
return $file;
|
|
|
623 |
}
|
|
|
624 |
$files[] = $file;
|
|
|
625 |
}
|
|
|
626 |
|
|
|
627 |
if (file_exists($file = $bundle->getPath().'/'.$path)) {
|
|
|
628 |
if ($first && !$isResource) {
|
|
|
629 |
return $file;
|
|
|
630 |
}
|
|
|
631 |
$files[] = $file;
|
|
|
632 |
$resourceBundle = $bundle->getName();
|
|
|
633 |
}
|
|
|
634 |
}
|
|
|
635 |
|
|
|
636 |
if (count($files) > 0) {
|
|
|
637 |
return $first && $isResource ? $files[0] : $files;
|
|
|
638 |
}
|
|
|
639 |
|
|
|
640 |
throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
|
|
|
641 |
}
|
|
|
642 |
|
|
|
643 |
|
|
|
644 |
public function getName()
|
|
|
645 |
{
|
|
|
646 |
return $this->name;
|
|
|
647 |
}
|
|
|
648 |
|
|
|
649 |
|
|
|
650 |
public function getEnvironment()
|
|
|
651 |
{
|
|
|
652 |
return $this->environment;
|
|
|
653 |
}
|
|
|
654 |
|
|
|
655 |
|
|
|
656 |
public function isDebug()
|
|
|
657 |
{
|
|
|
658 |
return $this->debug;
|
|
|
659 |
}
|
|
|
660 |
|
|
|
661 |
|
|
|
662 |
public function getRootDir()
|
|
|
663 |
{
|
|
|
664 |
if (null === $this->rootDir) {
|
|
|
665 |
$r = new \ReflectionObject($this);
|
|
|
666 |
$this->rootDir = dirname($r->getFileName());
|
|
|
667 |
}
|
|
|
668 |
|
|
|
669 |
return $this->rootDir;
|
|
|
670 |
}
|
|
|
671 |
|
|
|
672 |
|
|
|
673 |
public function getContainer()
|
|
|
674 |
{
|
|
|
675 |
return $this->container;
|
|
|
676 |
}
|
|
|
677 |
|
|
|
678 |
|
|
|
679 |
public function loadClassCache($name = 'classes', $extension = '.php')
|
|
|
680 |
{
|
|
|
681 |
if (!$this->booted && file_exists($this->getCacheDir().'/classes.map')) {
|
|
|
682 |
ClassCollectionLoader::load(include($this->getCacheDir().'/classes.map'), $this->getCacheDir(), $name, $this->debug, false, $extension);
|
|
|
683 |
}
|
|
|
684 |
}
|
|
|
685 |
|
|
|
686 |
|
|
|
687 |
public function setClassCache(array $classes)
|
|
|
688 |
{
|
|
|
689 |
file_put_contents($this->getCacheDir().'/classes.map', sprintf('<?php return %s;', var_export($classes, true)));
|
|
|
690 |
}
|
|
|
691 |
|
|
|
692 |
|
|
|
693 |
public function getStartTime()
|
|
|
694 |
{
|
|
|
695 |
return $this->debug ? $this->startTime : -INF;
|
|
|
696 |
}
|
|
|
697 |
|
|
|
698 |
|
|
|
699 |
public function getCacheDir()
|
|
|
700 |
{
|
|
|
701 |
return $this->rootDir.'/cache/'.$this->environment;
|
|
|
702 |
}
|
|
|
703 |
|
|
|
704 |
|
|
|
705 |
public function getLogDir()
|
|
|
706 |
{
|
|
|
707 |
return $this->rootDir.'/logs';
|
|
|
708 |
}
|
|
|
709 |
|
|
|
710 |
|
|
|
711 |
protected function initializeBundles()
|
|
|
712 |
{
|
|
|
713 |
$this->bundles = array();
|
|
|
714 |
$topMostBundles = array();
|
|
|
715 |
$directChildren = array();
|
|
|
716 |
|
|
|
717 |
foreach ($this->registerBundles() as $bundle) {
|
|
|
718 |
$name = $bundle->getName();
|
|
|
719 |
if (isset($this->bundles[$name])) {
|
|
|
720 |
throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name));
|
|
|
721 |
}
|
|
|
722 |
$this->bundles[$name] = $bundle;
|
|
|
723 |
|
|
|
724 |
if ($parentName = $bundle->getParent()) {
|
|
|
725 |
if (isset($directChildren[$parentName])) {
|
|
|
726 |
throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
|
|
|
727 |
}
|
|
|
728 |
if ($parentName == $name) {
|
|
|
729 |
throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name));
|
|
|
730 |
}
|
|
|
731 |
$directChildren[$parentName] = $name;
|
|
|
732 |
} else {
|
|
|
733 |
$topMostBundles[$name] = $bundle;
|
|
|
734 |
}
|
|
|
735 |
}
|
|
|
736 |
|
|
|
737 |
if (count($diff = array_values(array_diff(array_keys($directChildren), array_keys($this->bundles))))) {
|
|
|
738 |
throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0]));
|
|
|
739 |
}
|
|
|
740 |
|
|
|
741 |
$this->bundleMap = array();
|
|
|
742 |
foreach ($topMostBundles as $name => $bundle) {
|
|
|
743 |
$bundleMap = array($bundle);
|
|
|
744 |
$hierarchy = array($name);
|
|
|
745 |
|
|
|
746 |
while (isset($directChildren[$name])) {
|
|
|
747 |
$name = $directChildren[$name];
|
|
|
748 |
array_unshift($bundleMap, $this->bundles[$name]);
|
|
|
749 |
$hierarchy[] = $name;
|
|
|
750 |
}
|
|
|
751 |
|
|
|
752 |
foreach ($hierarchy as $bundle) {
|
|
|
753 |
$this->bundleMap[$bundle] = $bundleMap;
|
|
|
754 |
array_pop($bundleMap);
|
|
|
755 |
}
|
|
|
756 |
}
|
|
|
757 |
|
|
|
758 |
}
|
|
|
759 |
|
|
|
760 |
|
|
|
761 |
protected function getContainerClass()
|
|
|
762 |
{
|
|
|
763 |
return $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
|
|
|
764 |
}
|
|
|
765 |
|
|
|
766 |
|
|
|
767 |
protected function getContainerBaseClass()
|
|
|
768 |
{
|
|
|
769 |
return 'Container';
|
|
|
770 |
}
|
|
|
771 |
|
|
|
772 |
|
|
|
773 |
protected function initializeContainer()
|
|
|
774 |
{
|
|
|
775 |
$class = $this->getContainerClass();
|
|
|
776 |
$cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
|
|
|
777 |
$fresh = true;
|
|
|
778 |
if (!$cache->isFresh()) {
|
|
|
779 |
$container = $this->buildContainer();
|
|
|
780 |
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
|
|
|
781 |
|
|
|
782 |
$fresh = false;
|
|
|
783 |
}
|
|
|
784 |
|
|
|
785 |
require_once $cache;
|
|
|
786 |
|
|
|
787 |
$this->container = new $class();
|
|
|
788 |
$this->container->set('kernel', $this);
|
|
|
789 |
|
|
|
790 |
if (!$fresh) {
|
|
|
791 |
$this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
|
|
|
792 |
}
|
|
|
793 |
}
|
|
|
794 |
|
|
|
795 |
|
|
|
796 |
protected function getKernelParameters()
|
|
|
797 |
{
|
|
|
798 |
$bundles = array();
|
|
|
799 |
foreach ($this->bundles as $name => $bundle) {
|
|
|
800 |
$bundles[$name] = get_class($bundle);
|
|
|
801 |
}
|
|
|
802 |
|
|
|
803 |
return array_merge(
|
|
|
804 |
array(
|
|
|
805 |
'kernel.root_dir' => $this->rootDir,
|
|
|
806 |
'kernel.environment' => $this->environment,
|
|
|
807 |
'kernel.debug' => $this->debug,
|
|
|
808 |
'kernel.name' => $this->name,
|
|
|
809 |
'kernel.cache_dir' => $this->getCacheDir(),
|
|
|
810 |
'kernel.logs_dir' => $this->getLogDir(),
|
|
|
811 |
'kernel.bundles' => $bundles,
|
|
|
812 |
'kernel.charset' => 'UTF-8',
|
|
|
813 |
'kernel.container_class' => $this->getContainerClass(),
|
|
|
814 |
),
|
|
|
815 |
$this->getEnvParameters()
|
|
|
816 |
);
|
|
|
817 |
}
|
|
|
818 |
|
|
|
819 |
|
|
|
820 |
protected function getEnvParameters()
|
|
|
821 |
{
|
|
|
822 |
$parameters = array();
|
|
|
823 |
foreach ($_SERVER as $key => $value) {
|
|
|
824 |
if ('SYMFONY__' === substr($key, 0, 9)) {
|
|
|
825 |
$parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value;
|
|
|
826 |
}
|
|
|
827 |
}
|
|
|
828 |
|
|
|
829 |
return $parameters;
|
|
|
830 |
}
|
|
|
831 |
|
|
|
832 |
|
|
|
833 |
protected function buildContainer()
|
|
|
834 |
{
|
|
|
835 |
foreach (array('cache' => $this->getCacheDir(), 'logs' => $this->getLogDir()) as $name => $dir) {
|
|
|
836 |
if (!is_dir($dir)) {
|
|
|
837 |
if (false === @mkdir($dir, 0777, true)) {
|
|
|
838 |
throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n", $name, dirname($dir)));
|
|
|
839 |
}
|
|
|
840 |
} elseif (!is_writable($dir)) {
|
|
|
841 |
throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", $name, $dir));
|
|
|
842 |
}
|
|
|
843 |
}
|
|
|
844 |
|
|
|
845 |
$container = new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
|
|
|
846 |
$extensions = array();
|
|
|
847 |
foreach ($this->bundles as $bundle) {
|
|
|
848 |
$bundle->build($container);
|
|
|
849 |
|
|
|
850 |
if ($extension = $bundle->getContainerExtension()) {
|
|
|
851 |
$container->registerExtension($extension);
|
|
|
852 |
$extensions[] = $extension->getAlias();
|
|
|
853 |
}
|
|
|
854 |
|
|
|
855 |
if ($this->debug) {
|
|
|
856 |
$container->addObjectResource($bundle);
|
|
|
857 |
}
|
|
|
858 |
}
|
|
|
859 |
$container->addObjectResource($this);
|
|
|
860 |
|
|
|
861 |
$container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
|
|
|
862 |
|
|
|
863 |
if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
|
|
|
864 |
$container->merge($cont);
|
|
|
865 |
}
|
|
|
866 |
|
|
|
867 |
$container->addCompilerPass(new AddClassesToCachePass($this));
|
|
|
868 |
$container->compile();
|
|
|
869 |
|
|
|
870 |
return $container;
|
|
|
871 |
}
|
|
|
872 |
|
|
|
873 |
|
|
|
874 |
protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
|
|
|
875 |
{
|
|
|
876 |
$dumper = new PhpDumper($container);
|
|
|
877 |
$content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass));
|
|
|
878 |
if (!$this->debug) {
|
|
|
879 |
$content = self::stripComments($content);
|
|
|
880 |
}
|
|
|
881 |
|
|
|
882 |
$cache->write($content, $container->getResources());
|
|
|
883 |
}
|
|
|
884 |
|
|
|
885 |
|
|
|
886 |
protected function getContainerLoader(ContainerInterface $container)
|
|
|
887 |
{
|
|
|
888 |
$locator = new FileLocator($this);
|
|
|
889 |
$resolver = new LoaderResolver(array(
|
|
|
890 |
new XmlFileLoader($container, $locator),
|
|
|
891 |
new YamlFileLoader($container, $locator),
|
|
|
892 |
new IniFileLoader($container, $locator),
|
|
|
893 |
new PhpFileLoader($container, $locator),
|
|
|
894 |
new ClosureLoader($container),
|
|
|
895 |
));
|
|
|
896 |
|
|
|
897 |
return new DelegatingLoader($resolver);
|
|
|
898 |
}
|
|
|
899 |
|
|
|
900 |
|
|
|
901 |
static public function stripComments($source)
|
|
|
902 |
{
|
|
|
903 |
if (!function_exists('token_get_all')) {
|
|
|
904 |
return $source;
|
|
|
905 |
}
|
|
|
906 |
|
|
|
907 |
$output = '';
|
|
|
908 |
foreach (token_get_all($source) as $token) {
|
|
|
909 |
if (is_string($token)) {
|
|
|
910 |
$output .= $token;
|
|
|
911 |
} elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
|
|
|
912 |
$output .= $token[1];
|
|
|
913 |
}
|
|
|
914 |
}
|
|
|
915 |
|
|
|
916 |
$output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
|
|
|
917 |
|
|
|
918 |
return $output;
|
|
|
919 |
}
|
|
|
920 |
|
|
|
921 |
public function serialize()
|
|
|
922 |
{
|
|
|
923 |
return serialize(array($this->environment, $this->debug));
|
|
|
924 |
}
|
|
|
925 |
|
|
|
926 |
public function unserialize($data)
|
|
|
927 |
{
|
|
|
928 |
list($environment, $debug) = unserialize($data);
|
|
|
929 |
|
|
|
930 |
$this->__construct($environment, $debug);
|
|
|
931 |
}
|
|
|
932 |
}
|
|
|
933 |
}
|
|
|
934 |
|
|
|
935 |
|
|
|
936 |
|
|
|
937 |
|
|
|
938 |
namespace Symfony\Component\ClassLoader
|
|
|
939 |
{
|
|
|
940 |
|
|
|
941 |
|
|
|
942 |
class ClassCollectionLoader
|
|
|
943 |
{
|
|
|
944 |
static private $loaded;
|
|
|
945 |
|
|
|
946 |
|
|
|
947 |
static public function load($classes, $cacheDir, $name, $autoReload, $adaptive = false, $extension = '.php')
|
|
|
948 |
{
|
|
|
949 |
if (isset(self::$loaded[$name])) {
|
|
|
950 |
return;
|
|
|
951 |
}
|
|
|
952 |
|
|
|
953 |
self::$loaded[$name] = true;
|
|
|
954 |
|
|
|
955 |
if ($adaptive) {
|
|
|
956 |
$classes = array_diff($classes, get_declared_classes(), get_declared_interfaces());
|
|
|
957 |
|
|
|
958 |
$name = $name.'-'.substr(md5(implode('|', $classes)), 0, 5);
|
|
|
959 |
}
|
|
|
960 |
|
|
|
961 |
$cache = $cacheDir.'/'.$name.$extension;
|
|
|
962 |
|
|
|
963 |
$reload = false;
|
|
|
964 |
if ($autoReload) {
|
|
|
965 |
$metadata = $cacheDir.'/'.$name.$extension.'.meta';
|
|
|
966 |
if (!file_exists($metadata) || !file_exists($cache)) {
|
|
|
967 |
$reload = true;
|
|
|
968 |
} else {
|
|
|
969 |
$time = filemtime($cache);
|
|
|
970 |
$meta = unserialize(file_get_contents($metadata));
|
|
|
971 |
|
|
|
972 |
if ($meta[1] != $classes) {
|
|
|
973 |
$reload = true;
|
|
|
974 |
} else {
|
|
|
975 |
foreach ($meta[0] as $resource) {
|
|
|
976 |
if (!file_exists($resource) || filemtime($resource) > $time) {
|
|
|
977 |
$reload = true;
|
|
|
978 |
|
|
|
979 |
break;
|
|
|
980 |
}
|
|
|
981 |
}
|
|
|
982 |
}
|
|
|
983 |
}
|
|
|
984 |
}
|
|
|
985 |
|
|
|
986 |
if (!$reload && file_exists($cache)) {
|
|
|
987 |
require_once $cache;
|
|
|
988 |
|
|
|
989 |
return;
|
|
|
990 |
}
|
|
|
991 |
|
|
|
992 |
$files = array();
|
|
|
993 |
$content = '';
|
|
|
994 |
foreach ($classes as $class) {
|
|
|
995 |
if (!class_exists($class) && !interface_exists($class)) {
|
|
|
996 |
throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
|
|
|
997 |
}
|
|
|
998 |
|
|
|
999 |
$r = new \ReflectionClass($class);
|
|
|
1000 |
$files[] = $r->getFileName();
|
|
|
1001 |
|
|
|
1002 |
$c = preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', file_get_contents($r->getFileName()));
|
|
|
1003 |
|
|
|
1004 |
if (!$r->inNamespace()) {
|
|
|
1005 |
$c = "\nnamespace\n{\n".self::stripComments($c)."\n}\n";
|
|
|
1006 |
} else {
|
|
|
1007 |
$c = self::fixNamespaceDeclarations('<?php '.$c);
|
|
|
1008 |
$c = preg_replace('/^\s*<\?php/', '', $c);
|
|
|
1009 |
}
|
|
|
1010 |
|
|
|
1011 |
$content .= $c;
|
|
|
1012 |
}
|
|
|
1013 |
|
|
|
1014 |
if (!is_dir(dirname($cache))) {
|
|
|
1015 |
mkdir(dirname($cache), 0777, true);
|
|
|
1016 |
}
|
|
|
1017 |
self::writeCacheFile($cache, '<?php '.$content);
|
|
|
1018 |
|
|
|
1019 |
if ($autoReload) {
|
|
|
1020 |
self::writeCacheFile($metadata, serialize(array($files, $classes)));
|
|
|
1021 |
}
|
|
|
1022 |
}
|
|
|
1023 |
|
|
|
1024 |
|
|
|
1025 |
static public function fixNamespaceDeclarations($source)
|
|
|
1026 |
{
|
|
|
1027 |
if (!function_exists('token_get_all')) {
|
|
|
1028 |
return $source;
|
|
|
1029 |
}
|
|
|
1030 |
|
|
|
1031 |
$output = '';
|
|
|
1032 |
$inNamespace = false;
|
|
|
1033 |
$tokens = token_get_all($source);
|
|
|
1034 |
|
|
|
1035 |
for ($i = 0, $max = count($tokens); $i < $max; $i++) {
|
|
|
1036 |
$token = $tokens[$i];
|
|
|
1037 |
if (is_string($token)) {
|
|
|
1038 |
$output .= $token;
|
|
|
1039 |
} elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
|
|
|
1040 |
continue;
|
|
|
1041 |
} elseif (T_NAMESPACE === $token[0]) {
|
|
|
1042 |
if ($inNamespace) {
|
|
|
1043 |
$output .= "}\n";
|
|
|
1044 |
}
|
|
|
1045 |
$output .= $token[1];
|
|
|
1046 |
|
|
|
1047 |
while (($t = $tokens[++$i]) && is_array($t) && in_array($t[0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
|
|
|
1048 |
$output .= $t[1];
|
|
|
1049 |
}
|
|
|
1050 |
if (is_string($t) && '{' === $t) {
|
|
|
1051 |
$inNamespace = false;
|
|
|
1052 |
--$i;
|
|
|
1053 |
} else {
|
|
|
1054 |
$output .= "\n{";
|
|
|
1055 |
$inNamespace = true;
|
|
|
1056 |
}
|
|
|
1057 |
} else {
|
|
|
1058 |
$output .= $token[1];
|
|
|
1059 |
}
|
|
|
1060 |
}
|
|
|
1061 |
|
|
|
1062 |
if ($inNamespace) {
|
|
|
1063 |
$output .= "}\n";
|
|
|
1064 |
}
|
|
|
1065 |
|
|
|
1066 |
return $output;
|
|
|
1067 |
}
|
|
|
1068 |
|
|
|
1069 |
|
|
|
1070 |
static private function writeCacheFile($file, $content)
|
|
|
1071 |
{
|
|
|
1072 |
$tmpFile = tempnam(dirname($file), basename($file));
|
|
|
1073 |
if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
|
|
|
1074 |
chmod($file, 0644);
|
|
|
1075 |
|
|
|
1076 |
return;
|
|
|
1077 |
}
|
|
|
1078 |
|
|
|
1079 |
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
|
|
|
1080 |
}
|
|
|
1081 |
|
|
|
1082 |
|
|
|
1083 |
static private function stripComments($source)
|
|
|
1084 |
{
|
|
|
1085 |
if (!function_exists('token_get_all')) {
|
|
|
1086 |
return $source;
|
|
|
1087 |
}
|
|
|
1088 |
|
|
|
1089 |
$output = '';
|
|
|
1090 |
foreach (token_get_all($source) as $token) {
|
|
|
1091 |
if (is_string($token)) {
|
|
|
1092 |
$output .= $token;
|
|
|
1093 |
} elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
|
|
|
1094 |
$output .= $token[1];
|
|
|
1095 |
}
|
|
|
1096 |
}
|
|
|
1097 |
|
|
|
1098 |
$output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
|
|
|
1099 |
|
|
|
1100 |
return $output;
|
|
|
1101 |
}
|
|
|
1102 |
}
|
|
|
1103 |
}
|
|
|
1104 |
|
|
|
1105 |
|
|
|
1106 |
|
|
|
1107 |
|
|
|
1108 |
namespace Symfony\Component\ClassLoader
|
|
|
1109 |
{
|
|
|
1110 |
|
|
|
1111 |
|
|
|
1112 |
class UniversalClassLoader
|
|
|
1113 |
{
|
|
|
1114 |
private $namespaces = array();
|
|
|
1115 |
private $prefixes = array();
|
|
|
1116 |
private $namespaceFallbacks = array();
|
|
|
1117 |
private $prefixFallbacks = array();
|
|
|
1118 |
|
|
|
1119 |
|
|
|
1120 |
public function getNamespaces()
|
|
|
1121 |
{
|
|
|
1122 |
return $this->namespaces;
|
|
|
1123 |
}
|
|
|
1124 |
|
|
|
1125 |
|
|
|
1126 |
public function getPrefixes()
|
|
|
1127 |
{
|
|
|
1128 |
return $this->prefixes;
|
|
|
1129 |
}
|
|
|
1130 |
|
|
|
1131 |
|
|
|
1132 |
public function getNamespaceFallbacks()
|
|
|
1133 |
{
|
|
|
1134 |
return $this->namespaceFallbacks;
|
|
|
1135 |
}
|
|
|
1136 |
|
|
|
1137 |
|
|
|
1138 |
public function getPrefixFallbacks()
|
|
|
1139 |
{
|
|
|
1140 |
return $this->prefixFallbacks;
|
|
|
1141 |
}
|
|
|
1142 |
|
|
|
1143 |
|
|
|
1144 |
public function registerNamespaceFallbacks(array $dirs)
|
|
|
1145 |
{
|
|
|
1146 |
$this->namespaceFallbacks = $dirs;
|
|
|
1147 |
}
|
|
|
1148 |
|
|
|
1149 |
|
|
|
1150 |
public function registerPrefixFallbacks(array $dirs)
|
|
|
1151 |
{
|
|
|
1152 |
$this->prefixFallbacks = $dirs;
|
|
|
1153 |
}
|
|
|
1154 |
|
|
|
1155 |
|
|
|
1156 |
public function registerNamespaces(array $namespaces)
|
|
|
1157 |
{
|
|
|
1158 |
foreach ($namespaces as $namespace => $locations) {
|
|
|
1159 |
$this->namespaces[$namespace] = (array) $locations;
|
|
|
1160 |
}
|
|
|
1161 |
}
|
|
|
1162 |
|
|
|
1163 |
|
|
|
1164 |
public function registerNamespace($namespace, $paths)
|
|
|
1165 |
{
|
|
|
1166 |
$this->namespaces[$namespace] = (array) $paths;
|
|
|
1167 |
}
|
|
|
1168 |
|
|
|
1169 |
|
|
|
1170 |
public function registerPrefixes(array $classes)
|
|
|
1171 |
{
|
|
|
1172 |
foreach ($classes as $prefix => $locations) {
|
|
|
1173 |
$this->prefixes[$prefix] = (array) $locations;
|
|
|
1174 |
}
|
|
|
1175 |
}
|
|
|
1176 |
|
|
|
1177 |
|
|
|
1178 |
public function registerPrefix($prefix, $paths)
|
|
|
1179 |
{
|
|
|
1180 |
$this->prefixes[$prefix] = (array) $paths;
|
|
|
1181 |
}
|
|
|
1182 |
|
|
|
1183 |
|
|
|
1184 |
public function register($prepend = false)
|
|
|
1185 |
{
|
|
|
1186 |
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
|
|
1187 |
}
|
|
|
1188 |
|
|
|
1189 |
|
|
|
1190 |
public function loadClass($class)
|
|
|
1191 |
{
|
|
|
1192 |
if ($file = $this->findFile($class)) {
|
|
|
1193 |
require $file;
|
|
|
1194 |
}
|
|
|
1195 |
}
|
|
|
1196 |
|
|
|
1197 |
|
|
|
1198 |
public function findFile($class)
|
|
|
1199 |
{
|
|
|
1200 |
if ('\\' == $class[0]) {
|
|
|
1201 |
$class = substr($class, 1);
|
|
|
1202 |
}
|
|
|
1203 |
|
|
|
1204 |
if (false !== $pos = strrpos($class, '\\')) {
|
|
|
1205 |
$namespace = substr($class, 0, $pos);
|
|
|
1206 |
foreach ($this->namespaces as $ns => $dirs) {
|
|
|
1207 |
if (0 !== strpos($namespace, $ns)) {
|
|
|
1208 |
continue;
|
|
|
1209 |
}
|
|
|
1210 |
|
|
|
1211 |
foreach ($dirs as $dir) {
|
|
|
1212 |
$className = substr($class, $pos + 1);
|
|
|
1213 |
$file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
|
|
|
1214 |
if (file_exists($file)) {
|
|
|
1215 |
return $file;
|
|
|
1216 |
}
|
|
|
1217 |
}
|
|
|
1218 |
}
|
|
|
1219 |
|
|
|
1220 |
foreach ($this->namespaceFallbacks as $dir) {
|
|
|
1221 |
$file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php';
|
|
|
1222 |
if (file_exists($file)) {
|
|
|
1223 |
return $file;
|
|
|
1224 |
}
|
|
|
1225 |
}
|
|
|
1226 |
} else {
|
|
|
1227 |
foreach ($this->prefixes as $prefix => $dirs) {
|
|
|
1228 |
if (0 !== strpos($class, $prefix)) {
|
|
|
1229 |
continue;
|
|
|
1230 |
}
|
|
|
1231 |
|
|
|
1232 |
foreach ($dirs as $dir) {
|
|
|
1233 |
$file = $dir.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
|
|
|
1234 |
if (file_exists($file)) {
|
|
|
1235 |
return $file;
|
|
|
1236 |
}
|
|
|
1237 |
}
|
|
|
1238 |
}
|
|
|
1239 |
|
|
|
1240 |
foreach ($this->prefixFallbacks as $dir) {
|
|
|
1241 |
$file = $dir.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
|
|
|
1242 |
if (file_exists($file)) {
|
|
|
1243 |
return $file;
|
|
|
1244 |
}
|
|
|
1245 |
}
|
|
|
1246 |
}
|
|
|
1247 |
}
|
|
|
1248 |
}
|
|
|
1249 |
}
|
|
|
1250 |
|
|
|
1251 |
|
|
|
1252 |
|
|
|
1253 |
|
|
|
1254 |
namespace Symfony\Component\HttpKernel\Bundle
|
|
|
1255 |
{
|
|
|
1256 |
|
|
|
1257 |
use Symfony\Component\DependencyInjection\ContainerAware;
|
|
|
1258 |
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
1259 |
use Symfony\Component\DependencyInjection\Container;
|
|
|
1260 |
use Symfony\Component\Console\Application;
|
|
|
1261 |
use Symfony\Component\Finder\Finder;
|
|
|
1262 |
|
|
|
1263 |
|
|
|
1264 |
abstract class Bundle extends ContainerAware implements BundleInterface
|
|
|
1265 |
{
|
|
|
1266 |
protected $name;
|
|
|
1267 |
protected $reflected;
|
|
|
1268 |
protected $extension;
|
|
|
1269 |
|
|
|
1270 |
|
|
|
1271 |
public function boot()
|
|
|
1272 |
{
|
|
|
1273 |
}
|
|
|
1274 |
|
|
|
1275 |
|
|
|
1276 |
public function shutdown()
|
|
|
1277 |
{
|
|
|
1278 |
}
|
|
|
1279 |
|
|
|
1280 |
|
|
|
1281 |
public function build(ContainerBuilder $container)
|
|
|
1282 |
{
|
|
|
1283 |
}
|
|
|
1284 |
|
|
|
1285 |
|
|
|
1286 |
public function getContainerExtension()
|
|
|
1287 |
{
|
|
|
1288 |
if (null === $this->extension) {
|
|
|
1289 |
$basename = preg_replace('/Bundle$/', '', $this->getName());
|
|
|
1290 |
|
|
|
1291 |
$class = $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
|
|
|
1292 |
if (class_exists($class)) {
|
|
|
1293 |
$extension = new $class();
|
|
|
1294 |
|
|
|
1295 |
$expectedAlias = Container::underscore($basename);
|
|
|
1296 |
if ($expectedAlias != $extension->getAlias()) {
|
|
|
1297 |
throw new \LogicException(sprintf(
|
|
|
1298 |
'The extension alias for the default extension of a '.
|
|
|
1299 |
'bundle must be the underscored version of the '.
|
|
|
1300 |
'bundle name ("%s" instead of "%s")',
|
|
|
1301 |
$expectedAlias, $extension->getAlias()
|
|
|
1302 |
));
|
|
|
1303 |
}
|
|
|
1304 |
|
|
|
1305 |
$this->extension = $extension;
|
|
|
1306 |
} else {
|
|
|
1307 |
$this->extension = false;
|
|
|
1308 |
}
|
|
|
1309 |
}
|
|
|
1310 |
|
|
|
1311 |
if ($this->extension) {
|
|
|
1312 |
return $this->extension;
|
|
|
1313 |
}
|
|
|
1314 |
}
|
|
|
1315 |
|
|
|
1316 |
|
|
|
1317 |
public function getNamespace()
|
|
|
1318 |
{
|
|
|
1319 |
if (null === $this->reflected) {
|
|
|
1320 |
$this->reflected = new \ReflectionObject($this);
|
|
|
1321 |
}
|
|
|
1322 |
|
|
|
1323 |
return $this->reflected->getNamespaceName();
|
|
|
1324 |
}
|
|
|
1325 |
|
|
|
1326 |
|
|
|
1327 |
public function getPath()
|
|
|
1328 |
{
|
|
|
1329 |
if (null === $this->reflected) {
|
|
|
1330 |
$this->reflected = new \ReflectionObject($this);
|
|
|
1331 |
}
|
|
|
1332 |
|
|
|
1333 |
return dirname($this->reflected->getFileName());
|
|
|
1334 |
}
|
|
|
1335 |
|
|
|
1336 |
|
|
|
1337 |
public function getParent()
|
|
|
1338 |
{
|
|
|
1339 |
return null;
|
|
|
1340 |
}
|
|
|
1341 |
|
|
|
1342 |
|
|
|
1343 |
final public function getName()
|
|
|
1344 |
{
|
|
|
1345 |
if (null !== $this->name) {
|
|
|
1346 |
return $this->name;
|
|
|
1347 |
}
|
|
|
1348 |
|
|
|
1349 |
$name = get_class($this);
|
|
|
1350 |
$pos = strrpos($name, '\\');
|
|
|
1351 |
|
|
|
1352 |
return $this->name = false === $pos ? $name : substr($name, $pos + 1);
|
|
|
1353 |
}
|
|
|
1354 |
|
|
|
1355 |
|
|
|
1356 |
public function registerCommands(Application $application)
|
|
|
1357 |
{
|
|
|
1358 |
if (!$dir = realpath($this->getPath().'/Command')) {
|
|
|
1359 |
return;
|
|
|
1360 |
}
|
|
|
1361 |
|
|
|
1362 |
$finder = new Finder();
|
|
|
1363 |
$finder->files()->name('*Command.php')->in($dir);
|
|
|
1364 |
|
|
|
1365 |
$prefix = $this->getNamespace().'\\Command';
|
|
|
1366 |
foreach ($finder as $file) {
|
|
|
1367 |
$ns = $prefix;
|
|
|
1368 |
if ($relativePath = $file->getRelativePath()) {
|
|
|
1369 |
$ns .= '\\'.strtr($relativePath, '/', '\\');
|
|
|
1370 |
}
|
|
|
1371 |
$r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
|
|
|
1372 |
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
|
|
|
1373 |
$application->add($r->newInstance());
|
|
|
1374 |
}
|
|
|
1375 |
}
|
|
|
1376 |
}
|
|
|
1377 |
}
|
|
|
1378 |
}
|
|
|
1379 |
|
|
|
1380 |
|
|
|
1381 |
|
|
|
1382 |
|
|
|
1383 |
namespace Symfony\Component\HttpKernel\Bundle
|
|
|
1384 |
{
|
|
|
1385 |
|
|
|
1386 |
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
1387 |
|
|
|
1388 |
|
|
|
1389 |
interface BundleInterface
|
|
|
1390 |
{
|
|
|
1391 |
|
|
|
1392 |
function boot();
|
|
|
1393 |
|
|
|
1394 |
|
|
|
1395 |
function shutdown();
|
|
|
1396 |
|
|
|
1397 |
|
|
|
1398 |
function build(ContainerBuilder $container);
|
|
|
1399 |
|
|
|
1400 |
|
|
|
1401 |
function getContainerExtension();
|
|
|
1402 |
|
|
|
1403 |
|
|
|
1404 |
function getParent();
|
|
|
1405 |
|
|
|
1406 |
|
|
|
1407 |
function getName();
|
|
|
1408 |
|
|
|
1409 |
|
|
|
1410 |
function getNamespace();
|
|
|
1411 |
|
|
|
1412 |
|
|
|
1413 |
function getPath();
|
|
|
1414 |
}
|
|
|
1415 |
}
|
|
|
1416 |
|
|
|
1417 |
|
|
|
1418 |
|
|
|
1419 |
|
|
|
1420 |
namespace Symfony\Component\Config
|
|
|
1421 |
{
|
|
|
1422 |
|
|
|
1423 |
|
|
|
1424 |
class ConfigCache
|
|
|
1425 |
{
|
|
|
1426 |
private $debug;
|
|
|
1427 |
private $file;
|
|
|
1428 |
|
|
|
1429 |
|
|
|
1430 |
public function __construct($file, $debug)
|
|
|
1431 |
{
|
|
|
1432 |
$this->file = $file;
|
|
|
1433 |
$this->debug = (Boolean) $debug;
|
|
|
1434 |
}
|
|
|
1435 |
|
|
|
1436 |
|
|
|
1437 |
public function __toString()
|
|
|
1438 |
{
|
|
|
1439 |
return $this->file;
|
|
|
1440 |
}
|
|
|
1441 |
|
|
|
1442 |
|
|
|
1443 |
public function isFresh()
|
|
|
1444 |
{
|
|
|
1445 |
if (!file_exists($this->file)) {
|
|
|
1446 |
return false;
|
|
|
1447 |
}
|
|
|
1448 |
|
|
|
1449 |
if (!$this->debug) {
|
|
|
1450 |
return true;
|
|
|
1451 |
}
|
|
|
1452 |
|
|
|
1453 |
$metadata = $this->file.'.meta';
|
|
|
1454 |
if (!file_exists($metadata)) {
|
|
|
1455 |
return false;
|
|
|
1456 |
}
|
|
|
1457 |
|
|
|
1458 |
$time = filemtime($this->file);
|
|
|
1459 |
$meta = unserialize(file_get_contents($metadata));
|
|
|
1460 |
foreach ($meta as $resource) {
|
|
|
1461 |
if (!$resource->isFresh($time)) {
|
|
|
1462 |
return false;
|
|
|
1463 |
}
|
|
|
1464 |
}
|
|
|
1465 |
|
|
|
1466 |
return true;
|
|
|
1467 |
}
|
|
|
1468 |
|
|
|
1469 |
|
|
|
1470 |
public function write($content, array $metadata = null)
|
|
|
1471 |
{
|
|
|
1472 |
$dir = dirname($this->file);
|
|
|
1473 |
if (!is_dir($dir)) {
|
|
|
1474 |
if (false === @mkdir($dir, 0777, true)) {
|
|
|
1475 |
throw new \RuntimeException(sprintf('Unable to create the %s directory', $dir));
|
|
|
1476 |
}
|
|
|
1477 |
} elseif (!is_writable($dir)) {
|
|
|
1478 |
throw new \RuntimeException(sprintf('Unable to write in the %s directory', $dir));
|
|
|
1479 |
}
|
|
|
1480 |
|
|
|
1481 |
$tmpFile = tempnam(dirname($this->file), basename($this->file));
|
|
|
1482 |
if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $this->file)) {
|
|
|
1483 |
chmod($this->file, 0666);
|
|
|
1484 |
} else {
|
|
|
1485 |
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $this->file));
|
|
|
1486 |
}
|
|
|
1487 |
|
|
|
1488 |
if (null !== $metadata && true === $this->debug) {
|
|
|
1489 |
$file = $this->file.'.meta';
|
|
|
1490 |
$tmpFile = tempnam(dirname($file), basename($file));
|
|
|
1491 |
if (false !== @file_put_contents($tmpFile, serialize($metadata)) && @rename($tmpFile, $file)) {
|
|
|
1492 |
chmod($file, 0666);
|
|
|
1493 |
}
|
|
|
1494 |
}
|
|
|
1495 |
}
|
|
|
1496 |
}
|
|
|
1497 |
}
|