bootstrap.php.cache 40KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502
  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. 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. public function set($id, $service, $scope = self::SCOPE_CONTAINER);
  20. public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
  21. public function has($id);
  22. public function getParameter($name);
  23. public function hasParameter($name);
  24. public function setParameter($name, $value);
  25. public function enterScope($name);
  26. public function leaveScope($name);
  27. public function addScope(ScopeInterface $scope);
  28. public function hasScope($name);
  29. public 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->name, $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. public static function camelize($id)
  212. {
  213. return preg_replace_callback('/(^|_|\.)+(.)/', function ($match) { return ('.' === $match[1] ? '_' : '').strtoupper($match[2]); }, $id);
  214. }
  215. public static 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. public 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. public function registerBundles();
  241. public function registerContainerConfiguration(LoaderInterface $loader);
  242. public function boot();
  243. public function shutdown();
  244. public function getBundles();
  245. public function isClassInActiveBundle($class);
  246. public function getBundle($name, $first = true);
  247. public function locateResource($name, $dir = null, $first = true);
  248. public function getName();
  249. public function getEnvironment();
  250. public function isDebug();
  251. public function getRootDir();
  252. public function getContainer();
  253. public function getStartTime();
  254. public function getCacheDir();
  255. public 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\Debug\ErrorHandler;
  276. use Symfony\Component\HttpKernel\Debug\ExceptionHandler;
  277. use Symfony\Component\Config\Loader\LoaderResolver;
  278. use Symfony\Component\Config\Loader\DelegatingLoader;
  279. use Symfony\Component\Config\ConfigCache;
  280. use Symfony\Component\ClassLoader\ClassCollectionLoader;
  281. use Symfony\Component\ClassLoader\DebugUniversalClassLoader;
  282. abstract class Kernel implements KernelInterface
  283. {
  284. protected $bundles;
  285. protected $bundleMap;
  286. protected $container;
  287. protected $rootDir;
  288. protected $environment;
  289. protected $debug;
  290. protected $booted;
  291. protected $name;
  292. protected $startTime;
  293. protected $classes;
  294. const VERSION = '2.0.17';
  295. const VERSION_ID = '20017';
  296. const MAJOR_VERSION = '2';
  297. const MINOR_VERSION = '0';
  298. const RELEASE_VERSION = '17';
  299. const EXTRA_VERSION = '';
  300. public function __construct($environment, $debug)
  301. {
  302. $this->environment = $environment;
  303. $this->debug = (Boolean) $debug;
  304. $this->booted = false;
  305. $this->rootDir = $this->getRootDir();
  306. $this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
  307. $this->classes = array();
  308. if ($this->debug) {
  309. $this->startTime = microtime(true);
  310. }
  311. $this->init();
  312. }
  313. public function init()
  314. {
  315. if ($this->debug) {
  316. ini_set('display_errors', 1);
  317. error_reporting(-1);
  318. DebugUniversalClassLoader::enable();
  319. ErrorHandler::register();
  320. if ('cli' !== php_sapi_name()) {
  321. ExceptionHandler::register();
  322. }
  323. } else {
  324. ini_set('display_errors', 0);
  325. }
  326. }
  327. public function __clone()
  328. {
  329. if ($this->debug) {
  330. $this->startTime = microtime(true);
  331. }
  332. $this->booted = false;
  333. $this->container = null;
  334. }
  335. public function boot()
  336. {
  337. if (true === $this->booted) {
  338. return;
  339. }
  340. $this->initializeBundles();
  341. $this->initializeContainer();
  342. foreach ($this->getBundles() as $bundle) {
  343. $bundle->setContainer($this->container);
  344. $bundle->boot();
  345. }
  346. $this->booted = true;
  347. }
  348. public function shutdown()
  349. {
  350. if (false === $this->booted) {
  351. return;
  352. }
  353. $this->booted = false;
  354. foreach ($this->getBundles() as $bundle) {
  355. $bundle->shutdown();
  356. $bundle->setContainer(null);
  357. }
  358. $this->container = null;
  359. }
  360. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  361. {
  362. if (false === $this->booted) {
  363. $this->boot();
  364. }
  365. return $this->getHttpKernel()->handle($request, $type, $catch);
  366. }
  367. protected function getHttpKernel()
  368. {
  369. return $this->container->get('http_kernel');
  370. }
  371. public function getBundles()
  372. {
  373. return $this->bundles;
  374. }
  375. public function isClassInActiveBundle($class)
  376. {
  377. foreach ($this->getBundles() as $bundle) {
  378. if (0 === strpos($class, $bundle->getNamespace())) {
  379. return true;
  380. }
  381. }
  382. return false;
  383. }
  384. public function getBundle($name, $first = true)
  385. {
  386. if (!isset($this->bundleMap[$name])) {
  387. 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)));
  388. }
  389. if (true === $first) {
  390. return $this->bundleMap[$name][0];
  391. }
  392. return $this->bundleMap[$name];
  393. }
  394. public function locateResource($name, $dir = null, $first = true)
  395. {
  396. if ('@' !== $name[0]) {
  397. throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
  398. }
  399. if (false !== strpos($name, '..')) {
  400. throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
  401. }
  402. $bundleName = substr($name, 1);
  403. $path = '';
  404. if (false !== strpos($bundleName, '/')) {
  405. list($bundleName, $path) = explode('/', $bundleName, 2);
  406. }
  407. $isResource = 0 === strpos($path, 'Resources') && null !== $dir;
  408. $overridePath = substr($path, 9);
  409. $resourceBundle = null;
  410. $bundles = $this->getBundle($bundleName, false);
  411. $files = array();
  412. foreach ($bundles as $bundle) {
  413. if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
  414. if (null !== $resourceBundle) {
  415. 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.',
  416. $file,
  417. $resourceBundle,
  418. $dir.'/'.$bundles[0]->getName().$overridePath
  419. ));
  420. }
  421. if ($first) {
  422. return $file;
  423. }
  424. $files[] = $file;
  425. }
  426. if (file_exists($file = $bundle->getPath().'/'.$path)) {
  427. if ($first && !$isResource) {
  428. return $file;
  429. }
  430. $files[] = $file;
  431. $resourceBundle = $bundle->getName();
  432. }
  433. }
  434. if (count($files) > 0) {
  435. return $first && $isResource ? $files[0] : $files;
  436. }
  437. throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
  438. }
  439. public function getName()
  440. {
  441. return $this->name;
  442. }
  443. public function getEnvironment()
  444. {
  445. return $this->environment;
  446. }
  447. public function isDebug()
  448. {
  449. return $this->debug;
  450. }
  451. public function getRootDir()
  452. {
  453. if (null === $this->rootDir) {
  454. $r = new \ReflectionObject($this);
  455. $this->rootDir = str_replace('\\', '/', dirname($r->getFileName()));
  456. }
  457. return $this->rootDir;
  458. }
  459. public function getContainer()
  460. {
  461. return $this->container;
  462. }
  463. public function loadClassCache($name = 'classes', $extension = '.php')
  464. {
  465. if (!$this->booted && file_exists($this->getCacheDir().'/classes.map')) {
  466. ClassCollectionLoader::load(include($this->getCacheDir().'/classes.map'), $this->getCacheDir(), $name, $this->debug, false, $extension);
  467. }
  468. }
  469. public function setClassCache(array $classes)
  470. {
  471. file_put_contents($this->getCacheDir().'/classes.map', sprintf('<?php return %s;', var_export($classes, true)));
  472. }
  473. public function getStartTime()
  474. {
  475. return $this->debug ? $this->startTime : -INF;
  476. }
  477. public function getCacheDir()
  478. {
  479. return $this->rootDir.'/cache/'.$this->environment;
  480. }
  481. public function getLogDir()
  482. {
  483. return $this->rootDir.'/logs';
  484. }
  485. protected function initializeBundles()
  486. {
  487. $this->bundles = array();
  488. $topMostBundles = array();
  489. $directChildren = array();
  490. foreach ($this->registerBundles() as $bundle) {
  491. $name = $bundle->getName();
  492. if (isset($this->bundles[$name])) {
  493. throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name));
  494. }
  495. $this->bundles[$name] = $bundle;
  496. if ($parentName = $bundle->getParent()) {
  497. if (isset($directChildren[$parentName])) {
  498. throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
  499. }
  500. if ($parentName == $name) {
  501. throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name));
  502. }
  503. $directChildren[$parentName] = $name;
  504. } else {
  505. $topMostBundles[$name] = $bundle;
  506. }
  507. }
  508. if (count($diff = array_values(array_diff(array_keys($directChildren), array_keys($this->bundles))))) {
  509. throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0]));
  510. }
  511. $this->bundleMap = array();
  512. foreach ($topMostBundles as $name => $bundle) {
  513. $bundleMap = array($bundle);
  514. $hierarchy = array($name);
  515. while (isset($directChildren[$name])) {
  516. $name = $directChildren[$name];
  517. array_unshift($bundleMap, $this->bundles[$name]);
  518. $hierarchy[] = $name;
  519. }
  520. foreach ($hierarchy as $bundle) {
  521. $this->bundleMap[$bundle] = $bundleMap;
  522. array_pop($bundleMap);
  523. }
  524. }
  525. }
  526. protected function getContainerClass()
  527. {
  528. return $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
  529. }
  530. protected function getContainerBaseClass()
  531. {
  532. return 'Container';
  533. }
  534. protected function initializeContainer()
  535. {
  536. $class = $this->getContainerClass();
  537. $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
  538. $fresh = true;
  539. if (!$cache->isFresh()) {
  540. $container = $this->buildContainer();
  541. $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
  542. $fresh = false;
  543. }
  544. require_once $cache;
  545. $this->container = new $class();
  546. $this->container->set('kernel', $this);
  547. if (!$fresh && $this->container->has('cache_warmer')) {
  548. $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
  549. }
  550. }
  551. protected function getKernelParameters()
  552. {
  553. $bundles = array();
  554. foreach ($this->bundles as $name => $bundle) {
  555. $bundles[$name] = get_class($bundle);
  556. }
  557. return array_merge(
  558. array(
  559. 'kernel.root_dir' => $this->rootDir,
  560. 'kernel.environment' => $this->environment,
  561. 'kernel.debug' => $this->debug,
  562. 'kernel.name' => $this->name,
  563. 'kernel.cache_dir' => $this->getCacheDir(),
  564. 'kernel.logs_dir' => $this->getLogDir(),
  565. 'kernel.bundles' => $bundles,
  566. 'kernel.charset' => 'UTF-8',
  567. 'kernel.container_class' => $this->getContainerClass(),
  568. ),
  569. $this->getEnvParameters()
  570. );
  571. }
  572. protected function getEnvParameters()
  573. {
  574. $parameters = array();
  575. foreach ($_SERVER as $key => $value) {
  576. if (0 === strpos($key, 'SYMFONY__')) {
  577. $parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value;
  578. }
  579. }
  580. return $parameters;
  581. }
  582. protected function buildContainer()
  583. {
  584. foreach (array('cache' => $this->getCacheDir(), 'logs' => $this->getLogDir()) as $name => $dir) {
  585. if (!is_dir($dir)) {
  586. if (false === @mkdir($dir, 0777, true)) {
  587. throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n", $name, $dir));
  588. }
  589. } elseif (!is_writable($dir)) {
  590. throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", $name, $dir));
  591. }
  592. }
  593. $container = new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
  594. $extensions = array();
  595. foreach ($this->bundles as $bundle) {
  596. $bundle->build($container);
  597. if ($extension = $bundle->getContainerExtension()) {
  598. $container->registerExtension($extension);
  599. $extensions[] = $extension->getAlias();
  600. }
  601. if ($this->debug) {
  602. $container->addObjectResource($bundle);
  603. }
  604. }
  605. $container->addObjectResource($this);
  606. $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
  607. if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
  608. $container->merge($cont);
  609. }
  610. $container->addCompilerPass(new AddClassesToCachePass($this));
  611. $container->compile();
  612. return $container;
  613. }
  614. protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
  615. {
  616. $dumper = new PhpDumper($container);
  617. $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass));
  618. if (!$this->debug) {
  619. $content = self::stripComments($content);
  620. }
  621. $cache->write($content, $container->getResources());
  622. }
  623. protected function getContainerLoader(ContainerInterface $container)
  624. {
  625. $locator = new FileLocator($this);
  626. $resolver = new LoaderResolver(array(
  627. new XmlFileLoader($container, $locator),
  628. new YamlFileLoader($container, $locator),
  629. new IniFileLoader($container, $locator),
  630. new PhpFileLoader($container, $locator),
  631. new ClosureLoader($container),
  632. ));
  633. return new DelegatingLoader($resolver);
  634. }
  635. public static function stripComments($source)
  636. {
  637. if (!function_exists('token_get_all')) {
  638. return $source;
  639. }
  640. $output = '';
  641. foreach (token_get_all($source) as $token) {
  642. if (is_string($token)) {
  643. $output .= $token;
  644. } elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
  645. $output .= $token[1];
  646. }
  647. }
  648. $output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
  649. return $output;
  650. }
  651. public function serialize()
  652. {
  653. return serialize(array($this->environment, $this->debug));
  654. }
  655. public function unserialize($data)
  656. {
  657. list($environment, $debug) = unserialize($data);
  658. $this->__construct($environment, $debug);
  659. }
  660. }
  661. }
  662. namespace Symfony\Component\ClassLoader
  663. {
  664. class ClassCollectionLoader
  665. {
  666. private static $loaded;
  667. public static function load($classes, $cacheDir, $name, $autoReload, $adaptive = false, $extension = '.php')
  668. {
  669. if (isset(self::$loaded[$name])) {
  670. return;
  671. }
  672. self::$loaded[$name] = true;
  673. if ($adaptive) {
  674. $classes = array_diff($classes, get_declared_classes(), get_declared_interfaces());
  675. $name = $name.'-'.substr(md5(implode('|', $classes)), 0, 5);
  676. }
  677. $cache = $cacheDir.'/'.$name.$extension;
  678. $reload = false;
  679. if ($autoReload) {
  680. $metadata = $cacheDir.'/'.$name.$extension.'.meta';
  681. if (!file_exists($metadata) || !file_exists($cache)) {
  682. $reload = true;
  683. } else {
  684. $time = filemtime($cache);
  685. $meta = unserialize(file_get_contents($metadata));
  686. if ($meta[1] != $classes) {
  687. $reload = true;
  688. } else {
  689. foreach ($meta[0] as $resource) {
  690. if (!file_exists($resource) || filemtime($resource) > $time) {
  691. $reload = true;
  692. break;
  693. }
  694. }
  695. }
  696. }
  697. }
  698. if (!$reload && file_exists($cache)) {
  699. require_once $cache;
  700. return;
  701. }
  702. $files = array();
  703. $content = '';
  704. foreach ($classes as $class) {
  705. if (!class_exists($class) && !interface_exists($class) && (!function_exists('trait_exists') || !trait_exists($class))) {
  706. throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
  707. }
  708. $r = new \ReflectionClass($class);
  709. $files[] = $r->getFileName();
  710. $c = preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', file_get_contents($r->getFileName()));
  711. if (!$r->inNamespace()) {
  712. $c = "\nnamespace\n{\n".self::stripComments($c)."\n}\n";
  713. } else {
  714. $c = self::fixNamespaceDeclarations('<?php '.$c);
  715. $c = preg_replace('/^\s*<\?php/', '', $c);
  716. }
  717. $content .= $c;
  718. }
  719. if (!is_dir(dirname($cache))) {
  720. mkdir(dirname($cache), 0777, true);
  721. }
  722. self::writeCacheFile($cache, '<?php '.$content);
  723. if ($autoReload) {
  724. self::writeCacheFile($metadata, serialize(array($files, $classes)));
  725. }
  726. }
  727. public static function fixNamespaceDeclarations($source)
  728. {
  729. if (!function_exists('token_get_all')) {
  730. return $source;
  731. }
  732. $output = '';
  733. $inNamespace = false;
  734. $tokens = token_get_all($source);
  735. for ($i = 0, $max = count($tokens); $i < $max; $i++) {
  736. $token = $tokens[$i];
  737. if (is_string($token)) {
  738. $output .= $token;
  739. } elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
  740. continue;
  741. } elseif (T_NAMESPACE === $token[0]) {
  742. if ($inNamespace) {
  743. $output .= "}\n";
  744. }
  745. $output .= $token[1];
  746. while (($t = $tokens[++$i]) && is_array($t) && in_array($t[0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
  747. $output .= $t[1];
  748. }
  749. if (is_string($t) && '{' === $t) {
  750. $inNamespace = false;
  751. --$i;
  752. } else {
  753. $output .= "\n{";
  754. $inNamespace = true;
  755. }
  756. } else {
  757. $output .= $token[1];
  758. }
  759. }
  760. if ($inNamespace) {
  761. $output .= "}\n";
  762. }
  763. return $output;
  764. }
  765. private static function writeCacheFile($file, $content)
  766. {
  767. $tmpFile = tempnam(dirname($file), basename($file));
  768. if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
  769. chmod($file, 0644);
  770. return;
  771. }
  772. throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
  773. }
  774. private static function stripComments($source)
  775. {
  776. if (!function_exists('token_get_all')) {
  777. return $source;
  778. }
  779. $output = '';
  780. foreach (token_get_all($source) as $token) {
  781. if (is_string($token)) {
  782. $output .= $token;
  783. } elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
  784. $output .= $token[1];
  785. }
  786. }
  787. $output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
  788. return $output;
  789. }
  790. }
  791. }
  792. namespace Symfony\Component\ClassLoader
  793. {
  794. class UniversalClassLoader
  795. {
  796. private $namespaces = array();
  797. private $prefixes = array();
  798. private $namespaceFallbacks = array();
  799. private $prefixFallbacks = array();
  800. public function getNamespaces()
  801. {
  802. return $this->namespaces;
  803. }
  804. public function getPrefixes()
  805. {
  806. return $this->prefixes;
  807. }
  808. public function getNamespaceFallbacks()
  809. {
  810. return $this->namespaceFallbacks;
  811. }
  812. public function getPrefixFallbacks()
  813. {
  814. return $this->prefixFallbacks;
  815. }
  816. public function registerNamespaceFallbacks(array $dirs)
  817. {
  818. $this->namespaceFallbacks = $dirs;
  819. }
  820. public function registerPrefixFallbacks(array $dirs)
  821. {
  822. $this->prefixFallbacks = $dirs;
  823. }
  824. public function registerNamespaces(array $namespaces)
  825. {
  826. foreach ($namespaces as $namespace => $locations) {
  827. $this->namespaces[$namespace] = (array) $locations;
  828. }
  829. }
  830. public function registerNamespace($namespace, $paths)
  831. {
  832. $this->namespaces[$namespace] = (array) $paths;
  833. }
  834. public function registerPrefixes(array $classes)
  835. {
  836. foreach ($classes as $prefix => $locations) {
  837. $this->prefixes[$prefix] = (array) $locations;
  838. }
  839. }
  840. public function registerPrefix($prefix, $paths)
  841. {
  842. $this->prefixes[$prefix] = (array) $paths;
  843. }
  844. public function register($prepend = false)
  845. {
  846. spl_autoload_register(array($this, 'loadClass'), true, $prepend);
  847. }
  848. public function loadClass($class)
  849. {
  850. if ($file = $this->findFile($class)) {
  851. require $file;
  852. }
  853. }
  854. public function findFile($class)
  855. {
  856. if ('\\' == $class[0]) {
  857. $class = substr($class, 1);
  858. }
  859. if (false !== $pos = strrpos($class, '\\')) {
  860. $namespace = substr($class, 0, $pos);
  861. foreach ($this->namespaces as $ns => $dirs) {
  862. if (0 !== strpos($namespace, $ns)) {
  863. continue;
  864. }
  865. foreach ($dirs as $dir) {
  866. $className = substr($class, $pos + 1);
  867. $file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
  868. if (file_exists($file)) {
  869. return $file;
  870. }
  871. }
  872. }
  873. foreach ($this->namespaceFallbacks as $dir) {
  874. $file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php';
  875. if (file_exists($file)) {
  876. return $file;
  877. }
  878. }
  879. } else {
  880. foreach ($this->prefixes as $prefix => $dirs) {
  881. if (0 !== strpos($class, $prefix)) {
  882. continue;
  883. }
  884. foreach ($dirs as $dir) {
  885. $file = $dir.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
  886. if (file_exists($file)) {
  887. return $file;
  888. }
  889. }
  890. }
  891. foreach ($this->prefixFallbacks as $dir) {
  892. $file = $dir.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
  893. if (file_exists($file)) {
  894. return $file;
  895. }
  896. }
  897. }
  898. }
  899. }
  900. }
  901. namespace Symfony\Component\HttpKernel\Bundle
  902. {
  903. use Symfony\Component\DependencyInjection\ContainerAware;
  904. use Symfony\Component\DependencyInjection\ContainerBuilder;
  905. use Symfony\Component\DependencyInjection\Container;
  906. use Symfony\Component\Console\Application;
  907. use Symfony\Component\Finder\Finder;
  908. abstract class Bundle extends ContainerAware implements BundleInterface
  909. {
  910. protected $name;
  911. protected $reflected;
  912. protected $extension;
  913. public function boot()
  914. {
  915. }
  916. public function shutdown()
  917. {
  918. }
  919. public function build(ContainerBuilder $container)
  920. {
  921. }
  922. public function getContainerExtension()
  923. {
  924. if (null === $this->extension) {
  925. $basename = preg_replace('/Bundle$/', '', $this->getName());
  926. $class = $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
  927. if (class_exists($class)) {
  928. $extension = new $class();
  929. $expectedAlias = Container::underscore($basename);
  930. if ($expectedAlias != $extension->getAlias()) {
  931. throw new \LogicException(sprintf(
  932. 'The extension alias for the default extension of a '.
  933. 'bundle must be the underscored version of the '.
  934. 'bundle name ("%s" instead of "%s")',
  935. $expectedAlias, $extension->getAlias()
  936. ));
  937. }
  938. $this->extension = $extension;
  939. } else {
  940. $this->extension = false;
  941. }
  942. }
  943. if ($this->extension) {
  944. return $this->extension;
  945. }
  946. }
  947. public function getNamespace()
  948. {
  949. if (null === $this->reflected) {
  950. $this->reflected = new \ReflectionObject($this);
  951. }
  952. return $this->reflected->getNamespaceName();
  953. }
  954. public function getPath()
  955. {
  956. if (null === $this->reflected) {
  957. $this->reflected = new \ReflectionObject($this);
  958. }
  959. return dirname($this->reflected->getFileName());
  960. }
  961. public function getParent()
  962. {
  963. return null;
  964. }
  965. final public function getName()
  966. {
  967. if (null !== $this->name) {
  968. return $this->name;
  969. }
  970. $name = get_class($this);
  971. $pos = strrpos($name, '\\');
  972. return $this->name = false === $pos ? $name : substr($name, $pos + 1);
  973. }
  974. public function registerCommands(Application $application)
  975. {
  976. if (!$dir = realpath($this->getPath().'/Command')) {
  977. return;
  978. }
  979. $finder = new Finder();
  980. $finder->files()->name('*Command.php')->in($dir);
  981. $prefix = $this->getNamespace().'\\Command';
  982. foreach ($finder as $file) {
  983. $ns = $prefix;
  984. if ($relativePath = $file->getRelativePath()) {
  985. $ns .= '\\'.strtr($relativePath, '/', '\\');
  986. }
  987. $r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
  988. if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
  989. $application->add($r->newInstance());
  990. }
  991. }
  992. }
  993. }
  994. }
  995. namespace Symfony\Component\HttpKernel\Bundle
  996. {
  997. use Symfony\Component\DependencyInjection\ContainerBuilder;
  998. interface BundleInterface
  999. {
  1000. public function boot();
  1001. public function shutdown();
  1002. public function build(ContainerBuilder $container);
  1003. public function getContainerExtension();
  1004. public function getParent();
  1005. public function getName();
  1006. public function getNamespace();
  1007. public function getPath();
  1008. }
  1009. }
  1010. namespace Symfony\Component\Config
  1011. {
  1012. class ConfigCache
  1013. {
  1014. private $debug;
  1015. private $file;
  1016. public function __construct($file, $debug)
  1017. {
  1018. $this->file = $file;
  1019. $this->debug = (Boolean) $debug;
  1020. }
  1021. public function __toString()
  1022. {
  1023. return $this->file;
  1024. }
  1025. public function isFresh()
  1026. {
  1027. if (!file_exists($this->file)) {
  1028. return false;
  1029. }
  1030. if (!$this->debug) {
  1031. return true;
  1032. }
  1033. $metadata = $this->file.'.meta';
  1034. if (!file_exists($metadata)) {
  1035. return false;
  1036. }
  1037. $time = filemtime($this->file);
  1038. $meta = unserialize(file_get_contents($metadata));
  1039. foreach ($meta as $resource) {
  1040. if (!$resource->isFresh($time)) {
  1041. return false;
  1042. }
  1043. }
  1044. return true;
  1045. }
  1046. public function write($content, array $metadata = null)
  1047. {
  1048. $dir = dirname($this->file);
  1049. if (!is_dir($dir)) {
  1050. if (false === @mkdir($dir, 0777, true)) {
  1051. throw new \RuntimeException(sprintf('Unable to create the %s directory', $dir));
  1052. }
  1053. } elseif (!is_writable($dir)) {
  1054. throw new \RuntimeException(sprintf('Unable to write in the %s directory', $dir));
  1055. }
  1056. $tmpFile = tempnam(dirname($this->file), basename($this->file));
  1057. if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $this->file)) {
  1058. chmod($this->file, 0666);
  1059. } else {
  1060. throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $this->file));
  1061. }
  1062. if (null !== $metadata && true === $this->debug) {
  1063. $file = $this->file.'.meta';
  1064. $tmpFile = tempnam(dirname($file), basename($file));
  1065. if (false !== @file_put_contents($tmpFile, serialize($metadata)) && @rename($tmpFile, $file)) {
  1066. chmod($file, 0666);
  1067. }
  1068. }
  1069. }
  1070. }
  1071. }