bootstrap.php.cache 39KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498
  1. <?php
  2. namespace { require_once __DIR__.'/autoload.php'; }
  3. namespace Symfony\Component\DependencyInjection
  4. {
  5. interface ContainerAwareInterface
  6. {
  7. function setContainer(ContainerInterface $container = null);
  8. }
  9. }
  10. namespace Symfony\Component\DependencyInjection
  11. {
  12. interface ContainerInterface
  13. {
  14. const EXCEPTION_ON_INVALID_REFERENCE = 1;
  15. const NULL_ON_INVALID_REFERENCE = 2;
  16. const IGNORE_ON_INVALID_REFERENCE = 3;
  17. const SCOPE_CONTAINER = 'container';
  18. const SCOPE_PROTOTYPE = 'prototype';
  19. function set($id, $service, $scope = self::SCOPE_CONTAINER);
  20. function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
  21. function has($id);
  22. function getParameter($name);
  23. function hasParameter($name);
  24. function setParameter($name, $value);
  25. function enterScope($name);
  26. function leaveScope($name);
  27. function addScope(ScopeInterface $scope);
  28. function hasScope($name);
  29. function isScopeActive($name);
  30. }
  31. }
  32. namespace Symfony\Component\DependencyInjection
  33. {
  34. use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
  35. use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
  36. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  37. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  38. use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
  39. class Container implements ContainerInterface
  40. {
  41. protected $parameterBag;
  42. protected $services;
  43. protected $scopes;
  44. protected $scopeChildren;
  45. protected $scopedServices;
  46. protected $scopeStacks;
  47. protected $loading = array();
  48. public function __construct(ParameterBagInterface $parameterBag = null)
  49. {
  50. $this->parameterBag = null === $parameterBag ? new ParameterBag() : $parameterBag;
  51. $this->services = array();
  52. $this->scopes = array();
  53. $this->scopeChildren = array();
  54. $this->scopedServices = array();
  55. $this->scopeStacks = array();
  56. $this->set('service_container', $this);
  57. }
  58. public function compile()
  59. {
  60. $this->parameterBag->resolve();
  61. $this->parameterBag = new FrozenParameterBag($this->parameterBag->all());
  62. }
  63. public function isFrozen()
  64. {
  65. return $this->parameterBag instanceof FrozenParameterBag;
  66. }
  67. public function getParameterBag()
  68. {
  69. return $this->parameterBag;
  70. }
  71. public function getParameter($name)
  72. {
  73. return $this->parameterBag->get($name);
  74. }
  75. public function hasParameter($name)
  76. {
  77. return $this->parameterBag->has($name);
  78. }
  79. public function setParameter($name, $value)
  80. {
  81. $this->parameterBag->set($name, $value);
  82. }
  83. public function set($id, $service, $scope = self::SCOPE_CONTAINER)
  84. {
  85. if (self::SCOPE_PROTOTYPE === $scope) {
  86. throw new \InvalidArgumentException('You cannot set services of scope "prototype".');
  87. }
  88. $id = strtolower($id);
  89. if (self::SCOPE_CONTAINER !== $scope) {
  90. if (!isset($this->scopedServices[$scope])) {
  91. throw new \RuntimeException('You cannot set services of inactive scopes.');
  92. }
  93. $this->scopedServices[$scope][$id] = $service;
  94. }
  95. $this->services[$id] = $service;
  96. }
  97. public function has($id)
  98. {
  99. $id = strtolower($id);
  100. return isset($this->services[$id]) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service');
  101. }
  102. public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
  103. {
  104. $id = strtolower($id);
  105. if (isset($this->services[$id])) {
  106. return $this->services[$id];
  107. }
  108. if (isset($this->loading[$id])) {
  109. throw new ServiceCircularReferenceException($id, array_keys($this->loading));
  110. }
  111. if (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')) {
  112. $this->loading[$id] = true;
  113. try {
  114. $service = $this->$method();
  115. } catch (\Exception $e) {
  116. unset($this->loading[$id]);
  117. throw $e;
  118. }
  119. unset($this->loading[$id]);
  120. return $service;
  121. }
  122. if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
  123. throw new ServiceNotFoundException($id);
  124. }
  125. }
  126. public function getServiceIds()
  127. {
  128. $ids = array();
  129. $r = new \ReflectionClass($this);
  130. foreach ($r->getMethods() as $method) {
  131. if (preg_match('/^get(.+)Service$/', $method->getName(), $match)) {
  132. $ids[] = self::underscore($match[1]);
  133. }
  134. }
  135. return array_unique(array_merge($ids, array_keys($this->services)));
  136. }
  137. public function enterScope($name)
  138. {
  139. if (!isset($this->scopes[$name])) {
  140. throw new \InvalidArgumentException(sprintf('The scope "%s" does not exist.', $name));
  141. }
  142. if (self::SCOPE_CONTAINER !== $this->scopes[$name] && !isset($this->scopedServices[$this->scopes[$name]])) {
  143. throw new \RuntimeException(sprintf('The parent scope "%s" must be active when entering this scope.', $this->scopes[$name]));
  144. }
  145. if (isset($this->scopedServices[$name])) {
  146. $services = array($this->services, $name => $this->scopedServices[$name]);
  147. unset($this->scopedServices[$name]);
  148. foreach ($this->scopeChildren[$name] as $child) {
  149. $services[$child] = $this->scopedServices[$child];
  150. unset($this->scopedServices[$child]);
  151. }
  152. $this->services = call_user_func_array('array_diff_key', $services);
  153. array_shift($services);
  154. if (!isset($this->scopeStacks[$name])) {
  155. $this->scopeStacks[$name] = new \SplStack();
  156. }
  157. $this->scopeStacks[$name]->push($services);
  158. }
  159. $this->scopedServices[$name] = array();
  160. }
  161. public function leaveScope($name)
  162. {
  163. if (!isset($this->scopedServices[$name])) {
  164. throw new \InvalidArgumentException(sprintf('The scope "%s" is not active.', $name));
  165. }
  166. $services = array($this->services, $this->scopedServices[$name]);
  167. unset($this->scopedServices[$name]);
  168. foreach ($this->scopeChildren[$name] as $child) {
  169. if (!isset($this->scopedServices[$child])) {
  170. continue;
  171. }
  172. $services[] = $this->scopedServices[$child];
  173. unset($this->scopedServices[$child]);
  174. }
  175. $this->services = call_user_func_array('array_diff_key', $services);
  176. if (isset($this->scopeStacks[$name]) && count($this->scopeStacks[$name]) > 0) {
  177. $services = $this->scopeStacks[$name]->pop();
  178. $this->scopedServices += $services;
  179. array_unshift($services, $this->services);
  180. $this->services = call_user_func_array('array_merge', $services);
  181. }
  182. }
  183. public function addScope(ScopeInterface $scope)
  184. {
  185. $name = $scope->getName();
  186. $parentScope = $scope->getParentName();
  187. if (self::SCOPE_CONTAINER === $name || self::SCOPE_PROTOTYPE === $name) {
  188. throw new \InvalidArgumentException(sprintf('The scope "%s" is reserved.', $name));
  189. }
  190. if (isset($this->scopes[$name])) {
  191. throw new \InvalidArgumentException(sprintf('A scope with name "%s" already exists.', $name));
  192. }
  193. if (self::SCOPE_CONTAINER !== $parentScope && !isset($this->scopes[$parentScope])) {
  194. throw new \InvalidArgumentException(sprintf('The parent scope "%s" does not exist, or is invalid.', $parentScope));
  195. }
  196. $this->scopes[$name] = $parentScope;
  197. $this->scopeChildren[$name] = array();
  198. while ($parentScope !== self::SCOPE_CONTAINER) {
  199. $this->scopeChildren[$parentScope][] = $name;
  200. $parentScope = $this->scopes[$parentScope];
  201. }
  202. }
  203. public function hasScope($name)
  204. {
  205. return isset($this->scopes[$name]);
  206. }
  207. public function isScopeActive($name)
  208. {
  209. return isset($this->scopedServices[$name]);
  210. }
  211. static public function camelize($id)
  212. {
  213. return preg_replace_callback('/(^|_|\.)+(.)/', function ($match) { return ('.' === $match[1] ? '_' : '').strtoupper($match[2]); }, $id);
  214. }
  215. static public function underscore($id)
  216. {
  217. return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($id, '_', '.')));
  218. }
  219. }
  220. }
  221. namespace Symfony\Component\HttpKernel
  222. {
  223. use Symfony\Component\HttpFoundation\Request;
  224. use Symfony\Component\HttpFoundation\Response;
  225. interface HttpKernelInterface
  226. {
  227. const MASTER_REQUEST = 1;
  228. const SUB_REQUEST = 2;
  229. function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
  230. }
  231. }
  232. namespace Symfony\Component\HttpKernel
  233. {
  234. use Symfony\Component\DependencyInjection\ContainerInterface;
  235. use Symfony\Component\HttpKernel\HttpKernelInterface;
  236. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  237. use Symfony\Component\Config\Loader\LoaderInterface;
  238. interface KernelInterface extends HttpKernelInterface, \Serializable
  239. {
  240. function registerBundles();
  241. function registerContainerConfiguration(LoaderInterface $loader);
  242. function boot();
  243. function shutdown();
  244. function getBundles();
  245. function isClassInActiveBundle($class);
  246. function getBundle($name, $first = true);
  247. function locateResource($name, $dir = null, $first = true);
  248. function getName();
  249. function getEnvironment();
  250. function isDebug();
  251. function getRootDir();
  252. function getContainer();
  253. function getStartTime();
  254. function getCacheDir();
  255. function getLogDir();
  256. }
  257. }
  258. namespace Symfony\Component\HttpKernel
  259. {
  260. use Symfony\Component\DependencyInjection\ContainerInterface;
  261. use Symfony\Component\DependencyInjection\ContainerBuilder;
  262. use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
  263. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  264. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  265. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  266. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  267. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  268. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  269. use Symfony\Component\HttpFoundation\Request;
  270. use Symfony\Component\HttpKernel\HttpKernelInterface;
  271. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  272. use Symfony\Component\HttpKernel\Config\FileLocator;
  273. use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
  274. use Symfony\Component\HttpKernel\DependencyInjection\AddClassesToCachePass;
  275. use Symfony\Component\HttpKernel\DependencyInjection\Extension as DIExtension;
  276. use Symfony\Component\HttpKernel\Debug\ErrorHandler;
  277. use Symfony\Component\HttpKernel\Debug\ExceptionHandler;
  278. use Symfony\Component\Config\Loader\LoaderResolver;
  279. use Symfony\Component\Config\Loader\DelegatingLoader;
  280. use Symfony\Component\Config\ConfigCache;
  281. use Symfony\Component\ClassLoader\ClassCollectionLoader;
  282. use Symfony\Component\ClassLoader\DebugUniversalClassLoader;
  283. abstract class Kernel implements KernelInterface
  284. {
  285. protected $bundles;
  286. protected $bundleMap;
  287. protected $container;
  288. protected $rootDir;
  289. protected $environment;
  290. protected $debug;
  291. protected $booted;
  292. protected $name;
  293. protected $startTime;
  294. protected $classes;
  295. const VERSION = '2.0.8';
  296. public function __construct($environment, $debug)
  297. {
  298. $this->environment = $environment;
  299. $this->debug = (Boolean) $debug;
  300. $this->booted = false;
  301. $this->rootDir = $this->getRootDir();
  302. $this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
  303. $this->classes = array();
  304. if ($this->debug) {
  305. $this->startTime = microtime(true);
  306. }
  307. $this->init();
  308. }
  309. public function init()
  310. {
  311. if ($this->debug) {
  312. ini_set('display_errors', 1);
  313. error_reporting(-1);
  314. DebugUniversalClassLoader::enable();
  315. ErrorHandler::register();
  316. if ('cli' !== php_sapi_name()) {
  317. ExceptionHandler::register();
  318. }
  319. } else {
  320. ini_set('display_errors', 0);
  321. }
  322. }
  323. public function __clone()
  324. {
  325. if ($this->debug) {
  326. $this->startTime = microtime(true);
  327. }
  328. $this->booted = false;
  329. $this->container = null;
  330. }
  331. public function boot()
  332. {
  333. if (true === $this->booted) {
  334. return;
  335. }
  336. $this->initializeBundles();
  337. $this->initializeContainer();
  338. foreach ($this->getBundles() as $bundle) {
  339. $bundle->setContainer($this->container);
  340. $bundle->boot();
  341. }
  342. $this->booted = true;
  343. }
  344. public function shutdown()
  345. {
  346. if (false === $this->booted) {
  347. return;
  348. }
  349. $this->booted = false;
  350. foreach ($this->getBundles() as $bundle) {
  351. $bundle->shutdown();
  352. $bundle->setContainer(null);
  353. }
  354. $this->container = null;
  355. }
  356. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  357. {
  358. if (false === $this->booted) {
  359. $this->boot();
  360. }
  361. return $this->getHttpKernel()->handle($request, $type, $catch);
  362. }
  363. protected function getHttpKernel()
  364. {
  365. return $this->container->get('http_kernel');
  366. }
  367. public function getBundles()
  368. {
  369. return $this->bundles;
  370. }
  371. public function isClassInActiveBundle($class)
  372. {
  373. foreach ($this->getBundles() as $bundle) {
  374. if (0 === strpos($class, $bundle->getNamespace())) {
  375. return true;
  376. }
  377. }
  378. return false;
  379. }
  380. public function getBundle($name, $first = true)
  381. {
  382. if (!isset($this->bundleMap[$name])) {
  383. 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)));
  384. }
  385. if (true === $first) {
  386. return $this->bundleMap[$name][0];
  387. }
  388. return $this->bundleMap[$name];
  389. }
  390. public function locateResource($name, $dir = null, $first = true)
  391. {
  392. if ('@' !== $name[0]) {
  393. throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
  394. }
  395. if (false !== strpos($name, '..')) {
  396. throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
  397. }
  398. $bundleName = substr($name, 1);
  399. $path = '';
  400. if (false !== strpos($bundleName, '/')) {
  401. list($bundleName, $path) = explode('/', $bundleName, 2);
  402. }
  403. $isResource = 0 === strpos($path, 'Resources') && null !== $dir;
  404. $overridePath = substr($path, 9);
  405. $resourceBundle = null;
  406. $bundles = $this->getBundle($bundleName, false);
  407. $files = array();
  408. foreach ($bundles as $bundle) {
  409. if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
  410. if (null !== $resourceBundle) {
  411. 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.',
  412. $file,
  413. $resourceBundle,
  414. $dir.'/'.$bundles[0]->getName().$overridePath
  415. ));
  416. }
  417. if ($first) {
  418. return $file;
  419. }
  420. $files[] = $file;
  421. }
  422. if (file_exists($file = $bundle->getPath().'/'.$path)) {
  423. if ($first && !$isResource) {
  424. return $file;
  425. }
  426. $files[] = $file;
  427. $resourceBundle = $bundle->getName();
  428. }
  429. }
  430. if (count($files) > 0) {
  431. return $first && $isResource ? $files[0] : $files;
  432. }
  433. throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
  434. }
  435. public function getName()
  436. {
  437. return $this->name;
  438. }
  439. public function getEnvironment()
  440. {
  441. return $this->environment;
  442. }
  443. public function isDebug()
  444. {
  445. return $this->debug;
  446. }
  447. public function getRootDir()
  448. {
  449. if (null === $this->rootDir) {
  450. $r = new \ReflectionObject($this);
  451. $this->rootDir = dirname($r->getFileName());
  452. }
  453. return $this->rootDir;
  454. }
  455. public function getContainer()
  456. {
  457. return $this->container;
  458. }
  459. public function loadClassCache($name = 'classes', $extension = '.php')
  460. {
  461. if (!$this->booted && file_exists($this->getCacheDir().'/classes.map')) {
  462. ClassCollectionLoader::load(include($this->getCacheDir().'/classes.map'), $this->getCacheDir(), $name, $this->debug, false, $extension);
  463. }
  464. }
  465. public function setClassCache(array $classes)
  466. {
  467. file_put_contents($this->getCacheDir().'/classes.map', sprintf('<?php return %s;', var_export($classes, true)));
  468. }
  469. public function getStartTime()
  470. {
  471. return $this->debug ? $this->startTime : -INF;
  472. }
  473. public function getCacheDir()
  474. {
  475. return $this->rootDir.'/cache/'.$this->environment;
  476. }
  477. public function getLogDir()
  478. {
  479. return $this->rootDir.'/logs';
  480. }
  481. protected function initializeBundles()
  482. {
  483. $this->bundles = array();
  484. $topMostBundles = array();
  485. $directChildren = array();
  486. foreach ($this->registerBundles() as $bundle) {
  487. $name = $bundle->getName();
  488. if (isset($this->bundles[$name])) {
  489. throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name));
  490. }
  491. $this->bundles[$name] = $bundle;
  492. if ($parentName = $bundle->getParent()) {
  493. if (isset($directChildren[$parentName])) {
  494. throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
  495. }
  496. if ($parentName == $name) {
  497. throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name));
  498. }
  499. $directChildren[$parentName] = $name;
  500. } else {
  501. $topMostBundles[$name] = $bundle;
  502. }
  503. }
  504. if (count($diff = array_values(array_diff(array_keys($directChildren), array_keys($this->bundles))))) {
  505. throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0]));
  506. }
  507. $this->bundleMap = array();
  508. foreach ($topMostBundles as $name => $bundle) {
  509. $bundleMap = array($bundle);
  510. $hierarchy = array($name);
  511. while (isset($directChildren[$name])) {
  512. $name = $directChildren[$name];
  513. array_unshift($bundleMap, $this->bundles[$name]);
  514. $hierarchy[] = $name;
  515. }
  516. foreach ($hierarchy as $bundle) {
  517. $this->bundleMap[$bundle] = $bundleMap;
  518. array_pop($bundleMap);
  519. }
  520. }
  521. }
  522. protected function getContainerClass()
  523. {
  524. return $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
  525. }
  526. protected function getContainerBaseClass()
  527. {
  528. return 'Container';
  529. }
  530. protected function initializeContainer()
  531. {
  532. $class = $this->getContainerClass();
  533. $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
  534. $fresh = true;
  535. if (!$cache->isFresh()) {
  536. $container = $this->buildContainer();
  537. $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
  538. $fresh = false;
  539. }
  540. require_once $cache;
  541. $this->container = new $class();
  542. $this->container->set('kernel', $this);
  543. if (!$fresh && $this->container->has('cache_warmer')) {
  544. $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
  545. }
  546. }
  547. protected function getKernelParameters()
  548. {
  549. $bundles = array();
  550. foreach ($this->bundles as $name => $bundle) {
  551. $bundles[$name] = get_class($bundle);
  552. }
  553. return array_merge(
  554. array(
  555. 'kernel.root_dir' => $this->rootDir,
  556. 'kernel.environment' => $this->environment,
  557. 'kernel.debug' => $this->debug,
  558. 'kernel.name' => $this->name,
  559. 'kernel.cache_dir' => $this->getCacheDir(),
  560. 'kernel.logs_dir' => $this->getLogDir(),
  561. 'kernel.bundles' => $bundles,
  562. 'kernel.charset' => 'UTF-8',
  563. 'kernel.container_class' => $this->getContainerClass(),
  564. ),
  565. $this->getEnvParameters()
  566. );
  567. }
  568. protected function getEnvParameters()
  569. {
  570. $parameters = array();
  571. foreach ($_SERVER as $key => $value) {
  572. if ('SYMFONY__' === substr($key, 0, 9)) {
  573. $parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value;
  574. }
  575. }
  576. return $parameters;
  577. }
  578. protected function buildContainer()
  579. {
  580. foreach (array('cache' => $this->getCacheDir(), 'logs' => $this->getLogDir()) as $name => $dir) {
  581. if (!is_dir($dir)) {
  582. if (false === @mkdir($dir, 0777, true)) {
  583. throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n", $name, $dir));
  584. }
  585. } elseif (!is_writable($dir)) {
  586. throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", $name, $dir));
  587. }
  588. }
  589. $container = new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
  590. $extensions = array();
  591. foreach ($this->bundles as $bundle) {
  592. $bundle->build($container);
  593. if ($extension = $bundle->getContainerExtension()) {
  594. $container->registerExtension($extension);
  595. $extensions[] = $extension->getAlias();
  596. }
  597. if ($this->debug) {
  598. $container->addObjectResource($bundle);
  599. }
  600. }
  601. $container->addObjectResource($this);
  602. $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
  603. if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
  604. $container->merge($cont);
  605. }
  606. $container->addCompilerPass(new AddClassesToCachePass($this));
  607. $container->compile();
  608. return $container;
  609. }
  610. protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
  611. {
  612. $dumper = new PhpDumper($container);
  613. $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass));
  614. if (!$this->debug) {
  615. $content = self::stripComments($content);
  616. }
  617. $cache->write($content, $container->getResources());
  618. }
  619. protected function getContainerLoader(ContainerInterface $container)
  620. {
  621. $locator = new FileLocator($this);
  622. $resolver = new LoaderResolver(array(
  623. new XmlFileLoader($container, $locator),
  624. new YamlFileLoader($container, $locator),
  625. new IniFileLoader($container, $locator),
  626. new PhpFileLoader($container, $locator),
  627. new ClosureLoader($container),
  628. ));
  629. return new DelegatingLoader($resolver);
  630. }
  631. static public function stripComments($source)
  632. {
  633. if (!function_exists('token_get_all')) {
  634. return $source;
  635. }
  636. $output = '';
  637. foreach (token_get_all($source) as $token) {
  638. if (is_string($token)) {
  639. $output .= $token;
  640. } elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
  641. $output .= $token[1];
  642. }
  643. }
  644. $output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
  645. return $output;
  646. }
  647. public function serialize()
  648. {
  649. return serialize(array($this->environment, $this->debug));
  650. }
  651. public function unserialize($data)
  652. {
  653. list($environment, $debug) = unserialize($data);
  654. $this->__construct($environment, $debug);
  655. }
  656. }
  657. }
  658. namespace Symfony\Component\ClassLoader
  659. {
  660. class ClassCollectionLoader
  661. {
  662. static private $loaded;
  663. static public function load($classes, $cacheDir, $name, $autoReload, $adaptive = false, $extension = '.php')
  664. {
  665. if (isset(self::$loaded[$name])) {
  666. return;
  667. }
  668. self::$loaded[$name] = true;
  669. if ($adaptive) {
  670. $classes = array_diff($classes, get_declared_classes(), get_declared_interfaces());
  671. $name = $name.'-'.substr(md5(implode('|', $classes)), 0, 5);
  672. }
  673. $cache = $cacheDir.'/'.$name.$extension;
  674. $reload = false;
  675. if ($autoReload) {
  676. $metadata = $cacheDir.'/'.$name.$extension.'.meta';
  677. if (!file_exists($metadata) || !file_exists($cache)) {
  678. $reload = true;
  679. } else {
  680. $time = filemtime($cache);
  681. $meta = unserialize(file_get_contents($metadata));
  682. if ($meta[1] != $classes) {
  683. $reload = true;
  684. } else {
  685. foreach ($meta[0] as $resource) {
  686. if (!file_exists($resource) || filemtime($resource) > $time) {
  687. $reload = true;
  688. break;
  689. }
  690. }
  691. }
  692. }
  693. }
  694. if (!$reload && file_exists($cache)) {
  695. require_once $cache;
  696. return;
  697. }
  698. $files = array();
  699. $content = '';
  700. foreach ($classes as $class) {
  701. if (!class_exists($class) && !interface_exists($class) && (!function_exists('trait_exists') || !trait_exists($class))) {
  702. throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
  703. }
  704. $r = new \ReflectionClass($class);
  705. $files[] = $r->getFileName();
  706. $c = preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', file_get_contents($r->getFileName()));
  707. if (!$r->inNamespace()) {
  708. $c = "\nnamespace\n{\n".self::stripComments($c)."\n}\n";
  709. } else {
  710. $c = self::fixNamespaceDeclarations('<?php '.$c);
  711. $c = preg_replace('/^\s*<\?php/', '', $c);
  712. }
  713. $content .= $c;
  714. }
  715. if (!is_dir(dirname($cache))) {
  716. mkdir(dirname($cache), 0777, true);
  717. }
  718. self::writeCacheFile($cache, '<?php '.$content);
  719. if ($autoReload) {
  720. self::writeCacheFile($metadata, serialize(array($files, $classes)));
  721. }
  722. }
  723. static public function fixNamespaceDeclarations($source)
  724. {
  725. if (!function_exists('token_get_all')) {
  726. return $source;
  727. }
  728. $output = '';
  729. $inNamespace = false;
  730. $tokens = token_get_all($source);
  731. for ($i = 0, $max = count($tokens); $i < $max; $i++) {
  732. $token = $tokens[$i];
  733. if (is_string($token)) {
  734. $output .= $token;
  735. } elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
  736. continue;
  737. } elseif (T_NAMESPACE === $token[0]) {
  738. if ($inNamespace) {
  739. $output .= "}\n";
  740. }
  741. $output .= $token[1];
  742. while (($t = $tokens[++$i]) && is_array($t) && in_array($t[0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
  743. $output .= $t[1];
  744. }
  745. if (is_string($t) && '{' === $t) {
  746. $inNamespace = false;
  747. --$i;
  748. } else {
  749. $output .= "\n{";
  750. $inNamespace = true;
  751. }
  752. } else {
  753. $output .= $token[1];
  754. }
  755. }
  756. if ($inNamespace) {
  757. $output .= "}\n";
  758. }
  759. return $output;
  760. }
  761. static private function writeCacheFile($file, $content)
  762. {
  763. $tmpFile = tempnam(dirname($file), basename($file));
  764. if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
  765. chmod($file, 0644);
  766. return;
  767. }
  768. throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
  769. }
  770. static private function stripComments($source)
  771. {
  772. if (!function_exists('token_get_all')) {
  773. return $source;
  774. }
  775. $output = '';
  776. foreach (token_get_all($source) as $token) {
  777. if (is_string($token)) {
  778. $output .= $token;
  779. } elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
  780. $output .= $token[1];
  781. }
  782. }
  783. $output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
  784. return $output;
  785. }
  786. }
  787. }
  788. namespace Symfony\Component\ClassLoader
  789. {
  790. class UniversalClassLoader
  791. {
  792. private $namespaces = array();
  793. private $prefixes = array();
  794. private $namespaceFallbacks = array();
  795. private $prefixFallbacks = array();
  796. public function getNamespaces()
  797. {
  798. return $this->namespaces;
  799. }
  800. public function getPrefixes()
  801. {
  802. return $this->prefixes;
  803. }
  804. public function getNamespaceFallbacks()
  805. {
  806. return $this->namespaceFallbacks;
  807. }
  808. public function getPrefixFallbacks()
  809. {
  810. return $this->prefixFallbacks;
  811. }
  812. public function registerNamespaceFallbacks(array $dirs)
  813. {
  814. $this->namespaceFallbacks = $dirs;
  815. }
  816. public function registerPrefixFallbacks(array $dirs)
  817. {
  818. $this->prefixFallbacks = $dirs;
  819. }
  820. public function registerNamespaces(array $namespaces)
  821. {
  822. foreach ($namespaces as $namespace => $locations) {
  823. $this->namespaces[$namespace] = (array) $locations;
  824. }
  825. }
  826. public function registerNamespace($namespace, $paths)
  827. {
  828. $this->namespaces[$namespace] = (array) $paths;
  829. }
  830. public function registerPrefixes(array $classes)
  831. {
  832. foreach ($classes as $prefix => $locations) {
  833. $this->prefixes[$prefix] = (array) $locations;
  834. }
  835. }
  836. public function registerPrefix($prefix, $paths)
  837. {
  838. $this->prefixes[$prefix] = (array) $paths;
  839. }
  840. public function register($prepend = false)
  841. {
  842. spl_autoload_register(array($this, 'loadClass'), true, $prepend);
  843. }
  844. public function loadClass($class)
  845. {
  846. if ($file = $this->findFile($class)) {
  847. require $file;
  848. }
  849. }
  850. public function findFile($class)
  851. {
  852. if ('\\' == $class[0]) {
  853. $class = substr($class, 1);
  854. }
  855. if (false !== $pos = strrpos($class, '\\')) {
  856. $namespace = substr($class, 0, $pos);
  857. foreach ($this->namespaces as $ns => $dirs) {
  858. if (0 !== strpos($namespace, $ns)) {
  859. continue;
  860. }
  861. foreach ($dirs as $dir) {
  862. $className = substr($class, $pos + 1);
  863. $file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
  864. if (file_exists($file)) {
  865. return $file;
  866. }
  867. }
  868. }
  869. foreach ($this->namespaceFallbacks as $dir) {
  870. $file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php';
  871. if (file_exists($file)) {
  872. return $file;
  873. }
  874. }
  875. } else {
  876. foreach ($this->prefixes as $prefix => $dirs) {
  877. if (0 !== strpos($class, $prefix)) {
  878. continue;
  879. }
  880. foreach ($dirs as $dir) {
  881. $file = $dir.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
  882. if (file_exists($file)) {
  883. return $file;
  884. }
  885. }
  886. }
  887. foreach ($this->prefixFallbacks as $dir) {
  888. $file = $dir.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
  889. if (file_exists($file)) {
  890. return $file;
  891. }
  892. }
  893. }
  894. }
  895. }
  896. }
  897. namespace Symfony\Component\HttpKernel\Bundle
  898. {
  899. use Symfony\Component\DependencyInjection\ContainerAware;
  900. use Symfony\Component\DependencyInjection\ContainerBuilder;
  901. use Symfony\Component\DependencyInjection\Container;
  902. use Symfony\Component\Console\Application;
  903. use Symfony\Component\Finder\Finder;
  904. abstract class Bundle extends ContainerAware implements BundleInterface
  905. {
  906. protected $name;
  907. protected $reflected;
  908. protected $extension;
  909. public function boot()
  910. {
  911. }
  912. public function shutdown()
  913. {
  914. }
  915. public function build(ContainerBuilder $container)
  916. {
  917. }
  918. public function getContainerExtension()
  919. {
  920. if (null === $this->extension) {
  921. $basename = preg_replace('/Bundle$/', '', $this->getName());
  922. $class = $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
  923. if (class_exists($class)) {
  924. $extension = new $class();
  925. $expectedAlias = Container::underscore($basename);
  926. if ($expectedAlias != $extension->getAlias()) {
  927. throw new \LogicException(sprintf(
  928. 'The extension alias for the default extension of a '.
  929. 'bundle must be the underscored version of the '.
  930. 'bundle name ("%s" instead of "%s")',
  931. $expectedAlias, $extension->getAlias()
  932. ));
  933. }
  934. $this->extension = $extension;
  935. } else {
  936. $this->extension = false;
  937. }
  938. }
  939. if ($this->extension) {
  940. return $this->extension;
  941. }
  942. }
  943. public function getNamespace()
  944. {
  945. if (null === $this->reflected) {
  946. $this->reflected = new \ReflectionObject($this);
  947. }
  948. return $this->reflected->getNamespaceName();
  949. }
  950. public function getPath()
  951. {
  952. if (null === $this->reflected) {
  953. $this->reflected = new \ReflectionObject($this);
  954. }
  955. return dirname($this->reflected->getFileName());
  956. }
  957. public function getParent()
  958. {
  959. return null;
  960. }
  961. final public function getName()
  962. {
  963. if (null !== $this->name) {
  964. return $this->name;
  965. }
  966. $name = get_class($this);
  967. $pos = strrpos($name, '\\');
  968. return $this->name = false === $pos ? $name : substr($name, $pos + 1);
  969. }
  970. public function registerCommands(Application $application)
  971. {
  972. if (!$dir = realpath($this->getPath().'/Command')) {
  973. return;
  974. }
  975. $finder = new Finder();
  976. $finder->files()->name('*Command.php')->in($dir);
  977. $prefix = $this->getNamespace().'\\Command';
  978. foreach ($finder as $file) {
  979. $ns = $prefix;
  980. if ($relativePath = $file->getRelativePath()) {
  981. $ns .= '\\'.strtr($relativePath, '/', '\\');
  982. }
  983. $r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
  984. if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
  985. $application->add($r->newInstance());
  986. }
  987. }
  988. }
  989. }
  990. }
  991. namespace Symfony\Component\HttpKernel\Bundle
  992. {
  993. use Symfony\Component\DependencyInjection\ContainerBuilder;
  994. interface BundleInterface
  995. {
  996. function boot();
  997. function shutdown();
  998. function build(ContainerBuilder $container);
  999. function getContainerExtension();
  1000. function getParent();
  1001. function getName();
  1002. function getNamespace();
  1003. function getPath();
  1004. }
  1005. }
  1006. namespace Symfony\Component\Config
  1007. {
  1008. class ConfigCache
  1009. {
  1010. private $debug;
  1011. private $file;
  1012. public function __construct($file, $debug)
  1013. {
  1014. $this->file = $file;
  1015. $this->debug = (Boolean) $debug;
  1016. }
  1017. public function __toString()
  1018. {
  1019. return $this->file;
  1020. }
  1021. public function isFresh()
  1022. {
  1023. if (!file_exists($this->file)) {
  1024. return false;
  1025. }
  1026. if (!$this->debug) {
  1027. return true;
  1028. }
  1029. $metadata = $this->file.'.meta';
  1030. if (!file_exists($metadata)) {
  1031. return false;
  1032. }
  1033. $time = filemtime($this->file);
  1034. $meta = unserialize(file_get_contents($metadata));
  1035. foreach ($meta as $resource) {
  1036. if (!$resource->isFresh($time)) {
  1037. return false;
  1038. }
  1039. }
  1040. return true;
  1041. }
  1042. public function write($content, array $metadata = null)
  1043. {
  1044. $dir = dirname($this->file);
  1045. if (!is_dir($dir)) {
  1046. if (false === @mkdir($dir, 0777, true)) {
  1047. throw new \RuntimeException(sprintf('Unable to create the %s directory', $dir));
  1048. }
  1049. } elseif (!is_writable($dir)) {
  1050. throw new \RuntimeException(sprintf('Unable to write in the %s directory', $dir));
  1051. }
  1052. $tmpFile = tempnam(dirname($this->file), basename($this->file));
  1053. if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $this->file)) {
  1054. chmod($this->file, 0666);
  1055. } else {
  1056. throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $this->file));
  1057. }
  1058. if (null !== $metadata && true === $this->debug) {
  1059. $file = $this->file.'.meta';
  1060. $tmpFile = tempnam(dirname($file), basename($file));
  1061. if (false !== @file_put_contents($tmpFile, serialize($metadata)) && @rename($tmpFile, $file)) {
  1062. chmod($file, 0666);
  1063. }
  1064. }
  1065. }
  1066. }
  1067. }