bootstrap.php.cache 35KB

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