PageRenderTime 85ms CodeModel.GetById 43ms RepoModel.GetById 1ms app.codeStats 0ms

/app/bootstrap.php

https://github.com/gzOrg/symfonymeeting
PHP | 2032 lines | 2029 code | 3 blank | 0 comment | 260 complexity | 935cc28ebe31b9640fba9f7b82940f5b MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, LGPL-3.0

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

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

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