PageRenderTime 75ms CodeModel.GetById 36ms RepoModel.GetById 2ms app.codeStats 0ms

/app/bootstrap.php.cache

https://github.com/le0pard/symf_shop
Unknown | 2066 lines | 2063 code | 3 blank | 0 comment | 0 complexity | e4637f95f3e871d5f9b87fc145eb6c1a MD5 | raw file
Possible License(s): ISC

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\CircularReferenceException;
  28. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  29. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  30. use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
  31. class Container implements ContainerInterface
  32. {
  33. protected $parameterBag;
  34. protected $services;
  35. protected $scopes;
  36. protected $scopeChildren;
  37. protected $scopedServices;
  38. protected $scopeStacks;
  39. protected $loading = array();
  40. public function __construct(ParameterBagInterface $parameterBag = null)
  41. {
  42. $this->parameterBag = null === $parameterBag ? new ParameterBag() : $parameterBag;
  43. $this->services = array();
  44. $this->scopes = array();
  45. $this->scopeChildren = array();
  46. $this->scopedServices = array();
  47. $this->scopeStacks = array();
  48. $this->set('service_container', $this);
  49. }
  50. public function compile()
  51. {
  52. $this->parameterBag->resolve();
  53. $this->parameterBag = new FrozenParameterBag($this->parameterBag->all());
  54. }
  55. public function isFrozen()
  56. {
  57. return $this->parameterBag instanceof FrozenParameterBag;
  58. }
  59. public function getParameterBag()
  60. {
  61. return $this->parameterBag;
  62. }
  63. public function getParameter($name)
  64. {
  65. return $this->parameterBag->get($name);
  66. }
  67. public function hasParameter($name)
  68. {
  69. return $this->parameterBag->has($name);
  70. }
  71. public function setParameter($name, $value)
  72. {
  73. $this->parameterBag->set($name, $value);
  74. }
  75. public function set($id, $service, $scope = self::SCOPE_CONTAINER)
  76. {
  77. if (self::SCOPE_PROTOTYPE === $scope) {
  78. throw new \InvalidArgumentException('You cannot set services of scope "prototype".');
  79. }
  80. $id = strtolower($id);
  81. if (self::SCOPE_CONTAINER !== $scope) {
  82. if (!isset($this->scopedServices[$scope])) {
  83. throw new \RuntimeException('You cannot set services of inactive scopes.');
  84. }
  85. $this->scopedServices[$scope][$id] = $service;
  86. }
  87. $this->services[$id] = $service;
  88. }
  89. public function has($id)
  90. {
  91. $id = strtolower($id);
  92. return isset($this->services[$id]) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service');
  93. }
  94. public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
  95. {
  96. $id = strtolower($id);
  97. if (isset($this->services[$id])) {
  98. return $this->services[$id];
  99. }
  100. if (isset($this->loading[$id])) {
  101. throw new CircularReferenceException($id, array_keys($this->loading));
  102. }
  103. if (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')) {
  104. $this->loading[$id] = true;
  105. try {
  106. $service = $this->$method();
  107. } catch (\Exception $e) {
  108. unset($this->loading[$id]);
  109. throw $e;
  110. }
  111. unset($this->loading[$id]);
  112. return $service;
  113. }
  114. if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
  115. throw new \InvalidArgumentException(sprintf('The service "%s" does not exist.', $id));
  116. }
  117. }
  118. public function getServiceIds()
  119. {
  120. $ids = array();
  121. $r = new \ReflectionClass($this);
  122. foreach ($r->getMethods() as $method) {
  123. if (preg_match('/^get(.+)Service$/', $method->getName(), $match)) {
  124. $ids[] = self::underscore($match[1]);
  125. }
  126. }
  127. return array_merge($ids, array_keys($this->services));
  128. }
  129. public function enterScope($name)
  130. {
  131. if (!isset($this->scopes[$name])) {
  132. throw new \InvalidArgumentException(sprintf('The scope "%s" does not exist.', $name));
  133. }
  134. if (self::SCOPE_CONTAINER !== $this->scopes[$name] && !isset($this->scopedServices[$this->scopes[$name]])) {
  135. throw new \RuntimeException(sprintf('The parent scope "%s" must be active when entering this scope.', $this->scopes[$name]));
  136. }
  137. if (isset($this->scopedServices[$name])) {
  138. $services = array($this->services, $name => $this->scopedServices[$name]);
  139. unset($this->scopedServices[$name]);
  140. foreach ($this->scopeChildren[$name] as $child) {
  141. $services[$child] = $this->scopedServices[$child];
  142. unset($this->scopedServices[$child]);
  143. }
  144. $this->services = call_user_func_array('array_diff_key', $services);
  145. array_shift($services);
  146. if (!isset($this->scopeStacks[$name])) {
  147. $this->scopeStacks[$name] = new \SplStack();
  148. }
  149. $this->scopeStacks[$name]->push($services);
  150. }
  151. $this->scopedServices[$name] = array();
  152. }
  153. public function getCurrentScopedStack($name)
  154. {
  155. if (!isset($this->scopeStacks[$name]) || 0 === $this->scopeStacks[$name]->count()) {
  156. return null;
  157. }
  158. return $this->scopeStacks[$name]->top();
  159. }
  160. public function leaveScope($name)
  161. {
  162. if (!isset($this->scopedServices[$name])) {
  163. throw new \InvalidArgumentException(sprintf('The scope "%s" is not active.', $name));
  164. }
  165. $services = array($this->services, $this->scopedServices[$name]);
  166. unset($this->scopedServices[$name]);
  167. foreach ($this->scopeChildren[$name] as $child) {
  168. if (!isset($this->scopedServices[$child])) {
  169. continue;
  170. }
  171. $services[] = $this->scopedServices[$child];
  172. unset($this->scopedServices[$child]);
  173. }
  174. $this->services = call_user_func_array('array_diff_key', $services);
  175. if (isset($this->scopeStacks[$name]) && count($this->scopeStacks[$name]) > 0) {
  176. $services = $this->scopeStacks[$name]->pop();
  177. $this->scopedServices += $services;
  178. array_unshift($services, $this->services);
  179. $this->services = call_user_func_array('array_merge', $services);
  180. }
  181. }
  182. public function addScope(ScopeInterface $scope)
  183. {
  184. $name = $scope->getName();
  185. $parentScope = $scope->getParentName();
  186. if (self::SCOPE_CONTAINER === $name || self::SCOPE_PROTOTYPE === $name) {
  187. throw new \InvalidArgumentException(sprintf('The scope "%s" is reserved.', $name));
  188. }
  189. if (isset($this->scopes[$name])) {
  190. throw new \InvalidArgumentException(sprintf('A scope with name "%s" already exists.', $name));
  191. }
  192. if (self::SCOPE_CONTAINER !== $parentScope && !isset($this->scopes[$parentScope])) {
  193. throw new \InvalidArgumentException(sprintf('The parent scope "%s" does not exist, or is invalid.', $parentScope));
  194. }
  195. $this->scopes[$name] = $parentScope;
  196. $this->scopeChildren[$name] = array();
  197. while ($parentScope !== self::SCOPE_CONTAINER) {
  198. $this->scopeChildren[$parentScope][] = $name;
  199. $parentScope = $this->scopes[$parentScope];
  200. }
  201. }
  202. public function hasScope($name)
  203. {
  204. return isset($this->scopes[$name]);
  205. }
  206. public function isScopeActive($name)
  207. {
  208. return isset($this->scopedServices[$name]);
  209. }
  210. static public function camelize($id)
  211. {
  212. return preg_replace(array('/(?:^|_)+(.)/e', '/\.(.)/e'), array("strtoupper('\\1')", "'_'.strtoupper('\\1')"), $id);
  213. }
  214. static public function underscore($id)
  215. {
  216. return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($id, '_', '.')));
  217. }
  218. }
  219. }
  220. namespace Symfony\Component\DependencyInjection
  221. {
  222. interface ContainerAwareInterface
  223. {
  224. function setContainer(ContainerInterface $container = null);
  225. }
  226. }
  227. namespace Symfony\Component\DependencyInjection
  228. {
  229. class ContainerAware implements ContainerAwareInterface
  230. {
  231. protected $container;
  232. public function setContainer(ContainerInterface $container = null)
  233. {
  234. $this->container = $container;
  235. }
  236. }
  237. }
  238. namespace Symfony\Component\HttpKernel\Bundle
  239. {
  240. use Symfony\Component\DependencyInjection\ContainerBuilder;
  241. interface BundleInterface
  242. {
  243. function boot();
  244. function shutdown();
  245. function build(ContainerBuilder $container);
  246. function getParent();
  247. function getName();
  248. function getNamespace();
  249. function getPath();
  250. }
  251. }
  252. namespace Symfony\Component\HttpKernel\Bundle
  253. {
  254. use Symfony\Component\DependencyInjection\ContainerAware;
  255. use Symfony\Component\DependencyInjection\ContainerBuilder;
  256. use Symfony\Component\DependencyInjection\Container;
  257. use Symfony\Component\Console\Application;
  258. use Symfony\Component\Finder\Finder;
  259. abstract class Bundle extends ContainerAware implements BundleInterface
  260. {
  261. protected $name;
  262. protected $reflected;
  263. public function boot()
  264. {
  265. }
  266. public function shutdown()
  267. {
  268. }
  269. public function build(ContainerBuilder $container)
  270. {
  271. $class = $this->getNamespace().'\\DependencyInjection\\'.$this->getName().'Extension';
  272. if (class_exists($class)) {
  273. $extension = new $class();
  274. $alias = Container::underscore($this->getName());
  275. if ($alias !== $extension->getAlias()) {
  276. throw new \LogicException(sprintf('The extension alias for the default extension of a bundle must be the underscored version of the bundle name ("%s" vs "%s")', $alias, $extension->getAlias()));
  277. }
  278. $container->registerExtension($extension);
  279. }
  280. }
  281. public function getNamespace()
  282. {
  283. if (null === $this->reflected) {
  284. $this->reflected = new \ReflectionObject($this);
  285. }
  286. return $this->reflected->getNamespaceName();
  287. }
  288. public function getPath()
  289. {
  290. if (null === $this->reflected) {
  291. $this->reflected = new \ReflectionObject($this);
  292. }
  293. return strtr(dirname($this->reflected->getFileName()), '\\', '/');
  294. }
  295. public function getParent()
  296. {
  297. return null;
  298. }
  299. final public function getName()
  300. {
  301. if (null !== $this->name) {
  302. return $this->name;
  303. }
  304. $fqcn = get_class($this);
  305. $name = false === ($pos = strrpos($fqcn, '\\')) ? $fqcn : substr($fqcn, $pos + 1);
  306. if ('Bundle' != substr($name, -6)) {
  307. throw new \RuntimeException(sprintf('The bundle class name "%s" must end with "Bundle" to be valid.', $name));
  308. }
  309. return $this->name = substr($name, 0, -6);
  310. }
  311. public function registerCommands(Application $application)
  312. {
  313. if (!$dir = realpath($this->getPath().'/Command')) {
  314. return;
  315. }
  316. $finder = new Finder();
  317. $finder->files()->name('*Command.php')->in($dir);
  318. $prefix = $this->getNamespace().'\\Command';
  319. foreach ($finder as $file) {
  320. $ns = $prefix;
  321. if ($relativePath = $file->getRelativePath()) {
  322. $ns .= '\\'.strtr($relativePath, '/', '\\');
  323. }
  324. $r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
  325. if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
  326. $application->add($r->newInstance());
  327. }
  328. }
  329. }
  330. }
  331. }
  332. namespace Symfony\Component\HttpKernel\Debug
  333. {
  334. class ErrorHandler
  335. {
  336. private $levels = array(
  337. E_WARNING => 'Warning',
  338. E_NOTICE => 'Notice',
  339. E_USER_ERROR => 'User Error',
  340. E_USER_WARNING => 'User Warning',
  341. E_USER_NOTICE => 'User Notice',
  342. E_STRICT => 'Runtime Notice',
  343. E_RECOVERABLE_ERROR => 'Catchable Fatal Error',
  344. );
  345. private $level;
  346. public function __construct($level = null)
  347. {
  348. $this->level = null === $level ? error_reporting() : $level;
  349. }
  350. public function register()
  351. {
  352. set_error_handler(array($this, 'handle'));
  353. }
  354. public function handle($level, $message, $file, $line, $context)
  355. {
  356. if (0 === $this->level) {
  357. return false;
  358. }
  359. if (error_reporting() & $level && $this->level & $level) {
  360. throw new \ErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line));
  361. }
  362. return false;
  363. }
  364. }
  365. }
  366. namespace Symfony\Component\HttpKernel
  367. {
  368. use Symfony\Component\HttpFoundation\Request;
  369. interface HttpKernelInterface
  370. {
  371. const MASTER_REQUEST = 1;
  372. const SUB_REQUEST = 2;
  373. function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
  374. }
  375. }
  376. namespace Symfony\Component\HttpKernel
  377. {
  378. use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
  379. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  380. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  381. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  382. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  383. use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
  384. use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
  385. use Symfony\Component\HttpFoundation\Request;
  386. use Symfony\Component\HttpFoundation\Response;
  387. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  388. class HttpKernel implements HttpKernelInterface
  389. {
  390. private $dispatcher;
  391. private $resolver;
  392. public function __construct(EventDispatcherInterface $dispatcher, ControllerResolverInterface $resolver)
  393. {
  394. $this->dispatcher = $dispatcher;
  395. $this->resolver = $resolver;
  396. }
  397. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  398. {
  399. try {
  400. return $this->handleRaw($request, $type);
  401. } catch (\Exception $e) {
  402. if (false === $catch) {
  403. throw $e;
  404. }
  405. return $this->handleException($e, $request, $type);
  406. }
  407. }
  408. private function handleRaw(Request $request, $type = self::MASTER_REQUEST)
  409. {
  410. $event = new GetResponseEvent($this, $request, $type);
  411. $this->dispatcher->dispatch(Events::onCoreRequest, $event);
  412. if ($event->hasResponse()) {
  413. return $this->filterResponse($event->getResponse(), $request, $type);
  414. }
  415. if (false === $controller = $this->resolver->getController($request)) {
  416. 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()));
  417. }
  418. $event = new FilterControllerEvent($this, $controller, $request, $type);
  419. $this->dispatcher->dispatch(Events::onCoreController, $event);
  420. $controller = $event->getController();
  421. $arguments = $this->resolver->getArguments($request, $controller);
  422. $response = call_user_func_array($controller, $arguments);
  423. if (!$response instanceof Response) {
  424. $event = new GetResponseForControllerResultEvent($this, $request, $type, $response);
  425. $this->dispatcher->dispatch(Events::onCoreView, $event);
  426. if ($event->hasResponse()) {
  427. $response = $event->getResponse();
  428. }
  429. if (!$response instanceof Response) {
  430. $msg = sprintf('The controller must return a response (%s given).', $this->varToString($response));
  431. if (null === $response) {
  432. $msg .= ' Did you forget to add a return statement somewhere in your controller?';
  433. }
  434. throw new \LogicException($msg);
  435. }
  436. }
  437. return $this->filterResponse($response, $request, $type);
  438. }
  439. private function filterResponse(Response $response, Request $request, $type)
  440. {
  441. $event = new FilterResponseEvent($this, $request, $type, $response);
  442. $this->dispatcher->dispatch(Events::onCoreResponse, $event);
  443. return $event->getResponse();
  444. }
  445. private function handleException(\Exception $e, $request, $type)
  446. {
  447. $event = new GetResponseForExceptionEvent($this, $request, $type, $e);
  448. $this->dispatcher->dispatch(Events::onCoreException, $event);
  449. if (!$event->hasResponse()) {
  450. throw $e;
  451. }
  452. return $this->filterResponse($event->getResponse(), $request, $type);
  453. }
  454. private function varToString($var)
  455. {
  456. if (is_object($var)) {
  457. return sprintf('[object](%s)', get_class($var));
  458. }
  459. if (is_array($var)) {
  460. $a = array();
  461. foreach ($var as $k => $v) {
  462. $a[] = sprintf('%s => %s', $k, $this->varToString($v));
  463. }
  464. return sprintf("[array](%s)", implode(', ', $a));
  465. }
  466. if (is_resource($var)) {
  467. return '[resource]';
  468. }
  469. if (null === $var) {
  470. return 'null';
  471. }
  472. return str_replace("\n", '', var_export((string) $var, true));
  473. }
  474. }
  475. }
  476. namespace Symfony\Component\HttpKernel
  477. {
  478. use Symfony\Component\DependencyInjection\ContainerInterface;
  479. use Symfony\Component\HttpKernel\HttpKernelInterface;
  480. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  481. use Symfony\Component\Config\Loader\LoaderInterface;
  482. interface KernelInterface extends HttpKernelInterface, \Serializable
  483. {
  484. function registerBundles();
  485. function registerContainerConfiguration(LoaderInterface $loader);
  486. function boot();
  487. function shutdown();
  488. function getBundles();
  489. function isClassInActiveBundle($class);
  490. function getBundle($name, $first = true);
  491. function locateResource($name, $dir = null, $first = true);
  492. function getName();
  493. function getEnvironment();
  494. function isDebug();
  495. function getRootDir();
  496. function getContainer();
  497. function getStartTime();
  498. function getCacheDir();
  499. function getLogDir();
  500. }
  501. }
  502. namespace Symfony\Component\HttpKernel
  503. {
  504. use Symfony\Component\DependencyInjection\ContainerInterface;
  505. use Symfony\Component\DependencyInjection\ContainerBuilder;
  506. use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
  507. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  508. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  509. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  510. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  511. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  512. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  513. use Symfony\Component\HttpFoundation\Request;
  514. use Symfony\Component\HttpKernel\HttpKernelInterface;
  515. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  516. use Symfony\Component\HttpKernel\Config\FileLocator;
  517. use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
  518. use Symfony\Component\Config\Loader\LoaderResolver;
  519. use Symfony\Component\Config\Loader\DelegatingLoader;
  520. use Symfony\Component\Config\ConfigCache;
  521. abstract class Kernel implements KernelInterface
  522. {
  523. protected $bundles;
  524. protected $bundleMap;
  525. protected $container;
  526. protected $rootDir;
  527. protected $environment;
  528. protected $debug;
  529. protected $booted;
  530. protected $name;
  531. protected $startTime;
  532. const VERSION = '2.0.0-DEV';
  533. public function __construct($environment, $debug)
  534. {
  535. $this->environment = $environment;
  536. $this->debug = (Boolean) $debug;
  537. $this->booted = false;
  538. $this->rootDir = $this->getRootDir();
  539. $this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
  540. if ($this->debug) {
  541. ini_set('display_errors', 1);
  542. error_reporting(-1);
  543. $this->startTime = microtime(true);
  544. } else {
  545. ini_set('display_errors', 0);
  546. }
  547. }
  548. public function __clone()
  549. {
  550. if ($this->debug) {
  551. $this->startTime = microtime(true);
  552. }
  553. $this->booted = false;
  554. $this->container = null;
  555. }
  556. public function boot()
  557. {
  558. if (true === $this->booted) {
  559. return;
  560. }
  561. $this->initializeBundles();
  562. $this->initializeContainer();
  563. foreach ($this->getBundles() as $bundle) {
  564. $bundle->setContainer($this->container);
  565. $bundle->boot();
  566. }
  567. $this->booted = true;
  568. }
  569. public function shutdown()
  570. {
  571. $this->booted = false;
  572. foreach ($this->getBundles() as $bundle) {
  573. $bundle->shutdown();
  574. $bundle->setContainer(null);
  575. }
  576. $this->container = null;
  577. }
  578. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  579. {
  580. if (false === $this->booted) {
  581. $this->boot();
  582. }
  583. return $this->getHttpKernel()->handle($request, $type, $catch);
  584. }
  585. protected function getHttpKernel()
  586. {
  587. return $this->container->get('http_kernel');
  588. }
  589. public function getBundles()
  590. {
  591. return $this->bundles;
  592. }
  593. public function isClassInActiveBundle($class)
  594. {
  595. foreach ($this->getBundles() as $bundle) {
  596. if (0 === strpos($class, $bundle->getNamespace())) {
  597. return true;
  598. }
  599. }
  600. return false;
  601. }
  602. public function getBundle($name, $first = true)
  603. {
  604. if (!isset($this->bundleMap[$name])) {
  605. 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)));
  606. }
  607. if (true === $first) {
  608. return $this->bundleMap[$name][0];
  609. } elseif (false === $first) {
  610. return $this->bundleMap[$name];
  611. }
  612. }
  613. public function locateResource($name, $dir = null, $first = true)
  614. {
  615. if ('@' !== $name[0]) {
  616. throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
  617. }
  618. if (false !== strpos($name, '..')) {
  619. throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
  620. }
  621. $name = substr($name, 1);
  622. list($bundle, $path) = explode('/', $name, 2);
  623. $isResource = 0 === strpos($path, 'Resources');
  624. $files = array();
  625. if (true === $isResource && null !== $dir && file_exists($file = $dir.'/'.$bundle.'/'.substr($path, 10))) {
  626. if ($first) {
  627. return $file;
  628. }
  629. $files[] = $file;
  630. }
  631. foreach ($this->getBundle($bundle, false) as $bundle) {
  632. if (file_exists($file = $bundle->getPath().'/'.$path)) {
  633. if ($first) {
  634. return $file;
  635. }
  636. $files[] = $file;
  637. }
  638. }
  639. if ($files) {
  640. return $files;
  641. }
  642. throw new \InvalidArgumentException(sprintf('Unable to find file "@%s".', $name));
  643. }
  644. public function getName()
  645. {
  646. return $this->name;
  647. }
  648. public function getEnvironment()
  649. {
  650. return $this->environment;
  651. }
  652. public function isDebug()
  653. {
  654. return $this->debug;
  655. }
  656. public function getRootDir()
  657. {
  658. if (null === $this->rootDir) {
  659. $r = new \ReflectionObject($this);
  660. $this->rootDir = dirname($r->getFileName());
  661. }
  662. return $this->rootDir;
  663. }
  664. public function getContainer()
  665. {
  666. return $this->container;
  667. }
  668. public function getStartTime()
  669. {
  670. return $this->debug ? $this->startTime : -INF;
  671. }
  672. public function getCacheDir()
  673. {
  674. return $this->rootDir.'/cache/'.$this->environment;
  675. }
  676. public function getLogDir()
  677. {
  678. return $this->rootDir.'/logs';
  679. }
  680. protected function initializeBundles()
  681. {
  682. $this->bundles = array();
  683. $topMostBundles = array();
  684. $directChildren = array();
  685. foreach ($this->registerBundles() as $bundle) {
  686. $name = $bundle->getName();
  687. if (isset($this->bundles[$name])) {
  688. throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name));
  689. }
  690. $this->bundles[$name] = $bundle;
  691. if ($parentName = $bundle->getParent()) {
  692. if (isset($directChildren[$parentName])) {
  693. throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
  694. }
  695. $directChildren[$parentName] = $name;
  696. } else {
  697. $topMostBundles[$name] = $bundle;
  698. }
  699. }
  700. if (count($diff = array_values(array_diff(array_keys($directChildren), array_keys($this->bundles))))) {
  701. throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0]));
  702. }
  703. $this->bundleMap = array();
  704. foreach ($topMostBundles as $name => $bundle) {
  705. $bundleMap = array($bundle);
  706. $hierarchy = array($name);
  707. while (isset($directChildren[$name])) {
  708. $name = $directChildren[$name];
  709. array_unshift($bundleMap, $this->bundles[$name]);
  710. $hierarchy[] = $name;
  711. }
  712. foreach ($hierarchy as $bundle) {
  713. $this->bundleMap[$bundle] = $bundleMap;
  714. array_pop($bundleMap);
  715. }
  716. }
  717. }
  718. protected function getContainerClass()
  719. {
  720. return $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
  721. }
  722. protected function initializeContainer()
  723. {
  724. $class = $this->getContainerClass();
  725. $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
  726. $fresh = true;
  727. if (!$cache->isFresh()) {
  728. $container = $this->buildContainer();
  729. $this->dumpContainer($cache, $container, $class);
  730. $fresh = false;
  731. }
  732. require_once $cache;
  733. $this->container = new $class();
  734. $this->container->set('kernel', $this);
  735. if (!$fresh && 'cli' !== php_sapi_name()) {
  736. $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
  737. }
  738. }
  739. protected function getKernelParameters()
  740. {
  741. $bundles = array();
  742. foreach ($this->bundles as $name => $bundle) {
  743. $bundles[$name] = get_class($bundle);
  744. }
  745. return array_merge(
  746. array(
  747. 'kernel.root_dir' => $this->rootDir,
  748. 'kernel.environment' => $this->environment,
  749. 'kernel.debug' => $this->debug,
  750. 'kernel.name' => $this->name,
  751. 'kernel.cache_dir' => $this->getCacheDir(),
  752. 'kernel.logs_dir' => $this->getLogDir(),
  753. 'kernel.bundles' => $bundles,
  754. 'kernel.charset' => 'UTF-8',
  755. 'kernel.container_class' => $this->getContainerClass(),
  756. ),
  757. $this->getEnvParameters()
  758. );
  759. }
  760. protected function getEnvParameters()
  761. {
  762. $parameters = array();
  763. foreach ($_SERVER as $key => $value) {
  764. if ('SYMFONY__' === substr($key, 0, 9)) {
  765. $parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value;
  766. }
  767. }
  768. return $parameters;
  769. }
  770. protected function buildContainer()
  771. {
  772. $parameterBag = new ParameterBag($this->getKernelParameters());
  773. $container = new ContainerBuilder($parameterBag);
  774. $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass());
  775. foreach ($this->bundles as $bundle) {
  776. $bundle->build($container);
  777. if ($this->debug) {
  778. $container->addObjectResource($bundle);
  779. }
  780. }
  781. $container->addObjectResource($this);
  782. if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
  783. $container->merge($cont);
  784. }
  785. foreach (array('cache', 'logs') as $name) {
  786. $dir = $container->getParameter(sprintf('kernel.%s_dir', $name));
  787. if (!is_dir($dir)) {
  788. if (false === @mkdir($dir, 0777, true)) {
  789. exit(sprintf("Unable to create the %s directory (%s)\n", $name, dirname($dir)));
  790. }
  791. } elseif (!is_writable($dir)) {
  792. exit(sprintf("Unable to write in the %s directory (%s)\n", $name, $dir));
  793. }
  794. }
  795. $container->compile();
  796. return $container;
  797. }
  798. protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class)
  799. {
  800. $dumper = new PhpDumper($container);
  801. $content = $dumper->dump(array('class' => $class));
  802. if (!$this->debug) {
  803. $content = self::stripComments($content);
  804. }
  805. $cache->write($content, $container->getResources());
  806. }
  807. protected function getContainerLoader(ContainerInterface $container)
  808. {
  809. $locator = new FileLocator($this);
  810. $resolver = new LoaderResolver(array(
  811. new XmlFileLoader($container, $locator),
  812. new YamlFileLoader($container, $locator),
  813. new IniFileLoader($container, $locator),
  814. new PhpFileLoader($container, $locator),
  815. new ClosureLoader($container, $locator),
  816. ));
  817. return new DelegatingLoader($resolver);
  818. }
  819. static public function stripComments($source)
  820. {
  821. if (!function_exists('token_get_all')) {
  822. return $source;
  823. }
  824. $output = '';
  825. foreach (token_get_all($source) as $token) {
  826. if (is_string($token)) {
  827. $output .= $token;
  828. } elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
  829. $output .= $token[1];
  830. }
  831. }
  832. $output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
  833. return $output;
  834. }
  835. public function serialize()
  836. {
  837. return serialize(array($this->environment, $this->debug));
  838. }
  839. public function unserialize($data)
  840. {
  841. list($environment, $debug) = unserialize($data);
  842. $this->__construct($environment, $debug);
  843. }
  844. }
  845. }
  846. namespace Symfony\Component\HttpFoundation
  847. {
  848. class ParameterBag
  849. {
  850. protected $parameters;
  851. public function __construct(array $parameters = array())
  852. {
  853. $this->parameters = $parameters;
  854. }
  855. public function all()
  856. {
  857. return $this->parameters;
  858. }
  859. public function keys()
  860. {
  861. return array_keys($this->parameters);
  862. }
  863. public function replace(array $parameters = array())
  864. {
  865. $this->parameters = $parameters;
  866. }
  867. public function add(array $parameters = array())
  868. {
  869. $this->parameters = array_replace($this->parameters, $parameters);
  870. }
  871. public function get($key, $default = null)
  872. {
  873. return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
  874. }
  875. public function set($key, $value)
  876. {
  877. $this->parameters[$key] = $value;
  878. }
  879. public function has($key)
  880. {
  881. return array_key_exists($key, $this->parameters);
  882. }
  883. public function remove($key)
  884. {
  885. unset($this->parameters[$key]);
  886. }
  887. public function getAlpha($key, $default = '')
  888. {
  889. return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default));
  890. }
  891. public function getAlnum($key, $default = '')
  892. {
  893. return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default));
  894. }
  895. public function getDigits($key, $default = '')
  896. {
  897. return preg_replace('/[^[:digit:]]/', '', $this->get($key, $default));
  898. }
  899. public function getInt($key, $default = 0)
  900. {
  901. return (int) $this->get($key, $default);
  902. }
  903. }
  904. }
  905. namespace Symfony\Component\HttpFoundation
  906. {
  907. use Symfony\Component\HttpFoundation\File\UploadedFile;
  908. class FileBag extends ParameterBag
  909. {
  910. static private $fileKeys = array('error', 'name', 'size', 'tmp_name', 'type');
  911. public function __construct(array $parameters = array())
  912. {
  913. $this->replace($parameters);
  914. }
  915. public function replace(array $files = array())
  916. {
  917. $this->parameters = array();
  918. $this->add($files);
  919. }
  920. public function set($key, $value)
  921. {
  922. if (is_array($value) || $value instanceof UploadedFile) {
  923. parent::set($key, $this->convertFileInformation($value));
  924. }
  925. }
  926. public function add(array $files = array())
  927. {
  928. foreach ($files as $key => $file) {
  929. $this->set($key, $file);
  930. }
  931. }
  932. protected function convertFileInformation($file)
  933. {
  934. if ($file instanceof UploadedFile) {
  935. return $file;
  936. }
  937. $file = $this->fixPhpFilesArray($file);
  938. if (is_array($file)) {
  939. $keys = array_keys($file);
  940. sort($keys);
  941. if ($keys == self::$fileKeys) {
  942. if (UPLOAD_ERR_NO_FILE == $file['error']) {
  943. $file = null;
  944. } else {
  945. $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']);
  946. }
  947. } else {
  948. $file = array_map(array($this, 'convertFileInformation'), $file);
  949. }
  950. }
  951. return $file;
  952. }
  953. protected function fixPhpFilesArray($data)
  954. {
  955. if (!is_array($data)) {
  956. return $data;
  957. }
  958. $keys = array_keys($data);
  959. sort($keys);
  960. if (self::$fileKeys != $keys || !isset($data['name']) || !is_array($data['name'])) {
  961. return $data;
  962. }
  963. $files = $data;
  964. foreach (self::$fileKeys as $k) {
  965. unset($files[$k]);
  966. }
  967. foreach (array_keys($data['name']) as $key) {
  968. $files[$key] = $this->fixPhpFilesArray(array(
  969. 'error' => $data['error'][$key],
  970. 'name' => $data['name'][$key], 'type' => $data['type'][$key],
  971. 'tmp_name' => $data['tmp_name'][$key],
  972. 'size' => $data['size'][$key]
  973. ));
  974. }
  975. return $files;
  976. }
  977. }
  978. }
  979. namespace Symfony\Component\HttpFoundation
  980. {
  981. class ServerBag extends ParameterBag
  982. {
  983. public function getHeaders()
  984. {
  985. $headers = array();
  986. foreach ($this->parameters as $key => $value) {
  987. if ('HTTP_' === substr($key, 0, 5)) {
  988. $headers[substr($key, 5)] = $value;
  989. }
  990. }
  991. return $headers;
  992. }
  993. }
  994. }
  995. namespace Symfony\Component\HttpFoundation
  996. {
  997. class HeaderBag
  998. {
  999. protected $headers;
  1000. protected $cookies;
  1001. protected $cacheControl;
  1002. public function __construct(array $headers = array())
  1003. {
  1004. $this->cacheControl = array();
  1005. $this->cookies = array();
  1006. $this->headers = array();
  1007. foreach ($headers as $key => $values) {
  1008. $this->set($key, $values);
  1009. }
  1010. }
  1011. public function all()
  1012. {
  1013. return $this->headers;
  1014. }
  1015. public function keys()
  1016. {
  1017. return array_keys($this->headers);
  1018. }
  1019. public function replace(array $headers = array())
  1020. {
  1021. $this->headers = array();
  1022. $this->add($headers);
  1023. }
  1024. public function add(array $headers)
  1025. {
  1026. foreach ($headers as $key => $values) {
  1027. $this->set($key, $values);
  1028. }
  1029. }
  1030. public function get($key, $default = null, $first = true)
  1031. {
  1032. $key = strtr(strtolower($key), '_', '-');
  1033. if (!array_key_exists($key, $this->headers)) {
  1034. if (null === $default) {
  1035. return $first ? null : array();
  1036. }
  1037. return $first ? $default : array($default);
  1038. }
  1039. if ($first) {
  1040. return count($this->headers[$key]) ? $this->headers[$key][0] : $default;
  1041. }
  1042. return $this->headers[$key];
  1043. }
  1044. public function set($key, $values, $replace = true)
  1045. {
  1046. $key = strtr(strtolower($key), '_', '-');
  1047. if (!is_array($values)) {
  1048. $values = array($values);
  1049. }
  1050. if (true === $replace || !isset($this->headers[$key])) {
  1051. $this->headers[$key] = $values;
  1052. } else {
  1053. $this->headers[$key] = array_merge($this->headers[$key], $values);
  1054. }
  1055. if ('cache-control' === $key) {
  1056. $this->cacheControl = $this->parseCacheControl($values[0]);
  1057. }
  1058. }
  1059. public function has($key)
  1060. {
  1061. return array_key_exists(strtr(strtolower($key), '_', '-'), $this->headers);
  1062. }
  1063. public function contains($key, $value)
  1064. {
  1065. return in_array($value, $this->get($key, null, false));
  1066. }
  1067. public function remove($key)
  1068. {
  1069. $key = strtr(strtolower($key), '_', '-');
  1070. unset($this->headers[$key]);
  1071. if ('cache-control' === $key) {
  1072. $this->cacheControl = array();
  1073. }
  1074. }
  1075. public function setCookie(Cookie $cookie)
  1076. {
  1077. $this->cookies[$cookie->getName()] = $cookie;
  1078. }
  1079. public function removeCookie($name)
  1080. {
  1081. unset($this->cookies[$name]);
  1082. }
  1083. public function hasCookie($name)
  1084. {
  1085. return isset($this->cookies[$name]);
  1086. }
  1087. public function getCookie($name)
  1088. {
  1089. if (!$this->hasCookie($name)) {
  1090. throw new \InvalidArgumentException(sprintf('There is no cookie with name "%s".', $name));
  1091. }
  1092. return $this->cookies[$name];
  1093. }
  1094. public function getCookies()
  1095. {
  1096. return $this->cookies;
  1097. }
  1098. public function getDate($key, \DateTime $default = null)
  1099. {
  1100. if (null === $value = $this->get($key)) {
  1101. return $default;
  1102. }
  1103. if (false === $date = \DateTime::createFromFormat(DATE_RFC2822, $value)) {
  1104. throw new \RuntimeException(sprintf('The %s HTTP header is not parseable (%s).', $key, $value));
  1105. }
  1106. return $date;
  1107. }
  1108. public function addCacheControlDirective($key, $value = true)
  1109. {
  1110. $this->cacheControl[$key] = $value;
  1111. $this->set('Cache-Control', $this->getCacheControlHeader());
  1112. }
  1113. public function hasCacheControlDirective($key)
  1114. {
  1115. return array_key_exists($key, $this->cacheControl);
  1116. }
  1117. public function getCacheControlDirective($key)
  1118. {
  1119. return array_key_exists($key, $this->cacheControl) ? $this->cacheControl[$key] : null;
  1120. }
  1121. public function removeCacheControlDirective($key)
  1122. {
  1123. unset($this->cacheControl[$key]);
  1124. $this->set('Cache-Control', $this->getCacheControlHeader());
  1125. }
  1126. protected function getCacheControlHeader()
  1127. {
  1128. $parts = array();
  1129. ksort($this->cacheControl);
  1130. foreach ($this->cacheControl as $key => $value) {
  1131. if (true === $value) {
  1132. $parts[] = $key;
  1133. } else {
  1134. if (preg_match('#[^a-zA-Z0-9._-]#', $value)) {
  1135. $value = '"'.$value.'"';
  1136. }
  1137. $parts[] = "$key=$value";
  1138. }
  1139. }
  1140. return implode(', ', $parts);
  1141. }
  1142. protected function parseCacheControl($header)
  1143. {
  1144. $cacheControl = array();
  1145. preg_match_all('#([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?#', $header, $matches, PREG_SET_ORDER);
  1146. foreach ($matches as $match) {
  1147. $cacheControl[strtolower($match[1])] = isset($match[2]) && $match[2] ? $match[2] : (isset($match[3]) ? $match[3] : true);
  1148. }
  1149. return $cacheControl;
  1150. }
  1151. }
  1152. }
  1153. namespace Symfony\Component\HttpFoundation
  1154. {
  1155. use Symfony\Component\HttpFoundation\SessionStorage\NativeSessionStorage;
  1156. use Symfony\Component\HttpFoundation\File\UploadedFile;
  1157. class Request
  1158. {
  1159. public $attributes;
  1160. public $request;
  1161. public $query;
  1162. public $server;
  1163. public $files;
  1164. public $cookies;
  1165. public $headers;
  1166. protected $content;
  1167. protected $languages;
  1168. protected $charsets;
  1169. protected $acceptableContentTypes;
  1170. protected $pathInfo;
  1171. protected $requestUri;
  1172. protected $baseUrl;
  1173. protected $basePath;
  1174. protected $method;
  1175. protected $format;
  1176. protected $session;
  1177. static protected $formats;
  1178. public function __construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
  1179. {
  1180. $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content);
  1181. }
  1182. public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
  1183. {
  1184. $this->request = new ParameterBag($request);
  1185. $this->query = new ParameterBag($query);
  1186. $this->attributes = new ParameterBag($attributes);
  1187. $this->cookies = new ParameterBag($cookies);
  1188. $this->files = new FileBag($files);
  1189. $this->server = new ServerBag($server);
  1190. $this->headers = new HeaderBag($this->server->getHeaders());
  1191. $this->content = $content;
  1192. $this->languages = null;
  1193. $this->charsets = null;
  1194. $this->acceptableContentTypes = null;
  1195. $this->pathInfo = null;
  1196. $this->requestUri = null;
  1197. $this->baseUrl = null;
  1198. $this->basePath = null;
  1199. $this->method = null;
  1200. $this->format = null;
  1201. }
  1202. static public function createfromGlobals()
  1203. {
  1204. return new static($_GET, $_POST, array(), $_COOKIE, $_FILES, $_SERVER);
  1205. }
  1206. static public function create($uri, $method = 'GET', $parameters = array(), $cookies = array(), $files = array(), $server = array(), $content = null)
  1207. {
  1208. $defaults = array(
  1209. 'SERVER_NAME' => 'localhost',
  1210. 'SERVER_PORT' => 80,
  1211. 'HTTP_HOST' => 'localhost',
  1212. 'HTTP_USER_AGENT' => 'Symfony/2.X',
  1213. 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  1214. 'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
  1215. 'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
  1216. 'REMOTE_ADDR' => '127.0.0.1',
  1217. 'SCRIPT_NAME' => '',
  1218. 'SCRIPT_FILENAME' => '',
  1219. );
  1220. $components = parse_url($uri);
  1221. if (isset($components['host'])) {
  1222. $defaults['SERVER_NAME'] = $components['host'];
  1223. $defaults['HTTP_HOST'] = $components['host'];
  1224. }
  1225. if (isset($components['scheme'])) {
  1226. if ('https' === $components['scheme']) {
  1227. $defaults['HTTPS'] = 'on';
  1228. $defaults['SERVER_PORT'] = 443;
  1229. }
  1230. }
  1231. if (isset($components['port'])) {
  1232. $defaults['SERVER_PORT'] = $components['port'];
  1233. $defaults['HTTP_HOST'] = $defaults['HTTP_HOST'].':'.$components['port'];
  1234. }
  1235. if (in_array(strtoupper($method), array('POST', 'PUT', 'DELETE'))) {
  1236. $request = $parameters;
  1237. $query = array();
  1238. $defaults['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
  1239. } else {
  1240. $request = array();
  1241. $query = $parameters;
  1242. if (false !== $pos = strpos($uri, '?')) {
  1243. $qs = substr($uri, $pos + 1);
  1244. parse_str($qs, $params);
  1245. $query = array_merge($params, $query);
  1246. }
  1247. }
  1248. $queryString = isset($components['query']) ? html_entity_decode($components['query']) : '';
  1249. parse_str($queryString, $qs);
  1250. if (is_array($qs)) {
  1251. $query = array_replace($qs, $query);
  1252. }
  1253. $uri = $components['path'] . ($queryString ? '?'.$queryString : '');
  1254. $server = array_replace($defaults, $server, array(
  1255. 'REQUEST_METHOD' => strtoupper($method),
  1256. 'PATH_INFO' => '',
  1257. 'REQUEST_URI' => $uri,
  1258. 'QUERY_STRING' => $queryString,
  1259. ));
  1260. return new static($query, $request, array(), $cookies, $files, $server, $content);
  1261. }
  1262. public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
  1263. {
  1264. $dup = clone $this;
  1265. if ($query !== null) {
  1266. $dup->query = new ParameterBag($query);
  1267. }
  1268. if ($request !== null) {
  1269. $dup->request = new ParameterBag($request);
  1270. }
  1271. if ($attributes !== null) {
  1272. $dup->attributes = new ParameterBag($attributes);
  1273. }
  1274. if ($cookies !== null) {
  1275. $dup->cookies = new ParameterBag($cookies);
  1276. }
  1277. if ($files !== null) {
  1278. $dup->files = new FileBag($files);
  1279. }
  1280. if ($server !== null) {
  1281. $dup->server = new ServerBag($server);
  1282. $dup->headers = new HeaderBag($dup->server->getHeaders());
  1283. }
  1284. $this->languages = null;
  1285. $this->charsets = null;
  1286. $this->acceptableContentTypes = null;
  1287. $this->pathInfo = null;
  1288. $this->requestUri = null;
  1289. $this->baseUrl = null;
  1290. $this->basePath = null;
  1291. $this->method = null;
  1292. $this->format = null;
  1293. return $dup;
  1294. }
  1295. public function __clone()
  1296. {
  1297. $this->query = clone $this->query;
  1298. $this->request = clone $this->request;
  1299. $this->attributes = clone $this->attributes;
  1300. $this->cookies = clone $this->cookies;
  1301. $this->files = clone $this->files;
  1302. $this->server = clone $this->server;
  1303. $this->headers = clone $this->headers;
  1304. }
  1305. public function overrideGlobals()
  1306. {
  1307. $_GET = $this->query->all();
  1308. $_POST = $this->request->all();
  1309. $_SERVER = $this->server->all();
  1310. $_COOKIE = $this->cookies->all();
  1311. foreach ($this->headers->all() as $key => $value) {
  1312. $_SERVER['HTTP_'.strtoupper(str_replace('-', '_', $key))] = implode(', ', $value);
  1313. }
  1314. $_REQUEST = array_merge($_GET, $_POST);
  1315. }
  1316. public function get($key, $default = null)
  1317. {
  1318. return $this->query->get($key, $this->attributes->get($key, $this->request->get($key, $default)));
  1319. }
  1320. public function getSession()
  1321. {
  1322. return $this->session;
  1323. }
  1324. public function hasSession()
  1325. {
  1326. return $this->cookies->has(session_name());
  1327. }
  1328. public function setSession(Session $session)
  1329. {
  1330. $this->session = $session;
  1331. }
  1332. public function getClientIp($proxy = false)
  1333. {
  1334. if ($proxy) {
  1335. if ($this->server->has('HTTP_CLIENT_IP')) {
  1336. return $this->server->get('HTTP_CLIENT_IP');
  1337. } elseif ($this->server->has('HTTP_X_FORWARDED_FOR')) {
  1338. return $this->server->get('HTTP_X_FORWARDED_FOR');
  1339. }
  1340. }
  1341. return $this->server->get('REMOTE_ADDR');
  1342. }
  1343. public function getScriptName()
  1344. {
  1345. return $this->server->get('SCRIPT_NAME', $this->server->get('ORIG_SCRIPT_NAME', ''));
  1346. }
  1347. public function getPathInfo()
  1348. {
  1349. if (null === $this->pathInfo) {
  1350. $this->pathInfo = $this->preparePathInfo();
  1351. }
  1352. return $this->pathInfo;
  1353. }
  1354. public function getBasePath()
  1355. {
  1356. if (null === $this->basePath) {
  1357. $this->basePath = $this->prepareBasePath();
  1358. }
  1359. return $this->basePath;
  1360. }
  1361. public function getBaseUrl()
  1362. {
  1363. if (null === $this->baseUrl) {
  1364. $this->baseUrl = $this->prepareBaseUrl();
  1365. }
  1366. return $this->baseUrl;
  1367. }
  1368. public function getScheme()
  1369. {
  1370. return ($this->server->get('HTTPS') == 'on') ? 'https' : 'http';
  1371. }
  1372. public function getPort()
  1373. {
  1374. return $this->server->get('SERVER_PORT');
  1375. }
  1376. public function getHttpHost()
  1377. {
  1378. $host = $this->headers->get('HOST');
  1379. if (!empty($host)) {
  1380. return $host;
  1381. }
  1382. $scheme = $this->getScheme();
  1383. $name = $this->server->get('SERVER_NAME');
  1384. $port = $this->getPort();
  1385. if (('http' == $scheme && $port == 80) || ('https' == $scheme && $port == 443)) {
  1386. return $name;
  1387. }
  1388. return $name.':'.$port;
  1389. }
  1390. public function getRequestUri()
  1391. {
  1392. if (null === $this->requestUri) {
  1393. $this->requestUri = $this->prepareRequestUri();

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