bootstrap.php.cache 48KB

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