PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/symfony/src/Symfony/Component/HttpKernel/bootstrap.php

https://github.com/casoetan/ServerGroveLiveChat
PHP | 1944 lines | 1944 code | 0 blank | 0 comment | 195 complexity | 25bb64cfaaa5ed408fc66450df9ab501 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, ISC, BSD-3-Clause

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

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

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