bootstrap.php.cache 48KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736
  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('You cannot set services of scope "prototype".');
  99. }
  100. $id = strtolower($id);
  101. if (self::SCOPE_CONTAINER !== $scope) {
  102. if (!isset($this->scopedServices[$scope])) {
  103. throw new RuntimeException('You cannot set services of inactive scopes.');
  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.1.8-DEV';
  328. const VERSION_ID = '20108';
  329. const MAJOR_VERSION = '2';
  330. const MINOR_VERSION = '1';
  331. const RELEASE_VERSION = '8';
  332. const EXTRA_VERSION = 'DEV';
  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. if ($this->debug) {
  342. $this->startTime = microtime(true);
  343. }
  344. $this->init();
  345. }
  346. public function init()
  347. {
  348. if ($this->debug) {
  349. ini_set('display_errors', 1);
  350. error_reporting(-1);
  351. DebugClassLoader::enable();
  352. ErrorHandler::register($this->errorReportingLevel);
  353. if ('cli' !== php_sapi_name()) {
  354. ExceptionHandler::register();
  355. }
  356. } else {
  357. ini_set('display_errors', 0);
  358. }
  359. }
  360. public function __clone()
  361. {
  362. if ($this->debug) {
  363. $this->startTime = microtime(true);
  364. }
  365. $this->booted = false;
  366. $this->container = null;
  367. }
  368. public function boot()
  369. {
  370. if (true === $this->booted) {
  371. return;
  372. }
  373. $this->initializeBundles();
  374. $this->initializeContainer();
  375. foreach ($this->getBundles() as $bundle) {
  376. $bundle->setContainer($this->container);
  377. $bundle->boot();
  378. }
  379. $this->booted = true;
  380. }
  381. public function terminate(Request $request, Response $response)
  382. {
  383. if (false === $this->booted) {
  384. return;
  385. }
  386. if ($this->getHttpKernel() instanceof TerminableInterface) {
  387. $this->getHttpKernel()->terminate($request, $response);
  388. }
  389. }
  390. public function shutdown()
  391. {
  392. if (false === $this->booted) {
  393. return;
  394. }
  395. $this->booted = false;
  396. foreach ($this->getBundles() as $bundle) {
  397. $bundle->shutdown();
  398. $bundle->setContainer(null);
  399. }
  400. $this->container = null;
  401. }
  402. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  403. {
  404. if (false === $this->booted) {
  405. $this->boot();
  406. }
  407. return $this->getHttpKernel()->handle($request, $type, $catch);
  408. }
  409. protected function getHttpKernel()
  410. {
  411. return $this->container->get('http_kernel');
  412. }
  413. public function getBundles()
  414. {
  415. return $this->bundles;
  416. }
  417. public function isClassInActiveBundle($class)
  418. {
  419. foreach ($this->getBundles() as $bundle) {
  420. if (0 === strpos($class, $bundle->getNamespace())) {
  421. return true;
  422. }
  423. }
  424. return false;
  425. }
  426. public function getBundle($name, $first = true)
  427. {
  428. if (!isset($this->bundleMap[$name])) {
  429. 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)));
  430. }
  431. if (true === $first) {
  432. return $this->bundleMap[$name][0];
  433. }
  434. return $this->bundleMap[$name];
  435. }
  436. public function locateResource($name, $dir = null, $first = true)
  437. {
  438. if ('@' !== $name[0]) {
  439. throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
  440. }
  441. if (false !== strpos($name, '..')) {
  442. throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
  443. }
  444. $bundleName = substr($name, 1);
  445. $path = '';
  446. if (false !== strpos($bundleName, '/')) {
  447. list($bundleName, $path) = explode('/', $bundleName, 2);
  448. }
  449. $isResource = 0 === strpos($path, 'Resources') && null !== $dir;
  450. $overridePath = substr($path, 9);
  451. $resourceBundle = null;
  452. $bundles = $this->getBundle($bundleName, false);
  453. $files = array();
  454. foreach ($bundles as $bundle) {
  455. if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
  456. if (null !== $resourceBundle) {
  457. 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.',
  458. $file,
  459. $resourceBundle,
  460. $dir.'/'.$bundles[0]->getName().$overridePath
  461. ));
  462. }
  463. if ($first) {
  464. return $file;
  465. }
  466. $files[] = $file;
  467. }
  468. if (file_exists($file = $bundle->getPath().'/'.$path)) {
  469. if ($first && !$isResource) {
  470. return $file;
  471. }
  472. $files[] = $file;
  473. $resourceBundle = $bundle->getName();
  474. }
  475. }
  476. if (count($files) > 0) {
  477. return $first && $isResource ? $files[0] : $files;
  478. }
  479. throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
  480. }
  481. public function getName()
  482. {
  483. if (null === $this->name) {
  484. $this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
  485. }
  486. return $this->name;
  487. }
  488. public function getEnvironment()
  489. {
  490. return $this->environment;
  491. }
  492. public function isDebug()
  493. {
  494. return $this->debug;
  495. }
  496. public function getRootDir()
  497. {
  498. if (null === $this->rootDir) {
  499. $r = new \ReflectionObject($this);
  500. $this->rootDir = str_replace('\\', '/', dirname($r->getFileName()));
  501. }
  502. return $this->rootDir;
  503. }
  504. public function getContainer()
  505. {
  506. return $this->container;
  507. }
  508. public function loadClassCache($name = 'classes', $extension = '.php')
  509. {
  510. if (!$this->booted && is_file($this->getCacheDir().'/classes.map')) {
  511. ClassCollectionLoader::load(include($this->getCacheDir().'/classes.map'), $this->getCacheDir(), $name, $this->debug, false, $extension);
  512. }
  513. }
  514. public function setClassCache(array $classes)
  515. {
  516. file_put_contents($this->getCacheDir().'/classes.map', sprintf('<?php return %s;', var_export($classes, true)));
  517. }
  518. public function getStartTime()
  519. {
  520. return $this->debug ? $this->startTime : -INF;
  521. }
  522. public function getCacheDir()
  523. {
  524. return $this->rootDir.'/cache/'.$this->environment;
  525. }
  526. public function getLogDir()
  527. {
  528. return $this->rootDir.'/logs';
  529. }
  530. public function getCharset()
  531. {
  532. return 'UTF-8';
  533. }
  534. protected function initializeBundles()
  535. {
  536. $this->bundles = array();
  537. $topMostBundles = array();
  538. $directChildren = array();
  539. foreach ($this->registerBundles() as $bundle) {
  540. $name = $bundle->getName();
  541. if (isset($this->bundles[$name])) {
  542. throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name));
  543. }
  544. $this->bundles[$name] = $bundle;
  545. if ($parentName = $bundle->getParent()) {
  546. if (isset($directChildren[$parentName])) {
  547. throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
  548. }
  549. if ($parentName == $name) {
  550. throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name));
  551. }
  552. $directChildren[$parentName] = $name;
  553. } else {
  554. $topMostBundles[$name] = $bundle;
  555. }
  556. }
  557. if (count($diff = array_values(array_diff(array_keys($directChildren), array_keys($this->bundles))))) {
  558. throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0]));
  559. }
  560. $this->bundleMap = array();
  561. foreach ($topMostBundles as $name => $bundle) {
  562. $bundleMap = array($bundle);
  563. $hierarchy = array($name);
  564. while (isset($directChildren[$name])) {
  565. $name = $directChildren[$name];
  566. array_unshift($bundleMap, $this->bundles[$name]);
  567. $hierarchy[] = $name;
  568. }
  569. foreach ($hierarchy as $bundle) {
  570. $this->bundleMap[$bundle] = $bundleMap;
  571. array_pop($bundleMap);
  572. }
  573. }
  574. }
  575. protected function getContainerClass()
  576. {
  577. return $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
  578. }
  579. protected function getContainerBaseClass()
  580. {
  581. return 'Container';
  582. }
  583. protected function initializeContainer()
  584. {
  585. $class = $this->getContainerClass();
  586. $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
  587. $fresh = true;
  588. if (!$cache->isFresh()) {
  589. $container = $this->buildContainer();
  590. $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
  591. $fresh = false;
  592. }
  593. require_once $cache;
  594. $this->container = new $class();
  595. $this->container->set('kernel', $this);
  596. if (!$fresh && $this->container->has('cache_warmer')) {
  597. $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
  598. }
  599. }
  600. protected function getKernelParameters()
  601. {
  602. $bundles = array();
  603. foreach ($this->bundles as $name => $bundle) {
  604. $bundles[$name] = get_class($bundle);
  605. }
  606. return array_merge(
  607. array(
  608. 'kernel.root_dir' => $this->rootDir,
  609. 'kernel.environment' => $this->environment,
  610. 'kernel.debug' => $this->debug,
  611. 'kernel.name' => $this->name,
  612. 'kernel.cache_dir' => $this->getCacheDir(),
  613. 'kernel.logs_dir' => $this->getLogDir(),
  614. 'kernel.bundles' => $bundles,
  615. 'kernel.charset' => $this->getCharset(),
  616. 'kernel.container_class' => $this->getContainerClass(),
  617. ),
  618. $this->getEnvParameters()
  619. );
  620. }
  621. protected function getEnvParameters()
  622. {
  623. $parameters = array();
  624. foreach ($_SERVER as $key => $value) {
  625. if (0 === strpos($key, 'SYMFONY__')) {
  626. $parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value;
  627. }
  628. }
  629. return $parameters;
  630. }
  631. protected function buildContainer()
  632. {
  633. foreach (array('cache' => $this->getCacheDir(), 'logs' => $this->getLogDir()) as $name => $dir) {
  634. if (!is_dir($dir)) {
  635. if (false === @mkdir($dir, 0777, true)) {
  636. throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n", $name, $dir));
  637. }
  638. } elseif (!is_writable($dir)) {
  639. throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", $name, $dir));
  640. }
  641. }
  642. $container = $this->getContainerBuilder();
  643. $extensions = array();
  644. foreach ($this->bundles as $bundle) {
  645. if ($extension = $bundle->getContainerExtension()) {
  646. $container->registerExtension($extension);
  647. $extensions[] = $extension->getAlias();
  648. }
  649. if ($this->debug) {
  650. $container->addObjectResource($bundle);
  651. }
  652. }
  653. foreach ($this->bundles as $bundle) {
  654. $bundle->build($container);
  655. }
  656. $container->addObjectResource($this);
  657. $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
  658. if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
  659. $container->merge($cont);
  660. }
  661. $container->addCompilerPass(new AddClassesToCachePass($this));
  662. $container->compile();
  663. return $container;
  664. }
  665. protected function getContainerBuilder()
  666. {
  667. return new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
  668. }
  669. protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
  670. {
  671. $dumper = new PhpDumper($container);
  672. $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass));
  673. if (!$this->debug) {
  674. $content = self::stripComments($content);
  675. }
  676. $cache->write($content, $container->getResources());
  677. }
  678. protected function getContainerLoader(ContainerInterface $container)
  679. {
  680. $locator = new FileLocator($this);
  681. $resolver = new LoaderResolver(array(
  682. new XmlFileLoader($container, $locator),
  683. new YamlFileLoader($container, $locator),
  684. new IniFileLoader($container, $locator),
  685. new PhpFileLoader($container, $locator),
  686. new ClosureLoader($container),
  687. ));
  688. return new DelegatingLoader($resolver);
  689. }
  690. public static function stripComments($source)
  691. {
  692. if (!function_exists('token_get_all')) {
  693. return $source;
  694. }
  695. $output = '';
  696. foreach (token_get_all($source) as $token) {
  697. if (is_string($token)) {
  698. $output .= $token;
  699. } elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
  700. $output .= $token[1];
  701. }
  702. }
  703. $output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
  704. return $output;
  705. }
  706. public function serialize()
  707. {
  708. return serialize(array($this->environment, $this->debug));
  709. }
  710. public function unserialize($data)
  711. {
  712. list($environment, $debug) = unserialize($data);
  713. $this->__construct($environment, $debug);
  714. }
  715. }
  716. }
  717. namespace Symfony\Component\ClassLoader
  718. {
  719. class ApcClassLoader
  720. {
  721. private $prefix;
  722. private $classFinder;
  723. public function __construct($prefix, $classFinder)
  724. {
  725. if (!extension_loaded('apc')) {
  726. throw new \RuntimeException('Unable to use ApcClassLoader as APC is not enabled.');
  727. }
  728. if (!method_exists($classFinder, 'findFile')) {
  729. throw new \InvalidArgumentException('The class finder must implement a "findFile" method.');
  730. }
  731. $this->prefix = $prefix;
  732. $this->classFinder = $classFinder;
  733. }
  734. public function register($prepend = false)
  735. {
  736. spl_autoload_register(array($this, 'loadClass'), true, $prepend);
  737. }
  738. public function unregister()
  739. {
  740. spl_autoload_unregister(array($this, 'loadClass'));
  741. }
  742. public function loadClass($class)
  743. {
  744. if ($file = $this->findFile($class)) {
  745. require $file;
  746. return true;
  747. }
  748. }
  749. public function findFile($class)
  750. {
  751. if (false === $file = apc_fetch($this->prefix.$class)) {
  752. apc_store($this->prefix.$class, $file = $this->classFinder->findFile($class));
  753. }
  754. return $file;
  755. }
  756. }
  757. }
  758. namespace Symfony\Component\HttpKernel\Bundle
  759. {
  760. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  761. use Symfony\Component\DependencyInjection\ContainerBuilder;
  762. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  763. interface BundleInterface extends ContainerAwareInterface
  764. {
  765. public function boot();
  766. public function shutdown();
  767. public function build(ContainerBuilder $container);
  768. public function getContainerExtension();
  769. public function getParent();
  770. public function getName();
  771. public function getNamespace();
  772. public function getPath();
  773. }
  774. }
  775. namespace Symfony\Component\DependencyInjection
  776. {
  777. abstract class ContainerAware implements ContainerAwareInterface
  778. {
  779. protected $container;
  780. public function setContainer(ContainerInterface $container = null)
  781. {
  782. $this->container = $container;
  783. }
  784. }
  785. }
  786. namespace Symfony\Component\HttpKernel\Bundle
  787. {
  788. use Symfony\Component\DependencyInjection\ContainerAware;
  789. use Symfony\Component\DependencyInjection\ContainerBuilder;
  790. use Symfony\Component\DependencyInjection\Container;
  791. use Symfony\Component\Console\Application;
  792. use Symfony\Component\Finder\Finder;
  793. abstract class Bundle extends ContainerAware implements BundleInterface
  794. {
  795. protected $name;
  796. protected $reflected;
  797. protected $extension;
  798. public function boot()
  799. {
  800. }
  801. public function shutdown()
  802. {
  803. }
  804. public function build(ContainerBuilder $container)
  805. {
  806. }
  807. public function getContainerExtension()
  808. {
  809. if (null === $this->extension) {
  810. $basename = preg_replace('/Bundle$/', '', $this->getName());
  811. $class = $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
  812. if (class_exists($class)) {
  813. $extension = new $class();
  814. $expectedAlias = Container::underscore($basename);
  815. if ($expectedAlias != $extension->getAlias()) {
  816. throw new \LogicException(sprintf(
  817. 'The extension alias for the default extension of a '.
  818. 'bundle must be the underscored version of the '.
  819. 'bundle name ("%s" instead of "%s")',
  820. $expectedAlias, $extension->getAlias()
  821. ));
  822. }
  823. $this->extension = $extension;
  824. } else {
  825. $this->extension = false;
  826. }
  827. }
  828. if ($this->extension) {
  829. return $this->extension;
  830. }
  831. }
  832. public function getNamespace()
  833. {
  834. if (null === $this->reflected) {
  835. $this->reflected = new \ReflectionObject($this);
  836. }
  837. return $this->reflected->getNamespaceName();
  838. }
  839. public function getPath()
  840. {
  841. if (null === $this->reflected) {
  842. $this->reflected = new \ReflectionObject($this);
  843. }
  844. return dirname($this->reflected->getFileName());
  845. }
  846. public function getParent()
  847. {
  848. return null;
  849. }
  850. final public function getName()
  851. {
  852. if (null !== $this->name) {
  853. return $this->name;
  854. }
  855. $name = get_class($this);
  856. $pos = strrpos($name, '\\');
  857. return $this->name = false === $pos ? $name : substr($name, $pos + 1);
  858. }
  859. public function registerCommands(Application $application)
  860. {
  861. if (!is_dir($dir = $this->getPath().'/Command')) {
  862. return;
  863. }
  864. $finder = new Finder();
  865. $finder->files()->name('*Command.php')->in($dir);
  866. $prefix = $this->getNamespace().'\\Command';
  867. foreach ($finder as $file) {
  868. $ns = $prefix;
  869. if ($relativePath = $file->getRelativePath()) {
  870. $ns .= '\\'.strtr($relativePath, '/', '\\');
  871. }
  872. $r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
  873. if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
  874. $application->add($r->newInstance());
  875. }
  876. }
  877. }
  878. }
  879. }
  880. namespace Symfony\Component\Config
  881. {
  882. class ConfigCache
  883. {
  884. private $debug;
  885. private $file;
  886. public function __construct($file, $debug)
  887. {
  888. $this->file = $file;
  889. $this->debug = (Boolean) $debug;
  890. }
  891. public function __toString()
  892. {
  893. return $this->file;
  894. }
  895. public function isFresh()
  896. {
  897. if (!is_file($this->file)) {
  898. return false;
  899. }
  900. if (!$this->debug) {
  901. return true;
  902. }
  903. $metadata = $this->file.'.meta';
  904. if (!is_file($metadata)) {
  905. return false;
  906. }
  907. $time = filemtime($this->file);
  908. $meta = unserialize(file_get_contents($metadata));
  909. foreach ($meta as $resource) {
  910. if (!$resource->isFresh($time)) {
  911. return false;
  912. }
  913. }
  914. return true;
  915. }
  916. public function write($content, array $metadata = null)
  917. {
  918. $dir = dirname($this->file);
  919. if (!is_dir($dir)) {
  920. if (false === @mkdir($dir, 0777, true)) {
  921. throw new \RuntimeException(sprintf('Unable to create the %s directory', $dir));
  922. }
  923. } elseif (!is_writable($dir)) {
  924. throw new \RuntimeException(sprintf('Unable to write in the %s directory', $dir));
  925. }
  926. $tmpFile = tempnam(dirname($this->file), basename($this->file));
  927. if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $this->file)) {
  928. @chmod($this->file, 0666 & ~umask());
  929. } else {
  930. throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $this->file));
  931. }
  932. if (null !== $metadata && true === $this->debug) {
  933. $file = $this->file.'.meta';
  934. $tmpFile = tempnam(dirname($file), basename($file));
  935. if (false !== @file_put_contents($tmpFile, serialize($metadata)) && @rename($tmpFile, $file)) {
  936. @chmod($file, 0666 & ~umask());
  937. }
  938. }
  939. }
  940. }
  941. }
  942. namespace Symfony\Component\HttpKernel
  943. {
  944. use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
  945. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  946. use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
  947. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  948. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  949. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  950. use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
  951. use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
  952. use Symfony\Component\HttpKernel\Event\PostResponseEvent;
  953. use Symfony\Component\HttpFoundation\Request;
  954. use Symfony\Component\HttpFoundation\Response;
  955. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  956. class HttpKernel implements HttpKernelInterface, TerminableInterface
  957. {
  958. protected $dispatcher;
  959. protected $resolver;
  960. public function __construct(EventDispatcherInterface $dispatcher, ControllerResolverInterface $resolver)
  961. {
  962. $this->dispatcher = $dispatcher;
  963. $this->resolver = $resolver;
  964. }
  965. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  966. {
  967. try {
  968. return $this->handleRaw($request, $type);
  969. } catch (\Exception $e) {
  970. if (false === $catch) {
  971. throw $e;
  972. }
  973. return $this->handleException($e, $request, $type);
  974. }
  975. }
  976. public function terminate(Request $request, Response $response)
  977. {
  978. $this->dispatcher->dispatch(KernelEvents::TERMINATE, new PostResponseEvent($this, $request, $response));
  979. }
  980. private function handleRaw(Request $request, $type = self::MASTER_REQUEST)
  981. {
  982. $event = new GetResponseEvent($this, $request, $type);
  983. $this->dispatcher->dispatch(KernelEvents::REQUEST, $event);
  984. if ($event->hasResponse()) {
  985. return $this->filterResponse($event->getResponse(), $request, $type);
  986. }
  987. if (false === $controller = $this->resolver->getController($request)) {
  988. 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()));
  989. }
  990. $event = new FilterControllerEvent($this, $controller, $request, $type);
  991. $this->dispatcher->dispatch(KernelEvents::CONTROLLER, $event);
  992. $controller = $event->getController();
  993. $arguments = $this->resolver->getArguments($request, $controller);
  994. $response = call_user_func_array($controller, $arguments);
  995. if (!$response instanceof Response) {
  996. $event = new GetResponseForControllerResultEvent($this, $request, $type, $response);
  997. $this->dispatcher->dispatch(KernelEvents::VIEW, $event);
  998. if ($event->hasResponse()) {
  999. $response = $event->getResponse();
  1000. }
  1001. if (!$response instanceof Response) {
  1002. $msg = sprintf('The controller must return a response (%s given).', $this->varToString($response));
  1003. if (null === $response) {
  1004. $msg .= ' Did you forget to add a return statement somewhere in your controller?';
  1005. }
  1006. throw new \LogicException($msg);
  1007. }
  1008. }
  1009. return $this->filterResponse($response, $request, $type);
  1010. }
  1011. private function filterResponse(Response $response, Request $request, $type)
  1012. {
  1013. $event = new FilterResponseEvent($this, $request, $type, $response);
  1014. $this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
  1015. return $event->getResponse();
  1016. }
  1017. private function handleException(\Exception $e, $request, $type)
  1018. {
  1019. $event = new GetResponseForExceptionEvent($this, $request, $type, $e);
  1020. $this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
  1021. $e = $event->getException();
  1022. if (!$event->hasResponse()) {
  1023. throw $e;
  1024. }
  1025. $response = $event->getResponse();
  1026. if ($response->headers->has('X-Status-Code')) {
  1027. $response->setStatusCode($response->headers->get('X-Status-Code'));
  1028. $response->headers->remove('X-Status-Code');
  1029. } elseif (!$response->isClientError() && !$response->isServerError() && !$response->isRedirect()) {
  1030. if ($e instanceof HttpExceptionInterface) {
  1031. $response->setStatusCode($e->getStatusCode());
  1032. $response->headers->add($e->getHeaders());
  1033. } else {
  1034. $response->setStatusCode(500);
  1035. }
  1036. }
  1037. try {
  1038. return $this->filterResponse($response, $request, $type);
  1039. } catch (\Exception $e) {
  1040. return $response;
  1041. }
  1042. }
  1043. private function varToString($var)
  1044. {
  1045. if (is_object($var)) {
  1046. return sprintf('Object(%s)', get_class($var));
  1047. }
  1048. if (is_array($var)) {
  1049. $a = array();
  1050. foreach ($var as $k => $v) {
  1051. $a[] = sprintf('%s => %s', $k, $this->varToString($v));
  1052. }
  1053. return sprintf("Array(%s)", implode(', ', $a));
  1054. }
  1055. if (is_resource($var)) {
  1056. return sprintf('Resource(%s)', get_resource_type($var));
  1057. }
  1058. if (null === $var) {
  1059. return 'null';
  1060. }
  1061. if (false === $var) {
  1062. return 'false';
  1063. }
  1064. if (true === $var) {
  1065. return 'true';
  1066. }
  1067. return (string) $var;
  1068. }
  1069. }
  1070. }
  1071. namespace Symfony\Bundle\FrameworkBundle
  1072. {
  1073. use Symfony\Component\HttpFoundation\Request;
  1074. use Symfony\Component\HttpFoundation\Response;
  1075. use Symfony\Component\HttpFoundation\StreamedResponse;
  1076. use Symfony\Component\HttpKernel\HttpKernelInterface;
  1077. use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
  1078. use Symfony\Component\DependencyInjection\ContainerInterface;
  1079. use Symfony\Component\HttpKernel\HttpKernel as BaseHttpKernel;
  1080. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  1081. class HttpKernel extends BaseHttpKernel
  1082. {
  1083. protected $container;
  1084. private $esiSupport;
  1085. public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver)
  1086. {
  1087. parent::__construct($dispatcher, $controllerResolver);
  1088. $this->container = $container;
  1089. }
  1090. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  1091. {
  1092. $request->headers->set('X-Php-Ob-Level', ob_get_level());
  1093. $this->container->enterScope('request');
  1094. $this->container->set('request', $request, 'request');
  1095. try {
  1096. $response = parent::handle($request, $type, $catch);
  1097. } catch (\Exception $e) {
  1098. $this->container->leaveScope('request');
  1099. throw $e;
  1100. }
  1101. $this->container->leaveScope('request');
  1102. return $response;
  1103. }
  1104. public function forward($controller, array $attributes = array(), array $query = array())
  1105. {
  1106. $attributes['_controller'] = $controller;
  1107. $subRequest = $this->container->get('request')->duplicate($query, null, $attributes);
  1108. return $this->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
  1109. }
  1110. public function render($controller, array $options = array())
  1111. {
  1112. $options = array_merge(array(
  1113. 'attributes' => array(),
  1114. 'query' => array(),
  1115. 'ignore_errors' => !$this->container->getParameter('kernel.debug'),
  1116. 'alt' => array(),
  1117. 'standalone' => false,
  1118. 'comment' => '',
  1119. ), $options);
  1120. if (!is_array($options['alt'])) {
  1121. $options['alt'] = array($options['alt']);
  1122. }
  1123. if (null === $this->esiSupport) {
  1124. $this->esiSupport = $this->container->has('esi') && $this->container->get('esi')->hasSurrogateEsiCapability($this->container->get('request'));
  1125. }
  1126. if ($this->esiSupport && (true === $options['standalone'] || 'esi' === $options['standalone'])) {
  1127. if (0 === strpos($controller, 'http://') || 0 === strpos($controller, 'https://')) {
  1128. $uri = $controller;
  1129. } else {
  1130. $uri = $this->generateInternalUri($controller, $options['attributes'], $options['query']);
  1131. }
  1132. $alt = '';
  1133. if ($options['alt']) {
  1134. if (is_string($options['alt']) && (0 === strpos($options['alt'], 'http://') || 0 === strpos($options['alt'], 'https://'))) {
  1135. $alt = $options['alt'];
  1136. } else {
  1137. $alt = $this->generateInternalUri($options['alt'][0], isset($options['alt'][1]) ? $options['alt'][1] : array(), isset($options['alt'][2]) ? $options['alt'][2] : array());
  1138. }
  1139. }
  1140. return $this->container->get('esi')->renderIncludeTag($uri, $alt, $options['ignore_errors'], $options['comment']);
  1141. }
  1142. if ('js' === $options['standalone']) {
  1143. if (0 === strpos($controller, 'http://') || 0 === strpos($controller, 'https://')) {
  1144. $uri = $controller;
  1145. } else {
  1146. $uri = $this->generateInternalUri($controller, $options['attributes'], $options['query'], false);
  1147. }
  1148. $defaultContent = null;
  1149. if ($template = $this->container->getParameter('templating.hinclude.default_template')) {
  1150. $defaultContent = $this->container->get('templating')->render($template);
  1151. }
  1152. return $this->renderHIncludeTag($uri, $defaultContent);
  1153. }
  1154. $request = $this->container->get('request');
  1155. if (0 === strpos($controller, 'http://') || 0 === strpos($controller, 'https://')) {
  1156. $subRequest = Request::create($controller, 'get', array(), $request->cookies->all(), array(), $request->server->all());
  1157. if ($session = $request->getSession()) {
  1158. $subRequest->setSession($session);
  1159. }
  1160. } elseif (0 === strpos($controller, '/')) {
  1161. $subRequest = Request::create($request->getUriForPath($controller), 'get', array(), $request->cookies->all(), array(), $request->server->all());
  1162. if ($session = $request->getSession()) {
  1163. $subRequest->setSession($session);
  1164. }
  1165. } else {
  1166. $options['attributes']['_controller'] = $controller;
  1167. if (!isset($options['attributes']['_format'])) {
  1168. $options['attributes']['_format'] = $request->getRequestFormat();
  1169. }
  1170. $options['attributes']['_route'] = '_internal';
  1171. $subRequest = $request->duplicate($options['query'], null, $options['attributes']);
  1172. $subRequest->setMethod('GET');
  1173. }
  1174. $level = ob_get_level();
  1175. try {
  1176. $response = $this->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
  1177. if (!$response->isSuccessful()) {
  1178. throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $request->getUri(), $response->getStatusCode()));
  1179. }
  1180. if (!$response instanceof StreamedResponse) {
  1181. return $response->getContent();
  1182. }
  1183. $response->sendContent();
  1184. } catch (\Exception $e) {
  1185. if ($options['alt']) {
  1186. $alt = $options['alt'];
  1187. unset($options['alt']);
  1188. $options['attributes'] = isset($alt[1]) ? $alt[1] : array();
  1189. $options['query'] = isset($alt[2]) ? $alt[2] : array();
  1190. return $this->render($alt[0], $options);
  1191. }
  1192. if (!$options['ignore_errors']) {
  1193. throw $e;
  1194. }
  1195. while (ob_get_level() > $level) {
  1196. ob_get_clean();
  1197. }
  1198. }
  1199. }
  1200. public function generateInternalUri($controller, array $attributes = array(), array $query = array(), $secure = true)
  1201. {
  1202. if (0 === strpos($controller, '/')) {
  1203. return $controller;
  1204. }
  1205. $path = http_build_query($attributes, '', '&');
  1206. $uri = $this->container->get('router')->generate($secure ? '_internal' : '_internal_public', array(
  1207. 'controller' => $controller,
  1208. 'path' => $path ?: 'none',
  1209. '_format' => $this->container->get('request')->getRequestFormat(),
  1210. ));
  1211. if ($queryString = http_build_query($query, '', '&')) {
  1212. $uri .= '?'.$queryString;
  1213. }
  1214. return $uri;
  1215. }
  1216. public function renderHIncludeTag($uri, $defaultContent = null)
  1217. {
  1218. return sprintf('<hx:include src="%s">%s</hx:include>', $uri, $defaultContent);
  1219. }
  1220. public function hasEsiSupport()
  1221. {
  1222. return $this->esiSupport;
  1223. }
  1224. }
  1225. }
  1226. namespace { return $loader; }