PageRenderTime 61ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/app/bootstrap.php.cache

https://github.com/thaberkern/TaskBoxx
Unknown | 2206 lines | 2203 code | 3 blank | 0 comment | 0 complexity | aa406fd333d824c5f70d7af6f0338b65 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, MIT, BSD-3-Clause, Apache-2.0
  1. <?php
  2. namespace { require_once __DIR__.'/autoload.php'; }
  3. namespace Symfony\Component\DependencyInjection
  4. {
  5. interface ContainerInterface
  6. {
  7. const EXCEPTION_ON_INVALID_REFERENCE = 1;
  8. const NULL_ON_INVALID_REFERENCE = 2;
  9. const IGNORE_ON_INVALID_REFERENCE = 3;
  10. const SCOPE_CONTAINER = 'container';
  11. const SCOPE_PROTOTYPE = 'prototype';
  12. function set($id, $service, $scope = self::SCOPE_CONTAINER);
  13. function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
  14. function has($id);
  15. function getParameter($name);
  16. function hasParameter($name);
  17. function setParameter($name, $value);
  18. function enterScope($name);
  19. function leaveScope($name);
  20. function addScope(ScopeInterface $scope);
  21. function hasScope($name);
  22. function isScopeActive($name);
  23. }
  24. }
  25. namespace Symfony\Component\DependencyInjection
  26. {
  27. use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
  28. use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
  29. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  30. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  31. use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
  32. class Container implements ContainerInterface
  33. {
  34. protected $parameterBag;
  35. protected $services;
  36. protected $scopes;
  37. protected $scopeChildren;
  38. protected $scopedServices;
  39. protected $scopeStacks;
  40. protected $loading = array();
  41. public function __construct(ParameterBagInterface $parameterBag = null)
  42. {
  43. $this->parameterBag = null === $parameterBag ? new ParameterBag() : $parameterBag;
  44. $this->services = array();
  45. $this->scopes = array();
  46. $this->scopeChildren = array();
  47. $this->scopedServices = array();
  48. $this->scopeStacks = array();
  49. $this->set('service_container', $this);
  50. }
  51. public function compile()
  52. {
  53. $this->parameterBag->resolve();
  54. $this->parameterBag = new FrozenParameterBag($this->parameterBag->all());
  55. }
  56. public function isFrozen()
  57. {
  58. return $this->parameterBag instanceof FrozenParameterBag;
  59. }
  60. public function getParameterBag()
  61. {
  62. return $this->parameterBag;
  63. }
  64. public function getParameter($name)
  65. {
  66. return $this->parameterBag->get($name);
  67. }
  68. public function hasParameter($name)
  69. {
  70. return $this->parameterBag->has($name);
  71. }
  72. public function setParameter($name, $value)
  73. {
  74. $this->parameterBag->set($name, $value);
  75. }
  76. public function set($id, $service, $scope = self::SCOPE_CONTAINER)
  77. {
  78. if (self::SCOPE_PROTOTYPE === $scope) {
  79. throw new \InvalidArgumentException('You cannot set services of scope "prototype".');
  80. }
  81. $id = strtolower($id);
  82. if (self::SCOPE_CONTAINER !== $scope) {
  83. if (!isset($this->scopedServices[$scope])) {
  84. throw new \RuntimeException('You cannot set services of inactive scopes.');
  85. }
  86. $this->scopedServices[$scope][$id] = $service;
  87. }
  88. $this->services[$id] = $service;
  89. }
  90. public function has($id)
  91. {
  92. $id = strtolower($id);
  93. return isset($this->services[$id]) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service');
  94. }
  95. public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
  96. {
  97. $id = strtolower($id);
  98. if (isset($this->services[$id])) {
  99. return $this->services[$id];
  100. }
  101. if (isset($this->loading[$id])) {
  102. throw new ServiceCircularReferenceException($id, array_keys($this->loading));
  103. }
  104. if (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')) {
  105. $this->loading[$id] = true;
  106. try {
  107. $service = $this->$method();
  108. } catch (\Exception $e) {
  109. unset($this->loading[$id]);
  110. throw $e;
  111. }
  112. unset($this->loading[$id]);
  113. return $service;
  114. }
  115. if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
  116. throw new ServiceNotFoundException($id);
  117. }
  118. }
  119. public function getServiceIds()
  120. {
  121. $ids = array();
  122. $r = new \ReflectionClass($this);
  123. foreach ($r->getMethods() as $method) {
  124. if (preg_match('/^get(.+)Service$/', $method->getName(), $match)) {
  125. $ids[] = self::underscore($match[1]);
  126. }
  127. }
  128. return array_unique(array_merge($ids, array_keys($this->services)));
  129. }
  130. public function enterScope($name)
  131. {
  132. if (!isset($this->scopes[$name])) {
  133. throw new \InvalidArgumentException(sprintf('The scope "%s" does not exist.', $name));
  134. }
  135. if (self::SCOPE_CONTAINER !== $this->scopes[$name] && !isset($this->scopedServices[$this->scopes[$name]])) {
  136. throw new \RuntimeException(sprintf('The parent scope "%s" must be active when entering this scope.', $this->scopes[$name]));
  137. }
  138. if (isset($this->scopedServices[$name])) {
  139. $services = array($this->services, $name => $this->scopedServices[$name]);
  140. unset($this->scopedServices[$name]);
  141. foreach ($this->scopeChildren[$name] as $child) {
  142. $services[$child] = $this->scopedServices[$child];
  143. unset($this->scopedServices[$child]);
  144. }
  145. $this->services = call_user_func_array('array_diff_key', $services);
  146. array_shift($services);
  147. if (!isset($this->scopeStacks[$name])) {
  148. $this->scopeStacks[$name] = new \SplStack();
  149. }
  150. $this->scopeStacks[$name]->push($services);
  151. }
  152. $this->scopedServices[$name] = array();
  153. }
  154. public function leaveScope($name)
  155. {
  156. if (!isset($this->scopedServices[$name])) {
  157. throw new \InvalidArgumentException(sprintf('The scope "%s" is not active.', $name));
  158. }
  159. $services = array($this->services, $this->scopedServices[$name]);
  160. unset($this->scopedServices[$name]);
  161. foreach ($this->scopeChildren[$name] as $child) {
  162. if (!isset($this->scopedServices[$child])) {
  163. continue;
  164. }
  165. $services[] = $this->scopedServices[$child];
  166. unset($this->scopedServices[$child]);
  167. }
  168. $this->services = call_user_func_array('array_diff_key', $services);
  169. if (isset($this->scopeStacks[$name]) && count($this->scopeStacks[$name]) > 0) {
  170. $services = $this->scopeStacks[$name]->pop();
  171. $this->scopedServices += $services;
  172. array_unshift($services, $this->services);
  173. $this->services = call_user_func_array('array_merge', $services);
  174. }
  175. }
  176. public function addScope(ScopeInterface $scope)
  177. {
  178. $name = $scope->getName();
  179. $parentScope = $scope->getParentName();
  180. if (self::SCOPE_CONTAINER === $name || self::SCOPE_PROTOTYPE === $name) {
  181. throw new \InvalidArgumentException(sprintf('The scope "%s" is reserved.', $name));
  182. }
  183. if (isset($this->scopes[$name])) {
  184. throw new \InvalidArgumentException(sprintf('A scope with name "%s" already exists.', $name));
  185. }
  186. if (self::SCOPE_CONTAINER !== $parentScope && !isset($this->scopes[$parentScope])) {
  187. throw new \InvalidArgumentException(sprintf('The parent scope "%s" does not exist, or is invalid.', $parentScope));
  188. }
  189. $this->scopes[$name] = $parentScope;
  190. $this->scopeChildren[$name] = array();
  191. while ($parentScope !== self::SCOPE_CONTAINER) {
  192. $this->scopeChildren[$parentScope][] = $name;
  193. $parentScope = $this->scopes[$parentScope];
  194. }
  195. }
  196. public function hasScope($name)
  197. {
  198. return isset($this->scopes[$name]);
  199. }
  200. public function isScopeActive($name)
  201. {
  202. return isset($this->scopedServices[$name]);
  203. }
  204. static public function camelize($id)
  205. {
  206. return preg_replace(array('/(?:^|_)+(.)/e', '/\.(.)/e'), array("strtoupper('\\1')", "'_'.strtoupper('\\1')"), $id);
  207. }
  208. static public function underscore($id)
  209. {
  210. return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($id, '_', '.')));
  211. }
  212. }
  213. }
  214. namespace Symfony\Component\DependencyInjection
  215. {
  216. interface ContainerAwareInterface
  217. {
  218. function setContainer(ContainerInterface $container = null);
  219. }
  220. }
  221. namespace Symfony\Component\DependencyInjection
  222. {
  223. class ContainerAware implements ContainerAwareInterface
  224. {
  225. protected $container;
  226. public function setContainer(ContainerInterface $container = null)
  227. {
  228. $this->container = $container;
  229. }
  230. }
  231. }
  232. namespace Symfony\Component\HttpKernel\Bundle
  233. {
  234. use Symfony\Component\DependencyInjection\ContainerBuilder;
  235. interface BundleInterface
  236. {
  237. function boot();
  238. function shutdown();
  239. function build(ContainerBuilder $container);
  240. function getContainerExtension();
  241. function getParent();
  242. function getName();
  243. function getNamespace();
  244. function getPath();
  245. }
  246. }
  247. namespace Symfony\Component\HttpKernel\Bundle
  248. {
  249. use Symfony\Component\DependencyInjection\ContainerAware;
  250. use Symfony\Component\DependencyInjection\ContainerBuilder;
  251. use Symfony\Component\DependencyInjection\Container;
  252. use Symfony\Component\Console\Application;
  253. use Symfony\Component\Finder\Finder;
  254. abstract class Bundle extends ContainerAware implements BundleInterface
  255. {
  256. protected $name;
  257. protected $reflected;
  258. protected $extension;
  259. public function boot()
  260. {
  261. }
  262. public function shutdown()
  263. {
  264. }
  265. public function build(ContainerBuilder $container)
  266. {
  267. }
  268. public function getContainerExtension()
  269. {
  270. if (null === $this->extension) {
  271. $basename = preg_replace('/Bundle$/', '', $this->getName());
  272. $class = $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
  273. if (class_exists($class)) {
  274. $extension = new $class();
  275. $expectedAlias = Container::underscore($basename);
  276. if ($expectedAlias != $extension->getAlias()) {
  277. throw new \LogicException(sprintf(
  278. 'The extension alias for the default extension of a '.
  279. 'bundle must be the underscored version of the '.
  280. 'bundle name ("%s" vs "%s")',
  281. $expectedAlias, $extension->getAlias()
  282. ));
  283. }
  284. $this->extension = $extension;
  285. } else {
  286. $this->extension = false;
  287. }
  288. }
  289. if ($this->extension) {
  290. return $this->extension;
  291. }
  292. }
  293. public function getNamespace()
  294. {
  295. if (null === $this->reflected) {
  296. $this->reflected = new \ReflectionObject($this);
  297. }
  298. return $this->reflected->getNamespaceName();
  299. }
  300. public function getPath()
  301. {
  302. if (null === $this->reflected) {
  303. $this->reflected = new \ReflectionObject($this);
  304. }
  305. return dirname($this->reflected->getFileName());
  306. }
  307. public function getParent()
  308. {
  309. return null;
  310. }
  311. final public function getName()
  312. {
  313. if (null !== $this->name) {
  314. return $this->name;
  315. }
  316. $name = get_class($this);
  317. $pos = strrpos($name, '\\');
  318. return $this->name = false === $pos ? $name : substr($name, $pos + 1);
  319. }
  320. public function registerCommands(Application $application)
  321. {
  322. if (!$dir = realpath($this->getPath().'/Command')) {
  323. return;
  324. }
  325. $finder = new Finder();
  326. $finder->files()->name('*Command.php')->in($dir);
  327. $prefix = $this->getNamespace().'\\Command';
  328. foreach ($finder as $file) {
  329. $ns = $prefix;
  330. if ($relativePath = $file->getRelativePath()) {
  331. $ns .= '\\'.strtr($relativePath, '/', '\\');
  332. }
  333. $r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
  334. if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
  335. $application->add($r->newInstance());
  336. }
  337. }
  338. }
  339. }
  340. }
  341. namespace Symfony\Component\HttpKernel\Debug
  342. {
  343. class ErrorHandler
  344. {
  345. private $levels = array(
  346. E_WARNING => 'Warning',
  347. E_NOTICE => 'Notice',
  348. E_USER_ERROR => 'User Error',
  349. E_USER_WARNING => 'User Warning',
  350. E_USER_NOTICE => 'User Notice',
  351. E_STRICT => 'Runtime Notice',
  352. E_RECOVERABLE_ERROR => 'Catchable Fatal Error',
  353. );
  354. private $level;
  355. static public function register($level = null)
  356. {
  357. $handler = new static();
  358. $handler->setLevel($level);
  359. set_error_handler(array($handler, 'handle'));
  360. return $handler;
  361. }
  362. public function setLevel($level)
  363. {
  364. $this->level = null === $level ? error_reporting() : $level;
  365. }
  366. public function handle($level, $message, $file, $line, $context)
  367. {
  368. if (0 === $this->level) {
  369. return false;
  370. }
  371. if (error_reporting() & $level && $this->level & $level) {
  372. throw new \ErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line));
  373. }
  374. return false;
  375. }
  376. }
  377. }
  378. namespace Symfony\Component\HttpKernel
  379. {
  380. use Symfony\Component\HttpFoundation\Request;
  381. use Symfony\Component\HttpFoundation\Response;
  382. interface HttpKernelInterface
  383. {
  384. const MASTER_REQUEST = 1;
  385. const SUB_REQUEST = 2;
  386. function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
  387. }
  388. }
  389. namespace Symfony\Component\HttpKernel
  390. {
  391. use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
  392. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  393. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  394. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  395. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  396. use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
  397. use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
  398. use Symfony\Component\HttpFoundation\Request;
  399. use Symfony\Component\HttpFoundation\Response;
  400. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  401. class HttpKernel implements HttpKernelInterface
  402. {
  403. private $dispatcher;
  404. private $resolver;
  405. public function __construct(EventDispatcherInterface $dispatcher, ControllerResolverInterface $resolver)
  406. {
  407. $this->dispatcher = $dispatcher;
  408. $this->resolver = $resolver;
  409. }
  410. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  411. {
  412. try {
  413. return $this->handleRaw($request, $type);
  414. } catch (\Exception $e) {
  415. if (false === $catch) {
  416. throw $e;
  417. }
  418. return $this->handleException($e, $request, $type);
  419. }
  420. }
  421. private function handleRaw(Request $request, $type = self::MASTER_REQUEST)
  422. {
  423. $event = new GetResponseEvent($this, $request, $type);
  424. $this->dispatcher->dispatch(CoreEvents::REQUEST, $event);
  425. if ($event->hasResponse()) {
  426. return $this->filterResponse($event->getResponse(), $request, $type);
  427. }
  428. if (false === $controller = $this->resolver->getController($request)) {
  429. 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()));
  430. }
  431. $event = new FilterControllerEvent($this, $controller, $request, $type);
  432. $this->dispatcher->dispatch(CoreEvents::CONTROLLER, $event);
  433. $controller = $event->getController();
  434. $arguments = $this->resolver->getArguments($request, $controller);
  435. $response = call_user_func_array($controller, $arguments);
  436. if (!$response instanceof Response) {
  437. $event = new GetResponseForControllerResultEvent($this, $request, $type, $response);
  438. $this->dispatcher->dispatch(CoreEvents::VIEW, $event);
  439. if ($event->hasResponse()) {
  440. $response = $event->getResponse();
  441. }
  442. if (!$response instanceof Response) {
  443. $msg = sprintf('The controller must return a response (%s given).', $this->varToString($response));
  444. if (null === $response) {
  445. $msg .= ' Did you forget to add a return statement somewhere in your controller?';
  446. }
  447. throw new \LogicException($msg);
  448. }
  449. }
  450. return $this->filterResponse($response, $request, $type);
  451. }
  452. private function filterResponse(Response $response, Request $request, $type)
  453. {
  454. $event = new FilterResponseEvent($this, $request, $type, $response);
  455. $this->dispatcher->dispatch(CoreEvents::RESPONSE, $event);
  456. return $event->getResponse();
  457. }
  458. private function handleException(\Exception $e, $request, $type)
  459. {
  460. $event = new GetResponseForExceptionEvent($this, $request, $type, $e);
  461. $this->dispatcher->dispatch(CoreEvents::EXCEPTION, $event);
  462. if (!$event->hasResponse()) {
  463. throw $e;
  464. }
  465. try {
  466. return $this->filterResponse($event->getResponse(), $request, $type);
  467. } catch (\Exception $e) {
  468. return $event->getResponse();
  469. }
  470. }
  471. private function varToString($var)
  472. {
  473. if (is_object($var)) {
  474. return sprintf('[object](%s)', get_class($var));
  475. }
  476. if (is_array($var)) {
  477. $a = array();
  478. foreach ($var as $k => $v) {
  479. $a[] = sprintf('%s => %s', $k, $this->varToString($v));
  480. }
  481. return sprintf("[array](%s)", implode(', ', $a));
  482. }
  483. if (is_resource($var)) {
  484. return '[resource]';
  485. }
  486. if (null === $var) {
  487. return 'null';
  488. }
  489. return str_replace("\n", '', var_export((string) $var, true));
  490. }
  491. }
  492. }
  493. namespace Symfony\Component\HttpKernel
  494. {
  495. use Symfony\Component\DependencyInjection\ContainerInterface;
  496. use Symfony\Component\HttpKernel\HttpKernelInterface;
  497. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  498. use Symfony\Component\Config\Loader\LoaderInterface;
  499. interface KernelInterface extends HttpKernelInterface, \Serializable
  500. {
  501. function registerBundles();
  502. function registerContainerConfiguration(LoaderInterface $loader);
  503. function boot();
  504. function shutdown();
  505. function getBundles();
  506. function isClassInActiveBundle($class);
  507. function getBundle($name, $first = true);
  508. function locateResource($name, $dir = null, $first = true);
  509. function getName();
  510. function getEnvironment();
  511. function isDebug();
  512. function getRootDir();
  513. function getContainer();
  514. function getStartTime();
  515. function getCacheDir();
  516. function getLogDir();
  517. }
  518. }
  519. namespace Symfony\Component\HttpKernel
  520. {
  521. use Symfony\Component\DependencyInjection\ContainerInterface;
  522. use Symfony\Component\DependencyInjection\ContainerBuilder;
  523. use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
  524. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  525. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  526. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  527. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  528. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  529. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  530. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  531. use Symfony\Component\HttpFoundation\Request;
  532. use Symfony\Component\HttpKernel\HttpKernelInterface;
  533. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  534. use Symfony\Component\HttpKernel\Config\FileLocator;
  535. use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
  536. use Symfony\Component\HttpKernel\DependencyInjection\AddClassesToCachePass;
  537. use Symfony\Component\HttpKernel\DependencyInjection\Extension as DIExtension;
  538. use Symfony\Component\Config\Loader\LoaderResolver;
  539. use Symfony\Component\Config\Loader\DelegatingLoader;
  540. use Symfony\Component\Config\ConfigCache;
  541. use Symfony\Component\ClassLoader\ClassCollectionLoader;
  542. abstract class Kernel implements KernelInterface
  543. {
  544. protected $bundles;
  545. protected $bundleMap;
  546. protected $container;
  547. protected $rootDir;
  548. protected $environment;
  549. protected $debug;
  550. protected $booted;
  551. protected $name;
  552. protected $startTime;
  553. protected $classes;
  554. const VERSION = '2.0.0-DEV';
  555. public function __construct($environment, $debug)
  556. {
  557. $this->environment = $environment;
  558. $this->debug = (Boolean) $debug;
  559. $this->booted = false;
  560. $this->rootDir = $this->getRootDir();
  561. $this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
  562. $this->classes = array();
  563. if ($this->debug) {
  564. $this->startTime = microtime(true);
  565. }
  566. $this->init();
  567. }
  568. public function __clone()
  569. {
  570. if ($this->debug) {
  571. $this->startTime = microtime(true);
  572. }
  573. $this->booted = false;
  574. $this->container = null;
  575. }
  576. public function init()
  577. {
  578. }
  579. public function boot()
  580. {
  581. if (true === $this->booted) {
  582. return;
  583. }
  584. $this->initializeBundles();
  585. $this->initializeContainer();
  586. foreach ($this->getBundles() as $bundle) {
  587. $bundle->setContainer($this->container);
  588. $bundle->boot();
  589. }
  590. $this->booted = true;
  591. }
  592. public function shutdown()
  593. {
  594. if (false === $this->booted) {
  595. return;
  596. }
  597. $this->booted = false;
  598. foreach ($this->getBundles() as $bundle) {
  599. $bundle->shutdown();
  600. $bundle->setContainer(null);
  601. }
  602. $this->container = null;
  603. }
  604. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  605. {
  606. if (false === $this->booted) {
  607. $this->boot();
  608. }
  609. return $this->getHttpKernel()->handle($request, $type, $catch);
  610. }
  611. protected function getHttpKernel()
  612. {
  613. return $this->container->get('http_kernel');
  614. }
  615. public function getBundles()
  616. {
  617. return $this->bundles;
  618. }
  619. public function isClassInActiveBundle($class)
  620. {
  621. foreach ($this->getBundles() as $bundle) {
  622. if (0 === strpos($class, $bundle->getNamespace())) {
  623. return true;
  624. }
  625. }
  626. return false;
  627. }
  628. public function getBundle($name, $first = true)
  629. {
  630. if (!isset($this->bundleMap[$name])) {
  631. throw new \InvalidArgumentException(sprintf('Bundle "%s" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() function of your %s.php file?', $name, get_class($this)));
  632. }
  633. if (true === $first) {
  634. return $this->bundleMap[$name][0];
  635. }
  636. return $this->bundleMap[$name];
  637. }
  638. public function locateResource($name, $dir = null, $first = true)
  639. {
  640. if ('@' !== $name[0]) {
  641. throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
  642. }
  643. if (false !== strpos($name, '..')) {
  644. throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
  645. }
  646. $bundleName = substr($name, 1);
  647. $path = '';
  648. if (false !== strpos($bundleName, '/')) {
  649. list($bundleName, $path) = explode('/', $bundleName, 2);
  650. }
  651. $isResource = 0 === strpos($path, 'Resources') && null !== $dir;
  652. $overridePath = substr($path, 9);
  653. $resourceBundle = null;
  654. $bundles = $this->getBundle($bundleName, false);
  655. $files = array();
  656. foreach ($bundles as $bundle) {
  657. if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
  658. if (null !== $resourceBundle) {
  659. 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.',
  660. $file,
  661. $resourceBundle,
  662. $dir.'/'.$bundles[0]->getName().$overridePath
  663. ));
  664. }
  665. if ($first) {
  666. return $file;
  667. }
  668. $files[] = $file;
  669. }
  670. if (file_exists($file = $bundle->getPath().'/'.$path)) {
  671. if ($first && !$isResource) {
  672. return $file;
  673. }
  674. $files[] = $file;
  675. $resourceBundle = $bundle->getName();
  676. }
  677. }
  678. if (count($files) > 0) {
  679. return $first && $isResource ? $files[0] : $files;
  680. }
  681. throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
  682. }
  683. public function getName()
  684. {
  685. return $this->name;
  686. }
  687. public function getEnvironment()
  688. {
  689. return $this->environment;
  690. }
  691. public function isDebug()
  692. {
  693. return $this->debug;
  694. }
  695. public function getRootDir()
  696. {
  697. if (null === $this->rootDir) {
  698. $r = new \ReflectionObject($this);
  699. $this->rootDir = dirname($r->getFileName());
  700. }
  701. return $this->rootDir;
  702. }
  703. public function getContainer()
  704. {
  705. return $this->container;
  706. }
  707. public function loadClassCache($name = 'classes', $extension = '.php')
  708. {
  709. if (!$this->booted) {
  710. $this->boot();
  711. }
  712. if ($this->classes) {
  713. ClassCollectionLoader::load($this->classes, $this->getCacheDir(), $name, $this->debug, true, $extension);
  714. }
  715. }
  716. public function addClassesToCache(array $classes)
  717. {
  718. $this->classes = array_unique(array_merge($this->classes, $classes));
  719. }
  720. public function getStartTime()
  721. {
  722. return $this->debug ? $this->startTime : -INF;
  723. }
  724. public function getCacheDir()
  725. {
  726. return $this->rootDir.'/cache/'.$this->environment;
  727. }
  728. public function getLogDir()
  729. {
  730. return $this->rootDir.'/logs';
  731. }
  732. protected function initializeBundles()
  733. {
  734. $this->bundles = array();
  735. $topMostBundles = array();
  736. $directChildren = array();
  737. foreach ($this->registerBundles() as $bundle) {
  738. $name = $bundle->getName();
  739. if (isset($this->bundles[$name])) {
  740. throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name));
  741. }
  742. $this->bundles[$name] = $bundle;
  743. if ($parentName = $bundle->getParent()) {
  744. if (isset($directChildren[$parentName])) {
  745. throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
  746. }
  747. if ($parentName == $name) {
  748. throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name));
  749. }
  750. $directChildren[$parentName] = $name;
  751. } else {
  752. $topMostBundles[$name] = $bundle;
  753. }
  754. }
  755. if (count($diff = array_values(array_diff(array_keys($directChildren), array_keys($this->bundles))))) {
  756. throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0]));
  757. }
  758. $this->bundleMap = array();
  759. foreach ($topMostBundles as $name => $bundle) {
  760. $bundleMap = array($bundle);
  761. $hierarchy = array($name);
  762. while (isset($directChildren[$name])) {
  763. $name = $directChildren[$name];
  764. array_unshift($bundleMap, $this->bundles[$name]);
  765. $hierarchy[] = $name;
  766. }
  767. foreach ($hierarchy as $bundle) {
  768. $this->bundleMap[$bundle] = $bundleMap;
  769. array_pop($bundleMap);
  770. }
  771. }
  772. }
  773. protected function getContainerClass()
  774. {
  775. return $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
  776. }
  777. protected function getContainerBaseClass()
  778. {
  779. return 'Container';
  780. }
  781. protected function initializeContainer()
  782. {
  783. $class = $this->getContainerClass();
  784. $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
  785. $fresh = true;
  786. if (!$cache->isFresh()) {
  787. $container = $this->buildContainer();
  788. $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
  789. $fresh = false;
  790. }
  791. require_once $cache;
  792. $this->container = new $class();
  793. $this->container->set('kernel', $this);
  794. if (!$fresh && 'cli' !== php_sapi_name()) {
  795. $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
  796. }
  797. }
  798. protected function getKernelParameters()
  799. {
  800. $bundles = array();
  801. foreach ($this->bundles as $name => $bundle) {
  802. $bundles[$name] = get_class($bundle);
  803. }
  804. return array_merge(
  805. array(
  806. 'kernel.root_dir' => $this->rootDir,
  807. 'kernel.environment' => $this->environment,
  808. 'kernel.debug' => $this->debug,
  809. 'kernel.name' => $this->name,
  810. 'kernel.cache_dir' => $this->getCacheDir(),
  811. 'kernel.logs_dir' => $this->getLogDir(),
  812. 'kernel.bundles' => $bundles,
  813. 'kernel.charset' => 'UTF-8',
  814. 'kernel.container_class' => $this->getContainerClass(),
  815. ),
  816. $this->getEnvParameters()
  817. );
  818. }
  819. protected function getEnvParameters()
  820. {
  821. $parameters = array();
  822. foreach ($_SERVER as $key => $value) {
  823. if ('SYMFONY__' === substr($key, 0, 9)) {
  824. $parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value;
  825. }
  826. }
  827. return $parameters;
  828. }
  829. protected function buildContainer()
  830. {
  831. foreach (array('cache' => $this->getCacheDir(), 'logs' => $this->getLogDir()) as $name => $dir) {
  832. if (!is_dir($dir)) {
  833. if (false === @mkdir($dir, 0777, true)) {
  834. throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n", $name, dirname($dir)));
  835. }
  836. } elseif (!is_writable($dir)) {
  837. throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", $name, $dir));
  838. }
  839. }
  840. $container = new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
  841. $extensions = array();
  842. foreach ($this->bundles as $bundle) {
  843. $bundle->build($container);
  844. if ($extension = $bundle->getContainerExtension()) {
  845. $container->registerExtension($extension);
  846. $extensions[] = $extension->getAlias();
  847. }
  848. if ($this->debug) {
  849. $container->addObjectResource($bundle);
  850. }
  851. }
  852. $container->addObjectResource($this);
  853. $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
  854. if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
  855. $container->merge($cont);
  856. }
  857. $container->addCompilerPass(new AddClassesToCachePass($this));
  858. $container->compile();
  859. $this->addClassesToCache($container->getParameter('kernel.compiled_classes'));
  860. return $container;
  861. }
  862. protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
  863. {
  864. $dumper = new PhpDumper($container);
  865. $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass));
  866. if (!$this->debug) {
  867. $content = self::stripComments($content);
  868. }
  869. $cache->write($content, $container->getResources());
  870. }
  871. protected function getContainerLoader(ContainerInterface $container)
  872. {
  873. $locator = new FileLocator($this);
  874. $resolver = new LoaderResolver(array(
  875. new XmlFileLoader($container, $locator),
  876. new YamlFileLoader($container, $locator),
  877. new IniFileLoader($container, $locator),
  878. new PhpFileLoader($container, $locator),
  879. new ClosureLoader($container),
  880. ));
  881. return new DelegatingLoader($resolver);
  882. }
  883. static public function stripComments($source)
  884. {
  885. if (!function_exists('token_get_all')) {
  886. return $source;
  887. }
  888. $output = '';
  889. foreach (token_get_all($source) as $token) {
  890. if (is_string($token)) {
  891. $output .= $token;
  892. } elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
  893. $output .= $token[1];
  894. }
  895. }
  896. $output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
  897. return $output;
  898. }
  899. public function serialize()
  900. {
  901. return serialize(array($this->environment, $this->debug));
  902. }
  903. public function unserialize($data)
  904. {
  905. list($environment, $debug) = unserialize($data);
  906. $this->__construct($environment, $debug);
  907. }
  908. }
  909. }
  910. namespace Symfony\Component\HttpFoundation
  911. {
  912. class ParameterBag
  913. {
  914. protected $parameters;
  915. public function __construct(array $parameters = array())
  916. {
  917. $this->parameters = $parameters;
  918. }
  919. public function all()
  920. {
  921. return $this->parameters;
  922. }
  923. public function keys()
  924. {
  925. return array_keys($this->parameters);
  926. }
  927. public function replace(array $parameters = array())
  928. {
  929. $this->parameters = $parameters;
  930. }
  931. public function add(array $parameters = array())
  932. {
  933. $this->parameters = array_replace($this->parameters, $parameters);
  934. }
  935. public function get($path, $default = null, $deep = false)
  936. {
  937. if (!$deep || false === $pos = strpos($path, '[')) {
  938. return array_key_exists($path, $this->parameters) ? $this->parameters[$path] : $default;
  939. }
  940. $root = substr($path, 0, $pos);
  941. if (!array_key_exists($root, $this->parameters)) {
  942. return $default;
  943. }
  944. $value = $this->parameters[$root];
  945. $currentKey = null;
  946. for ($i=$pos,$c=strlen($path); $i<$c; $i++) {
  947. $char = $path[$i];
  948. if ('[' === $char) {
  949. if (null !== $currentKey) {
  950. throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "[" at position %d.', $i));
  951. }
  952. $currentKey = '';
  953. } else if (']' === $char) {
  954. if (null === $currentKey) {
  955. throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "]" at position %d.', $i));
  956. }
  957. if (!is_array($value) || !array_key_exists($currentKey, $value)) {
  958. return $default;
  959. }
  960. $value = $value[$currentKey];
  961. $currentKey = null;
  962. } else {
  963. if (null === $currentKey) {
  964. throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "%s" at position %d.', $char, $i));
  965. }
  966. $currentKey .= $char;
  967. }
  968. }
  969. if (null !== $currentKey) {
  970. throw new \InvalidArgumentException(sprintf('Malformed path. Path must end with "]".'));
  971. }
  972. return $value;
  973. }
  974. public function set($key, $value)
  975. {
  976. $this->parameters[$key] = $value;
  977. }
  978. public function has($key)
  979. {
  980. return array_key_exists($key, $this->parameters);
  981. }
  982. public function remove($key)
  983. {
  984. unset($this->parameters[$key]);
  985. }
  986. public function getAlpha($key, $default = '', $deep = false)
  987. {
  988. return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default, $deep));
  989. }
  990. public function getAlnum($key, $default = '', $deep = false)
  991. {
  992. return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default, $deep));
  993. }
  994. public function getDigits($key, $default = '', $deep = false)
  995. {
  996. return preg_replace('/[^[:digit:]]/', '', $this->get($key, $default, $deep));
  997. }
  998. public function getInt($key, $default = 0, $deep = false)
  999. {
  1000. return (int) $this->get($key, $default, $deep);
  1001. }
  1002. }
  1003. }
  1004. namespace Symfony\Component\HttpFoundation
  1005. {
  1006. use Symfony\Component\HttpFoundation\File\UploadedFile;
  1007. class FileBag extends ParameterBag
  1008. {
  1009. static private $fileKeys = array('error', 'name', 'size', 'tmp_name', 'type');
  1010. public function __construct(array $parameters = array())
  1011. {
  1012. $this->replace($parameters);
  1013. }
  1014. public function replace(array $files = array())
  1015. {
  1016. $this->parameters = array();
  1017. $this->add($files);
  1018. }
  1019. public function set($key, $value)
  1020. {
  1021. if (is_array($value) || $value instanceof UploadedFile) {
  1022. parent::set($key, $this->convertFileInformation($value));
  1023. }
  1024. }
  1025. public function add(array $files = array())
  1026. {
  1027. foreach ($files as $key => $file) {
  1028. $this->set($key, $file);
  1029. }
  1030. }
  1031. protected function convertFileInformation($file)
  1032. {
  1033. if ($file instanceof UploadedFile) {
  1034. return $file;
  1035. }
  1036. $file = $this->fixPhpFilesArray($file);
  1037. if (is_array($file)) {
  1038. $keys = array_keys($file);
  1039. sort($keys);
  1040. if ($keys == self::$fileKeys) {
  1041. if (UPLOAD_ERR_NO_FILE == $file['error']) {
  1042. $file = null;
  1043. } else {
  1044. $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']);
  1045. }
  1046. } else {
  1047. $file = array_map(array($this, 'convertFileInformation'), $file);
  1048. }
  1049. }
  1050. return $file;
  1051. }
  1052. protected function fixPhpFilesArray($data)
  1053. {
  1054. if (!is_array($data)) {
  1055. return $data;
  1056. }
  1057. $keys = array_keys($data);
  1058. sort($keys);
  1059. if (self::$fileKeys != $keys || !isset($data['name']) || !is_array($data['name'])) {
  1060. return $data;
  1061. }
  1062. $files = $data;
  1063. foreach (self::$fileKeys as $k) {
  1064. unset($files[$k]);
  1065. }
  1066. foreach (array_keys($data['name']) as $key) {
  1067. $files[$key] = $this->fixPhpFilesArray(array(
  1068. 'error' => $data['error'][$key],
  1069. 'name' => $data['name'][$key],
  1070. 'type' => $data['type'][$key],
  1071. 'tmp_name' => $data['tmp_name'][$key],
  1072. 'size' => $data['size'][$key]
  1073. ));
  1074. }
  1075. return $files;
  1076. }
  1077. }
  1078. }
  1079. namespace Symfony\Component\HttpFoundation
  1080. {
  1081. class ServerBag extends ParameterBag
  1082. {
  1083. public function getHeaders()
  1084. {
  1085. $headers = array();
  1086. foreach ($this->parameters as $key => $value) {
  1087. if ('HTTP_' === substr($key, 0, 5)) {
  1088. $headers[substr($key, 5)] = $value;
  1089. }
  1090. }
  1091. return $headers;
  1092. }
  1093. }
  1094. }
  1095. namespace Symfony\Component\HttpFoundation
  1096. {
  1097. class HeaderBag
  1098. {
  1099. protected $headers;
  1100. protected $cookies;
  1101. protected $cacheControl;
  1102. public function __construct(array $headers = array())
  1103. {
  1104. $this->cacheControl = array();
  1105. $this->cookies = array();
  1106. $this->headers = array();
  1107. foreach ($headers as $key => $values) {
  1108. $this->set($key, $values);
  1109. }
  1110. }
  1111. public function __toString()
  1112. {
  1113. if (!$this->headers) {
  1114. return '';
  1115. }
  1116. $beautifier = function ($name) {
  1117. return preg_replace('/\-(.)/e', "'-'.strtoupper('\\1')", ucfirst($name));
  1118. };
  1119. $max = max(array_map('strlen', array_keys($this->headers))) + 1;
  1120. $content = '';
  1121. ksort($this->headers);
  1122. foreach ($this->headers as $name => $values) {
  1123. foreach ($values as $value) {
  1124. $content .= sprintf("%-{$max}s %s\r\n", $beautifier($name).':', $value);
  1125. }
  1126. }
  1127. return $content;
  1128. }
  1129. public function all()
  1130. {
  1131. return $this->headers;
  1132. }
  1133. public function keys()
  1134. {
  1135. return array_keys($this->headers);
  1136. }
  1137. public function replace(array $headers = array())
  1138. {
  1139. $this->headers = array();
  1140. $this->add($headers);
  1141. }
  1142. public function add(array $headers)
  1143. {
  1144. foreach ($headers as $key => $values) {
  1145. $this->set($key, $values);
  1146. }
  1147. }
  1148. public function get($key, $default = null, $first = true)
  1149. {
  1150. $key = strtr(strtolower($key), '_', '-');
  1151. if (!array_key_exists($key, $this->headers)) {
  1152. if (null === $default) {
  1153. return $first ? null : array();
  1154. }
  1155. return $first ? $default : array($default);
  1156. }
  1157. if ($first) {
  1158. return count($this->headers[$key]) ? $this->headers[$key][0] : $default;
  1159. }
  1160. return $this->headers[$key];
  1161. }
  1162. public function set($key, $values, $replace = true)
  1163. {
  1164. $key = strtr(strtolower($key), '_', '-');
  1165. $values = (array) $values;
  1166. if (true === $replace || !isset($this->headers[$key])) {
  1167. $this->headers[$key] = $values;
  1168. } else {
  1169. $this->headers[$key] = array_merge($this->headers[$key], $values);
  1170. }
  1171. if ('cache-control' === $key) {
  1172. $this->cacheControl = $this->parseCacheControl($values[0]);
  1173. }
  1174. }
  1175. public function has($key)
  1176. {
  1177. return array_key_exists(strtr(strtolower($key), '_', '-'), $this->headers);
  1178. }
  1179. public function contains($key, $value)
  1180. {
  1181. return in_array($value, $this->get($key, null, false));
  1182. }
  1183. public function remove($key)
  1184. {
  1185. $key = strtr(strtolower($key), '_', '-');
  1186. unset($this->headers[$key]);
  1187. if ('cache-control' === $key) {
  1188. $this->cacheControl = array();
  1189. }
  1190. }
  1191. public function setCookie(Cookie $cookie)
  1192. {
  1193. $this->cookies[$cookie->getName()] = $cookie;
  1194. }
  1195. public function removeCookie($name)
  1196. {
  1197. unset($this->cookies[$name]);
  1198. }
  1199. public function hasCookie($name)
  1200. {
  1201. return isset($this->cookies[$name]);
  1202. }
  1203. public function getCookie($name)
  1204. {
  1205. if (!$this->hasCookie($name)) {
  1206. throw new \InvalidArgumentException(sprintf('There is no cookie with name "%s".', $name));
  1207. }
  1208. return $this->cookies[$name];
  1209. }
  1210. public function getCookies()
  1211. {
  1212. return $this->cookies;
  1213. }
  1214. public function getDate($key, \DateTime $default = null)
  1215. {
  1216. if (null === $value = $this->get($key)) {
  1217. return $default;
  1218. }
  1219. if (false === $date = \DateTime::createFromFormat(DATE_RFC2822, $value)) {
  1220. throw new \RuntimeException(sprintf('The %s HTTP header is not parseable (%s).', $key, $value));
  1221. }
  1222. return $date;
  1223. }
  1224. public function addCacheControlDirective($key, $value = true)
  1225. {
  1226. $this->cacheControl[$key] = $value;
  1227. $this->set('Cache-Control', $this->getCacheControlHeader());
  1228. }
  1229. public function hasCacheControlDirective($key)
  1230. {
  1231. return array_key_exists($key, $this->cacheControl);
  1232. }
  1233. public function getCacheControlDirective($key)
  1234. {
  1235. return array_key_exists($key, $this->cacheControl) ? $this->cacheControl[$key] : null;
  1236. }
  1237. public function removeCacheControlDirective($key)
  1238. {
  1239. unset($this->cacheControl[$key]);
  1240. $this->set('Cache-Control', $this->getCacheControlHeader());
  1241. }
  1242. protected function getCacheControlHeader()
  1243. {
  1244. $parts = array();
  1245. ksort($this->cacheControl);
  1246. foreach ($this->cacheControl as $key => $value) {
  1247. if (true === $value) {
  1248. $parts[] = $key;
  1249. } else {
  1250. if (preg_match('#[^a-zA-Z0-9._-]#', $value)) {
  1251. $value = '"'.$value.'"';
  1252. }
  1253. $parts[] = "$key=$value";
  1254. }
  1255. }
  1256. return implode(', ', $parts);
  1257. }
  1258. protected function parseCacheControl($header)
  1259. {
  1260. $cacheControl = array();
  1261. preg_match_all('#([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?#', $header, $matches, PREG_SET_ORDER);
  1262. foreach ($matches as $match) {
  1263. $cacheControl[strtolower($match[1])] = isset($match[2]) && $match[2] ? $match[2] : (isset($match[3]) ? $match[3] : true);
  1264. }
  1265. return $cacheControl;
  1266. }
  1267. }
  1268. }
  1269. namespace Symfony\Component\HttpFoundation
  1270. {
  1271. use Symfony\Component\HttpFoundation\SessionStorage\NativeSessionStorage;
  1272. class Request
  1273. {
  1274. public $attributes;
  1275. public $request;
  1276. public $query;
  1277. public $server;
  1278. public $files;
  1279. public $cookies;
  1280. public $headers;
  1281. protected $content;
  1282. protected $languages;
  1283. protected $charsets;
  1284. protected $acceptableContentTypes;
  1285. protected $pathInfo;
  1286. protected $requestUri;
  1287. protected $baseUrl;
  1288. protected $basePath;
  1289. protected $method;
  1290. protected $format;
  1291. protected $session;
  1292. static protected $formats;
  1293. public function __construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
  1294. {
  1295. $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content);
  1296. }
  1297. public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
  1298. {
  1299. $this->request = new ParameterBag($request);
  1300. $this->query = new ParameterBag($query);
  1301. $this->attributes = new ParameterBag($attributes);
  1302. $this->cookies = new ParameterBag($cookies);
  1303. $this->files = new FileBag($files);
  1304. $this->server = new ServerBag($server);
  1305. $this->headers = new HeaderBag($this->server->getHeaders());
  1306. $this->content = $content;
  1307. $this->languages = null;
  1308. $this->charsets = null;
  1309. $this->acceptableContentTypes = null;
  1310. $this->pathInfo = null;
  1311. $this->requestUri = null;
  1312. $this->baseUrl = null;
  1313. $this->basePath = null;
  1314. $this->method = null;
  1315. $this->format = null;
  1316. }
  1317. static public function createFromGlobals()
  1318. {
  1319. $request = new static($_GET, $_POST, array(), $_COOKIE, $_FILES, $_SERVER);
  1320. if (0 === strpos($request->server->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded')
  1321. && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), array('PUT', 'DELETE'))
  1322. ) {
  1323. parse_str($request->getContent(), $data);
  1324. $request->request = new ParameterBag($data);
  1325. }
  1326. return $request;
  1327. }
  1328. static public function create($uri, $method = 'GET', $parameters = array(), $cookies = array(), $files = array(), $server = array(), $content = null)
  1329. {
  1330. $defaults = array(
  1331. 'SERVER_NAME' => 'localhost',
  1332. 'SERVER_PORT' => 80,
  1333. 'HTTP_HOST' => 'localhost',
  1334. 'HTTP_USER_AGENT' => 'Symfony/2.X',
  1335. 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  1336. 'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
  1337. 'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
  1338. 'REMOTE_ADDR' => '127.0.0.1',
  1339. 'SCRIPT_NAME' => '',
  1340. 'SCRIPT_FILENAME' => '',
  1341. 'SERVER_PROTOCOL' => 'HTTP/1.1',
  1342. );
  1343. $components = parse_url($uri);
  1344. if (isset($components['host'])) {
  1345. $defaults['SERVER_NAME'] = $components['host'];
  1346. $defaults['HTTP_HOST'] = $components['host'];
  1347. }
  1348. if (isset($components['scheme'])) {
  1349. if ('https' === $components['scheme']) {
  1350. $defaults['HTTPS'] = 'on';
  1351. $defaults['SERVER_PORT'] = 443;
  1352. }
  1353. }
  1354. if (isset($components['port'])) {
  1355. $defaults['SERVER_PORT'] = $components['port'];
  1356. $defaults['HTTP_HOST'] = $defaults['HTTP_HOST'].':'.$components['port'];
  1357. }
  1358. if (in_array(strtoupper($method), array('POST', 'PUT', 'DELETE'))) {
  1359. $request = $parameters;
  1360. $query = array();
  1361. $defaults['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
  1362. } else {
  1363. $request = array();
  1364. $query = $parameters;
  1365. if (false !== $pos = strpos($uri, '?')) {
  1366. $qs = substr($uri, $pos + 1);
  1367. parse_str($qs, $params);
  1368. $query = array_merge($params, $query);
  1369. }
  1370. }
  1371. $queryString = isset($components['query']) ? html_entity_decode($components['query']) : '';
  1372. parse_str($queryString, $qs);
  1373. if (is_array($qs)) {
  1374. $query = array_replace($qs, $query);
  1375. }
  1376. $uri = $components['path'] . ($queryString ? '?'.$queryString : '');
  1377. $server = array_replace($defaults, $server, array(
  1378. 'REQUEST_METHOD' => strtoupper($method),
  1379. 'PATH_INFO' => '',
  1380. 'REQUEST_URI' => $uri,
  1381. 'QUERY_STRING' => $queryString,
  1382. ));
  1383. return new static($query, $request, array(), $cookies, $files, $server, $content);
  1384. }
  1385. public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
  1386. {
  1387. $dup = clone $this;
  1388. if ($query !== null) {
  1389. $dup->query = new ParameterBag($query);
  1390. }
  1391. if ($request !== null) {
  1392. $dup->request = new ParameterBag($request);
  1393. }
  1394. if ($attributes !== null) {
  1395. $dup->attributes = new ParameterBag($attributes);
  1396. }
  1397. if ($cookies !== null) {
  1398. $dup->cookies = new ParameterBag($cookies);
  1399. }
  1400. if ($files !== null) {
  1401. $dup->files = new FileBag($files);
  1402. }
  1403. if ($server !== null) {
  1404. $dup->server = new ServerBag($server);
  1405. $dup->headers = new HeaderBag($dup->server->getHeaders());
  1406. }
  1407. $this->languages = null;
  1408. $this->charsets = null;
  1409. $this->acceptableContentTypes = null;
  1410. $this->pathInfo = null;
  1411. $this->requestUri = null;
  1412. $this->baseUrl = null;
  1413. $this->basePath = null;
  1414. $this->method = null;
  1415. $this->format = null;
  1416. return $dup;
  1417. }
  1418. public function __clone()
  1419. {
  1420. $this->query = clone $this->query;
  1421. $this->request = clone $this->request;
  1422. $this->attributes = clone $this->attributes;
  1423. $this->cookies = clone $this->cookies;
  1424. $this->files = clone $this->files;
  1425. $this->server = clone $this->server;
  1426. $this->headers = clone $this->headers;
  1427. }
  1428. public function __toString()
  1429. {
  1430. return
  1431. sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n".
  1432. $this->headers."\r\n".
  1433. $this->getContent();
  1434. }
  1435. public function overrideGlobals()
  1436. {
  1437. $_GET = $this->query->all();
  1438. $_POST = $this->request->all();
  1439. $_SERVER = $this->server->all();
  1440. $_COOKIE = $this->cookies->all();
  1441. foreach ($this->headers->all() as $key => $value) {
  1442. $_SERVER['HTTP_'.strtoupper(str_replace('-', '_', $key))] = implode(', ', $value);
  1443. }
  1444. $_REQUEST = array_merge($_GET, $_POST);
  1445. }
  1446. public function get($key, $default = null, $deep = false)
  1447. {
  1448. return $this->query->get($key, $this->attributes->get($key, $this->request->get($key, $default, $deep), $deep), $deep);
  1449. }
  1450. public function getSession()
  1451. {
  1452. return $this->session;
  1453. }
  1454. public function hasPreviousSession()
  1455. {
  1456. return $this->cookies->has(session_name()) && null !== $this->session;
  1457. }
  1458. public function hasSession()
  1459. {
  1460. return null !== $this->session;
  1461. }
  1462. public function setSession(Session $session)
  1463. {
  1464. $this->session = $session;
  1465. }
  1466. public function getClientIp($proxy = false)
  1467. {
  1468. if ($proxy) {
  1469. if ($this->server->has('HTTP_CLIENT_IP')) {
  1470. return $this->server->get('HTTP_CLIENT_IP');
  1471. } elseif ($this->server->has('HTTP_X_FORWARDED_FOR')) {
  1472. return $this->server->get('HTTP_X_FORWARDED_FOR');
  1473. }
  1474. }
  1475. return $this->server->get('REMOTE_ADDR');
  1476. }
  1477. public function getScriptName()
  1478. {
  1479. return $this->server->get('SCRIPT_NAME', $this->server->get('ORIG_SCRIPT_NAME', ''));
  1480. }
  1481. public function getPathInfo()
  1482. {
  1483. if (null === $this->pathInfo) {
  1484. $this->pathInfo = $this->preparePathInfo();
  1485. }
  1486. return $this->pathInfo;
  1487. }
  1488. public function getBasePath()
  1489. {
  1490. if (null === $this->basePath) {
  1491. $this->basePath = $this->prepareBasePath();
  1492. }
  1493. return $this->basePath;
  1494. }
  1495. public function getBaseUrl()
  1496. {
  1497. if (null === $this->baseUrl) {
  1498. $this->baseUrl = $this->prepareBaseUrl();
  1499. }
  1500. return $this->baseUrl;
  1501. }
  1502. public function getScheme()
  1503. {
  1504. return $this->isSecure() ? 'https' : 'http';
  1505. }
  1506. public function getPort()
  1507. {
  1508. return $this->headers->get('X-Forwarded-Port') ?: $this->server->get('SERVER_PORT');
  1509. }
  1510. public function getHttpHost()
  1511. {
  1512. $scheme = $this->getScheme();
  1513. $port = $this->getPort();
  1514. if (('http' == $scheme && $port == 80) || ('https' == $scheme && $port == 443)) {
  1515. return $this->getHost();
  1516. }
  1517. return $this->getHost().':'.$port;
  1518. }
  1519. public function getRequestUri()
  1520. {
  1521. if (null === $this->requestUri) {
  1522. $this->requestUri = $this->prepareRequestUri();
  1523. }
  1524. return $this->requestUri;
  1525. }
  1526. public function getUri()
  1527. {
  1528. $qs = $this->getQueryString();
  1529. if (null !== $qs) {
  1530. $qs = '?'.$qs;
  1531. }
  1532. return $this->getScheme().'://'.$this->getHttpHost().$this->getBaseUrl().$this->getPathInfo().$qs;
  1533. }
  1534. public function getUriForPath($path)
  1535. {
  1536. return $this->getScheme().'://'.$this->getHttpHost().$this->getBaseUrl().$path;
  1537. }
  1538. public function getQueryString()
  1539. {
  1540. if (!$qs = $this->server->get('QUERY_STRING')) {
  1541. return null;
  1542. }
  1543. $parts = array();
  1544. $order = array();
  1545. foreach (explode('&', $qs) as $segment) {
  1546. if (false === strpos($segment, '=')) {
  1547. $parts[] = $segment;
  1548. $order[] = $segment;
  1549. } else {
  1550. $tmp = explode('=', rawurldecode($segment), 2);
  1551. $parts[] = rawurlencode($tmp[0]).'='.rawurlencode($tmp[1]);
  1552. $order[] = $tmp[0];
  1553. }
  1554. }
  1555. array_multisort($order, SORT_ASC, $parts);
  1556. return implode('&', $parts);
  1557. }
  1558. public function isSecure()
  1559. {
  1560. return (
  1561. (strtolower($this->server->get('HTTPS')) == 'on' || $this->server->get('HTTPS') == 1)
  1562. ||
  1563. (strtolower($this->headers->get('SSL_HTTPS')) == 'on' || $this->headers->get('SSL_HTTPS') == 1)
  1564. ||
  1565. (strtolower($this->headers->get('X_FORWARDED_PROTO')) == 'https')
  1566. );
  1567. }
  1568. public function getHost()
  1569. {
  1570. if ($host = $this->headers->get('X_FORWARDED_HOST')) {
  1571. $elements = explode(',', $host);
  1572. $host = trim($elements[count($elements) - 1]);
  1573. } else {
  1574. if (!$host = $this->headers->get('HOST')) {
  1575. if (!$host = $this->server->get('SERVER_NAME')) {
  1576. $host = $this->server->get('SERVER_ADDR', '');
  1577. }
  1578. }
  1579. }
  1580. $host = preg_replace('/:\d+$/', '', $host);
  1581. return trim($host);
  1582. }
  1583. public function setMethod($method)
  1584. {
  1585. $this->method = null;
  1586. $this->server->set('REQUEST_METHOD', $method);
  1587. }
  1588. public function getMethod()
  1589. {
  1590. if (null === $this->method) {
  1591. $this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
  1592. if ('POST' === $this->method) {
  1593. $this->method = strtoupper($this->server->get('X-HTTP-METHOD-OVERRIDE', $this->request->get('_method', 'POST')));
  1594. }
  1595. }
  1596. return $this->method;
  1597. }
  1598. public function getMimeType($format)
  1599. {
  1600. if (null === static::$formats) {
  1601. static::initializeFormats();
  1602. }
  1603. return isset(static::$formats[$format]) ? static::$formats[$format][0] : null;
  1604. }
  1605. public function getFormat($mimeType)
  1606. {
  1607. if (null === static::$formats) {
  1608. static::initializeFormats();
  1609. }
  1610. foreach (static::$formats as $format => $mimeTypes) {
  1611. if (in_array($mimeType, (array) $mimeTypes)) {
  1612. return $format;
  1613. }
  1614. }
  1615. return null;
  1616. }
  1617. public function setFormat($format, $mimeTypes)
  1618. {
  1619. if (null === static::$formats) {
  1620. static::initializeFormats();
  1621. }
  1622. static::$formats[$format] = is_array($mimeTypes) ? $mimeTypes : array($mimeTypes);
  1623. }
  1624. public function getRequestFormat($default = 'html')
  1625. {
  1626. if (null === $this->format) {
  1627. $this->format = $this->get('_format', $default);
  1628. }
  1629. return $this->format;
  1630. }
  1631. public function setRequestFormat($format)
  1632. {
  1633. $this->format = $format;
  1634. }
  1635. public function isMethodSafe()
  1636. {
  1637. return in_array($this->getMethod(), array('GET', 'HEAD'));
  1638. }
  1639. public function getContent($asResource = false)
  1640. {
  1641. if (false === $this->content || (true === $asResource && null !== $this->content)) {
  1642. throw new \LogicException('getContent() can only be called once when using the resource return type.');
  1643. }
  1644. if (true === $asResource) {
  1645. $this->content = false;
  1646. return fopen('php://input', 'rb');
  1647. }
  1648. if (null === $this->content) {
  1649. $this->content = file_get_contents('php://input');
  1650. }
  1651. return $this->content;
  1652. }
  1653. public function getETags()
  1654. {
  1655. return preg_split('/\s*,\s*/', $this->headers->get('if_none_match'), null, PREG_SPLIT_NO_EMPTY);
  1656. }
  1657. public function isNoCache()
  1658. {
  1659. return $this->headers->hasCacheControlDirective('no-cache') || 'no-cache' == $this->headers->get('Pragma');
  1660. }
  1661. public function getPreferredLanguage(array $locales = null)
  1662. {
  1663. $preferredLanguages = $this->getLanguages();
  1664. if (null === $locales) {
  1665. return isset($preferredLanguages[0]) ? $preferredLanguages[0] : null;
  1666. }
  1667. if (!$preferredLanguages) {
  1668. return $locales[0];
  1669. }
  1670. $preferredLanguages = array_values(array_intersect($preferredLanguages, $locales));
  1671. return isset($preferredLanguages[0]) ? $preferredLanguages[0] : $locales[0];
  1672. }
  1673. public function getLanguages()
  1674. {
  1675. if (null !== $this->languages) {
  1676. return $this->languages;
  1677. }
  1678. $languages = $this->splitHttpAcceptHeader($this->headers->get('Accept-Language'));
  1679. $this->languages = array();
  1680. foreach ($languages as $lang => $q) {
  1681. if (strstr($lang, '-')) {
  1682. $codes = explode('-', $lang);
  1683. if ($codes[0] == 'i') {
  1684. if (count($codes) > 1) {
  1685. $lang = $codes[1];
  1686. }
  1687. } else {
  1688. for ($i = 0, $max = count($codes); $i < $max; $i++) {
  1689. if ($i == 0) {
  1690. $lang = strtolower($codes[0]);
  1691. } else {
  1692. $lang .= '_'.strtoupper($codes[$i]);
  1693. }
  1694. }
  1695. }
  1696. }
  1697. $this->languages[] = $lang;
  1698. }
  1699. return $this->languages;
  1700. }
  1701. public function getCharsets()
  1702. {
  1703. if (null !== $this->charsets) {
  1704. return $this->charsets;
  1705. }
  1706. return $this->charsets = array_keys($this->splitHttpAcceptHeader($this->headers->get('Accept-Charset')));
  1707. }
  1708. public function getAcceptableContentTypes()
  1709. {
  1710. if (null !== $this->acceptableContentTypes) {
  1711. return $this->acceptableContentTypes;
  1712. }
  1713. return $this->acceptableContentTypes = array_keys($this->splitHttpAcceptHeader($this->headers->get('Accept')));
  1714. }
  1715. public function isXmlHttpRequest()
  1716. {
  1717. return 'XMLHttpRequest' == $this->headers->get('X-Requested-With');
  1718. }
  1719. public function splitHttpAcceptHeader($header)
  1720. {
  1721. if (!$header) {
  1722. return array();
  1723. }
  1724. $values = array();
  1725. foreach (array_filter(explode(',', $header)) as $value) {
  1726. if ($pos = strpos($value, ';')) {
  1727. $q = (float) trim(substr($value, strpos($value, '=') + 1));
  1728. $value = trim(substr($value, 0, $pos));
  1729. } else {
  1730. $q = 1;
  1731. }
  1732. if (0 < $q) {
  1733. $values[trim($value)] = $q;
  1734. }
  1735. }
  1736. arsort($values);
  1737. reset($values);
  1738. return $values;
  1739. }
  1740. protected function prepareRequestUri()
  1741. {
  1742. $requestUri = '';
  1743. if ($this->headers->has('X_REWRITE_URL')) {
  1744. $requestUri = $this->headers->get('X_REWRITE_URL');
  1745. } elseif ($this->server->get('IIS_WasUrlRewritten') == '1' && $this->server->get('UNENCODED_URL') != '') {
  1746. $requestUri = $this->server->get('UNENCODED_URL');
  1747. } elseif ($this->server->has('REQUEST_URI')) {
  1748. $requestUri = $this->server->get('REQUEST_URI');
  1749. $schemeAndHttpHost = $this->getScheme().'://'.$this->getHttpHost();
  1750. if (strpos($requestUri, $schemeAndHttpHost) === 0) {
  1751. $requestUri = substr($requestUri, strlen($schemeAndHttpHost));
  1752. }
  1753. } elseif ($this->server->has('ORIG_PATH_INFO')) {
  1754. $requestUri = $this->server->get('ORIG_PATH_INFO');
  1755. if ($this->server->get('QUERY_STRING')) {
  1756. $requestUri .= '?'.$this->server->get('QUERY_STRING');
  1757. }
  1758. }
  1759. return $requestUri;
  1760. }
  1761. protected function prepareBaseUrl()
  1762. {
  1763. $filename = basename($this->server->get('SCRIPT_FILENAME'));
  1764. if (basename($this->server->get('SCRIPT_NAME')) === $filename) {
  1765. $baseUrl = $this->server->get('SCRIPT_NAME');
  1766. } elseif (basename($this->server->get('PHP_SELF')) === $filename) {
  1767. $baseUrl = $this->server->get('PHP_SELF');
  1768. } elseif (basename($this->server->get('ORIG_SCRIPT_NAME')) === $filename) {
  1769. $baseUrl = $this->server->get('ORIG_SCRIPT_NAME'); } else {
  1770. $path = $this->server->get('PHP_SELF', '');
  1771. $file = $this->server->get('SCRIPT_FILENAME', '');
  1772. $segs = explode('/', trim($file, '/'));
  1773. $segs = array_reverse($segs);
  1774. $index = 0;
  1775. $last = count($segs);
  1776. $baseUrl = '';
  1777. do {
  1778. $seg = $segs[$index];
  1779. $baseUrl = '/'.$seg.$baseUrl;
  1780. ++$index;
  1781. } while (($last > $index) && (false !== ($pos = strpos($path, $baseUrl))) && (0 != $pos));
  1782. }
  1783. $requestUri = $this->getRequestUri();
  1784. if ($baseUrl && 0 === strpos($requestUri, $baseUrl)) {
  1785. return $baseUrl;
  1786. }
  1787. if ($baseUrl && 0 === strpos($requestUri, dirname($baseUrl))) {
  1788. return rtrim(dirname($baseUrl), '/');
  1789. }
  1790. $truncatedRequestUri = $requestUri;
  1791. if (($pos = strpos($requestUri, '?')) !== false) {
  1792. $truncatedRequestUri = substr($requestUri, 0, $pos);
  1793. }
  1794. $basename = basename($baseUrl);
  1795. if (empty($basename) || !strpos($truncatedRequestUri, $basename)) {
  1796. return '';
  1797. }
  1798. if ((strlen($requestUri) >= strlen($baseUrl)) && ((false !== ($pos = strpos($requestUri, $baseUrl))) && ($pos !== 0))) {
  1799. $baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
  1800. }
  1801. return rtrim($baseUrl, '/');
  1802. }
  1803. protected function prepareBasePath()
  1804. {
  1805. $filename = basename($this->server->get('SCRIPT_FILENAME'));
  1806. $baseUrl = $this->getBaseUrl();
  1807. if (empty($baseUrl)) {
  1808. return '';
  1809. }
  1810. if (basename($baseUrl) === $filename) {
  1811. $basePath = dirname($baseUrl);
  1812. } else {
  1813. $basePath = $baseUrl;
  1814. }
  1815. if ('\\' === DIRECTORY_SEPARATOR) {
  1816. $basePath = str_replace('\\', '/', $basePath);
  1817. }
  1818. return rtrim($basePath, '/');
  1819. }
  1820. protected function preparePathInfo()
  1821. {
  1822. $baseUrl = $this->getBaseUrl();
  1823. if (null === ($requestUri = $this->getRequestUri())) {
  1824. return '/';
  1825. }
  1826. $pathInfo = '/';
  1827. if ($pos = strpos($requestUri, '?')) {
  1828. $requestUri = substr($requestUri, 0, $pos);
  1829. }
  1830. if ((null !== $baseUrl) && (false === ($pathInfo = substr($requestUri, strlen($baseUrl))))) {
  1831. return '/';
  1832. } elseif (null === $baseUrl) {
  1833. return $requestUri;
  1834. }
  1835. return (string) $pathInfo;
  1836. }
  1837. static protected function initializeFormats()
  1838. {
  1839. static::$formats = array(
  1840. 'html' => array('text/html', 'application/xhtml+xml'),
  1841. 'txt' => array('text/plain'),
  1842. 'js' => array('application/javascript', 'application/x-javascript', 'text/javascript'),
  1843. 'css' => array('text/css'),
  1844. 'json' => array('application/json', 'application/x-json'),
  1845. 'xml' => array('text/xml', 'application/xml', 'application/x-xml'),
  1846. 'rdf' => array('application/rdf+xml'),
  1847. 'atom' => array('application/atom+xml'),
  1848. );
  1849. }
  1850. }
  1851. }
  1852. namespace Symfony\Component\HttpFoundation
  1853. {
  1854. class ApacheRequest extends Request
  1855. {
  1856. protected function prepareRequestUri()
  1857. {
  1858. return $this->server->get('REQUEST_URI');
  1859. }
  1860. protected function prepareBaseUrl()
  1861. {
  1862. $baseUrl = $this->server->get('SCRIPT_NAME');
  1863. if (false === strpos($this->server->get('REQUEST_URI'), $baseUrl)) {
  1864. return rtrim(dirname($baseUrl), '/\\');
  1865. }
  1866. return $baseUrl;
  1867. }
  1868. protected function preparePathInfo()
  1869. {
  1870. return $this->server->get('PATH_INFO');
  1871. }
  1872. }
  1873. }
  1874. namespace Symfony\Component\ClassLoader
  1875. {
  1876. class ClassCollectionLoader
  1877. {
  1878. static private $loaded;
  1879. static public function load($classes, $cacheDir, $name, $autoReload, $adaptive = false, $extension = '.php')
  1880. {
  1881. if (isset(self::$loaded[$name])) {
  1882. return;
  1883. }
  1884. self::$loaded[$name] = true;
  1885. $classes = array_unique($classes);
  1886. if ($adaptive) {
  1887. $classes = array_diff($classes, get_declared_classes(), get_declared_interfaces());
  1888. $name = $name.'-'.substr(md5(implode('|', $classes)), 0, 5);
  1889. }
  1890. $cache = $cacheDir.'/'.$name.$extension;
  1891. $reload = false;
  1892. if ($autoReload) {
  1893. $metadata = $cacheDir.'/'.$name.$extension.'.meta';
  1894. if (!file_exists($metadata) || !file_exists($cache)) {
  1895. $reload = true;
  1896. } else {
  1897. $time = filemtime($cache);
  1898. $meta = unserialize(file_get_contents($metadata));
  1899. if ($meta[1] != $classes) {
  1900. $reload = true;
  1901. } else {
  1902. foreach ($meta[0] as $resource) {
  1903. if (!file_exists($resource) || filemtime($resource) > $time) {
  1904. $reload = true;
  1905. break;
  1906. }
  1907. }
  1908. }
  1909. }
  1910. }
  1911. if (!$reload && file_exists($cache)) {
  1912. require_once $cache;
  1913. return;
  1914. }
  1915. $files = array();
  1916. $content = '';
  1917. foreach ($classes as $class) {
  1918. if (!class_exists($class) && !interface_exists($class)) {
  1919. throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
  1920. }
  1921. $r = new \ReflectionClass($class);
  1922. $files[] = $r->getFileName();
  1923. $c = preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', file_get_contents($r->getFileName()));
  1924. if (!$r->inNamespace()) {
  1925. $c = "\nnamespace\n{\n$c\n}\n";
  1926. } else {
  1927. $c = self::fixNamespaceDeclarations('<?php '.$c);
  1928. $c = preg_replace('/^\s*<\?php/', '', $c);
  1929. }
  1930. $content .= $c;
  1931. }
  1932. if (!is_dir(dirname($cache))) {
  1933. mkdir(dirname($cache), 0777, true);
  1934. }
  1935. self::writeCacheFile($cache, self::stripComments('<?php '.$content));
  1936. if ($autoReload) {
  1937. self::writeCacheFile($metadata, serialize(array($files, $classes)));
  1938. }
  1939. }
  1940. static public function fixNamespaceDeclarations($source)
  1941. {
  1942. if (!function_exists('token_get_all')) {
  1943. return $source;
  1944. }
  1945. $output = '';
  1946. $inNamespace = false;
  1947. $tokens = token_get_all($source);
  1948. while ($token = array_shift($tokens)) {
  1949. if (is_string($token)) {
  1950. $output .= $token;
  1951. } elseif (T_NAMESPACE === $token[0]) {
  1952. if ($inNamespace) {
  1953. $output .= "}\n";
  1954. }
  1955. $output .= $token[1];
  1956. while (($t = array_shift($tokens)) && is_array($t) && in_array($t[0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
  1957. $output .= $t[1];
  1958. }
  1959. if (is_string($t) && '{' === $t) {
  1960. $inNamespace = false;
  1961. array_unshift($tokens, $t);
  1962. } else {
  1963. $output .= "\n{";
  1964. $inNamespace = true;
  1965. }
  1966. } else {
  1967. $output .= $token[1];
  1968. }
  1969. }
  1970. if ($inNamespace) {
  1971. $output .= "}\n";
  1972. }
  1973. return $output;
  1974. }
  1975. static private function writeCacheFile($file, $content)
  1976. {
  1977. $tmpFile = tempnam(dirname($file), basename($file));
  1978. if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
  1979. chmod($file, 0644);
  1980. return;
  1981. }
  1982. throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
  1983. }
  1984. static private function stripComments($source)
  1985. {
  1986. if (!function_exists('token_get_all')) {
  1987. return $source;
  1988. }
  1989. $output = '';
  1990. foreach (token_get_all($source) as $token) {
  1991. if (is_string($token)) {
  1992. $output .= $token;
  1993. } elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
  1994. $output .= $token[1];
  1995. }
  1996. }
  1997. $output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
  1998. return $output;
  1999. }
  2000. }
  2001. }
  2002. namespace Symfony\Component\ClassLoader
  2003. {
  2004. class UniversalClassLoader
  2005. {
  2006. private $namespaces = array();
  2007. private $prefixes = array();
  2008. private $namespaceFallbacks = array();
  2009. private $prefixFallbacks = array();
  2010. public function getNamespaces()
  2011. {
  2012. return $this->namespaces;
  2013. }
  2014. public function getPrefixes()
  2015. {
  2016. return $this->prefixes;
  2017. }
  2018. public function getNamespaceFallbacks()
  2019. {
  2020. return $this->namespaceFallbacks;
  2021. }
  2022. public function getPrefixFallbacks()
  2023. {
  2024. return $this->prefixFallbacks;
  2025. }
  2026. public function registerNamespaceFallbacks(array $dirs)
  2027. {
  2028. $this->namespaceFallbacks = $dirs;
  2029. }
  2030. public function registerPrefixFallbacks(array $dirs)
  2031. {
  2032. $this->prefixFallbacks = $dirs;
  2033. }
  2034. public function registerNamespaces(array $namespaces)
  2035. {
  2036. foreach ($namespaces as $namespace => $locations) {
  2037. $this->namespaces[$namespace] = (array) $locations;
  2038. }
  2039. }
  2040. public function registerNamespace($namespace, $paths)
  2041. {
  2042. $this->namespaces[$namespace] = (array) $paths;
  2043. }
  2044. public function registerPrefixes(array $classes)
  2045. {
  2046. foreach ($classes as $prefix => $locations) {
  2047. $this->prefixes[$prefix] = (array) $locations;
  2048. }
  2049. }
  2050. public function registerPrefix($prefix, $paths)
  2051. {
  2052. $this->prefixes[$prefix] = (array) $paths;
  2053. }
  2054. public function register($prepend = false)
  2055. {
  2056. spl_autoload_register(array($this, 'loadClass'), true, $prepend);
  2057. }
  2058. public function loadClass($class)
  2059. {
  2060. if ($file = $this->findFile($class)) {
  2061. require $file;
  2062. }
  2063. }
  2064. public function findFile($class)
  2065. {
  2066. if ('\\' == $class[0]) {
  2067. $class = substr($class, 1);
  2068. }
  2069. if (false !== $pos = strrpos($class, '\\')) {
  2070. $namespace = substr($class, 0, $pos);
  2071. foreach ($this->namespaces as $ns => $dirs) {
  2072. foreach ($dirs as $dir) {
  2073. if (0 === strpos($namespace, $ns)) {
  2074. $className = substr($class, $pos + 1);
  2075. $file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
  2076. if (file_exists($file)) {
  2077. return $file;
  2078. }
  2079. }
  2080. }
  2081. }
  2082. foreach ($this->namespaceFallbacks as $dir) {
  2083. $file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php';
  2084. if (file_exists($file)) {
  2085. return $file;
  2086. }
  2087. }
  2088. } else {
  2089. foreach ($this->prefixes as $prefix => $dirs) {
  2090. foreach ($dirs as $dir) {
  2091. if (0 === strpos($class, $prefix)) {
  2092. $file = $dir.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
  2093. if (file_exists($file)) {
  2094. return $file;
  2095. }
  2096. }
  2097. }
  2098. }
  2099. foreach ($this->prefixFallbacks as $dir) {
  2100. $file = $dir.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
  2101. if (file_exists($file)) {
  2102. return $file;
  2103. }
  2104. }
  2105. }
  2106. }
  2107. }
  2108. }
  2109. namespace Symfony\Component\ClassLoader
  2110. {
  2111. class MapFileClassLoader
  2112. {
  2113. private $map = array();
  2114. public function __construct($file)
  2115. {
  2116. $this->map = require $file;
  2117. }
  2118. public function register($prepend = false)
  2119. {
  2120. spl_autoload_register(array($this, 'loadClass'), true, $prepend);
  2121. }
  2122. public function loadClass($class)
  2123. {
  2124. if ('\\' === $class[0]) {
  2125. $class = substr($class, 1);
  2126. }
  2127. if (isset($this->map[$class])) {
  2128. require $this->map[$class];
  2129. }
  2130. }
  2131. public function findFile($class)
  2132. {
  2133. if ('\\' === $class[0]) {
  2134. $class = substr($class, 1);
  2135. }
  2136. if (isset($this->map[$class])) {
  2137. return $this->map[$class];
  2138. }
  2139. }
  2140. }
  2141. }
  2142. namespace Symfony\Component\Config
  2143. {
  2144. class ConfigCache
  2145. {
  2146. private $debug;
  2147. private $file;
  2148. public function __construct($file, $debug)
  2149. {
  2150. $this->file = $file;
  2151. $this->debug = (Boolean) $debug;
  2152. }
  2153. public function __toString()
  2154. {
  2155. return $this->file;
  2156. }
  2157. public function isFresh()
  2158. {
  2159. if (!file_exists($this->file)) {
  2160. return false;
  2161. }
  2162. if (!$this->debug) {
  2163. return true;
  2164. }
  2165. $metadata = $this->file.'.meta';
  2166. if (!file_exists($metadata)) {
  2167. return false;
  2168. }
  2169. $time = filemtime($this->file);
  2170. $meta = unserialize(file_get_contents($metadata));
  2171. foreach ($meta as $resource) {
  2172. if (!$resource->isFresh($time)) {
  2173. return false;
  2174. }
  2175. }
  2176. return true;
  2177. }
  2178. public function write($content, array $metadata = null)
  2179. {
  2180. $dir = dirname($this->file);
  2181. if (!is_dir($dir)) {
  2182. if (false === @mkdir($dir, 0777, true)) {
  2183. throw new \RuntimeException(sprintf('Unable to create the %s directory', $dir));
  2184. }
  2185. } elseif (!is_writable($dir)) {
  2186. throw new \RuntimeException(sprintf('Unable to write in the %s directory', $dir));
  2187. }
  2188. $tmpFile = tempnam(dirname($this->file), basename($this->file));
  2189. if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $this->file)) {
  2190. chmod($this->file, 0666);
  2191. } else {
  2192. throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $this->file));
  2193. }
  2194. if (null !== $metadata && true === $this->debug) {
  2195. $file = $this->file.'.meta';
  2196. $tmpFile = tempnam(dirname($file), basename($file));
  2197. if (false !== @file_put_contents($tmpFile, serialize($metadata)) && @rename($tmpFile, $file)) {
  2198. chmod($file, 0666);
  2199. }
  2200. }
  2201. }
  2202. }
  2203. }