PageRenderTime 59ms CodeModel.GetById 21ms RepoModel.GetById 0ms 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

Large files files are truncated, but you can click here to view the full file

  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, '?')) {

Large files files are truncated, but you can click here to view the full file