bootstrap.php.cache 40KB

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