PageRenderTime 64ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/cart/bootstrap.php

https://github.com/noelg/symfony-demo
PHP | 2035 lines | 2032 code | 3 blank | 0 comment | 261 complexity | 251abecd4aab1d08be22cbd2dd8b341e MD5 | raw file
Possible License(s): ISC, BSD-3-Clause

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, 'controller_value' => $response));
  413. $retval = $this->dispatcher->notifyUntil($event);
  414. if ($event->isProcessed()) {
  415. $response = $retval;
  416. }
  417. }
  418. return $this->filterResponse($response, $request, sprintf('The controller must return a response (%s given).', $this->varToString($response)), $type);
  419. }
  420. protected function filterResponse($response, $request, $message, $type)
  421. {
  422. if (!$response instanceof Response) {
  423. throw new \RuntimeException($message);
  424. }
  425. $response = $this->dispatcher->filter(new Event($this, 'core.response', array('request_type' => $type, 'request' => $request)), $response);
  426. if (!$response instanceof Response) {
  427. throw new \RuntimeException('A "core.response" listener returned a non response object.');
  428. }
  429. return $response;
  430. }
  431. protected function varToString($var)
  432. {
  433. if (is_object($var)) {
  434. return sprintf('[object](%s)', get_class($var));
  435. }
  436. if (is_array($var)) {
  437. $a = array();
  438. foreach ($var as $k => $v) {
  439. $a[] = sprintf('%s => %s', $k, $this->varToString($v));
  440. }
  441. return sprintf("[array](%s)", implode(', ', $a));
  442. }
  443. if (is_resource($var)) {
  444. return '[resource]';
  445. }
  446. return str_replace("\n", '', var_export((string) $var, true));
  447. }
  448. }
  449. }
  450. namespace Symfony\Component\HttpKernel
  451. {
  452. use Symfony\Component\DependencyInjection\ContainerInterface;
  453. use Symfony\Component\HttpKernel\HttpKernelInterface;
  454. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  455. use Symfony\Component\Config\Loader\LoaderInterface;
  456. interface KernelInterface extends HttpKernelInterface, \Serializable
  457. {
  458. function registerRootDir();
  459. function registerBundles();
  460. function registerContainerConfiguration(LoaderInterface $loader);
  461. function boot();
  462. function shutdown();
  463. function getBundles();
  464. function isClassInActiveBundle($class);
  465. function getBundle($name, $first = true);
  466. function locateResource($name, $dir = null, $first = true);
  467. function getName();
  468. function getEnvironment();
  469. function isDebug();
  470. function getRootDir();
  471. function getContainer();
  472. function getStartTime();
  473. function getCacheDir();
  474. function getLogDir();
  475. }
  476. }
  477. namespace Symfony\Component\HttpKernel
  478. {
  479. use Symfony\Component\DependencyInjection\ContainerInterface;
  480. use Symfony\Component\DependencyInjection\ContainerBuilder;
  481. use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
  482. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  483. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  484. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  485. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  486. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  487. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  488. use Symfony\Component\HttpFoundation\Request;
  489. use Symfony\Component\HttpKernel\HttpKernelInterface;
  490. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  491. use Symfony\Component\HttpKernel\Config\FileLocator;
  492. use Symfony\Component\Config\Loader\LoaderResolver;
  493. use Symfony\Component\Config\Loader\DelegatingLoader;
  494. use Symfony\Component\Config\ConfigCache;
  495. abstract class Kernel implements KernelInterface
  496. {
  497. protected $bundles;
  498. protected $bundleMap;
  499. protected $container;
  500. protected $rootDir;
  501. protected $environment;
  502. protected $debug;
  503. protected $booted;
  504. protected $name;
  505. protected $startTime;
  506. const VERSION = '2.0.0-DEV';
  507. public function __construct($environment, $debug)
  508. {
  509. $this->environment = $environment;
  510. $this->debug = (Boolean) $debug;
  511. $this->booted = false;
  512. $this->rootDir = realpath($this->registerRootDir());
  513. $this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
  514. if ($this->debug) {
  515. ini_set('display_errors', 1);
  516. error_reporting(-1);
  517. $this->startTime = microtime(true);
  518. } else {
  519. ini_set('display_errors', 0);
  520. }
  521. }
  522. public function __clone()
  523. {
  524. if ($this->debug) {
  525. $this->startTime = microtime(true);
  526. }
  527. $this->booted = false;
  528. $this->container = null;
  529. }
  530. public function boot()
  531. {
  532. if (true === $this->booted) {
  533. return;
  534. }
  535. $this->initializeBundles();
  536. $this->initializeContainer();
  537. foreach ($this->getBundles() as $bundle) {
  538. $bundle->setContainer($this->container);
  539. $bundle->boot();
  540. }
  541. $this->booted = true;
  542. }
  543. public function shutdown()
  544. {
  545. $this->booted = false;
  546. foreach ($this->getBundles() as $bundle) {
  547. $bundle->shutdown();
  548. $bundle->setContainer(null);
  549. }
  550. $this->container = null;
  551. }
  552. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  553. {
  554. if (false === $this->booted) {
  555. $this->boot();
  556. }
  557. return $this->getHttpKernel()->handle($request, $type, $catch);
  558. }
  559. protected function getHttpKernel()
  560. {
  561. return $this->container->get('http_kernel');
  562. }
  563. public function getBundles()
  564. {
  565. return $this->bundles;
  566. }
  567. public function isClassInActiveBundle($class)
  568. {
  569. foreach ($this->getBundles() as $bundle) {
  570. if (0 === strpos($class, $bundle->getNamespace())) {
  571. return true;
  572. }
  573. }
  574. return false;
  575. }
  576. public function getBundle($name, $first = true)
  577. {
  578. if (!isset($this->bundleMap[$name])) {
  579. 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)));
  580. }
  581. if (true === $first) {
  582. return $this->bundleMap[$name][0];
  583. } elseif (false === $first) {
  584. return $this->bundleMap[$name];
  585. }
  586. }
  587. public function locateResource($name, $dir = null, $first = true)
  588. {
  589. if ('@' !== $name[0]) {
  590. throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
  591. }
  592. if (false !== strpos($name, '..')) {
  593. throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
  594. }
  595. $name = substr($name, 1);
  596. list($bundle, $path) = explode('/', $name, 2);
  597. $isResource = 0 === strpos($path, 'Resources');
  598. $files = array();
  599. if (true === $isResource && null !== $dir && file_exists($file = $dir.'/'.$bundle.'/'.substr($path, 10))) {
  600. if ($first) {
  601. return $file;
  602. }
  603. $files[] = $file;
  604. }
  605. foreach ($this->getBundle($bundle, false) as $bundle) {
  606. if (file_exists($file = $bundle->getPath().'/'.$path)) {
  607. if ($first) {
  608. return $file;
  609. }
  610. $files[] = $file;
  611. }
  612. }
  613. if ($files) {
  614. return $files;
  615. }
  616. throw new \InvalidArgumentException(sprintf('Unable to find file "@%s".', $name));
  617. }
  618. public function getName()
  619. {
  620. return $this->name;
  621. }
  622. public function getEnvironment()
  623. {
  624. return $this->environment;
  625. }
  626. public function isDebug()
  627. {
  628. return $this->debug;
  629. }
  630. public function getRootDir()
  631. {
  632. return $this->rootDir;
  633. }
  634. public function getContainer()
  635. {
  636. return $this->container;
  637. }
  638. public function getStartTime()
  639. {
  640. return $this->debug ? $this->startTime : -INF;
  641. }
  642. public function getCacheDir()
  643. {
  644. return $this->rootDir.'/cache/'.$this->environment;
  645. }
  646. public function getLogDir()
  647. {
  648. return $this->rootDir.'/logs';
  649. }
  650. protected function initializeBundles()
  651. {
  652. $this->bundles = array();
  653. $topMostBundles = array();
  654. $directChildren = array();
  655. foreach ($this->registerBundles() as $bundle) {
  656. $name = $bundle->getName();
  657. if (isset($this->bundles[$name])) {
  658. throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name));
  659. }
  660. $this->bundles[$name] = $bundle;
  661. if ($parentName = $bundle->getParent()) {
  662. if (isset($directChildren[$parentName])) {
  663. throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
  664. }
  665. $directChildren[$parentName] = $name;
  666. } else {
  667. $topMostBundles[$name] = $bundle;
  668. }
  669. }
  670. if (count($diff = array_values(array_diff(array_keys($directChildren), array_keys($this->bundles))))) {
  671. throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0]));
  672. }
  673. $this->bundleMap = array();
  674. foreach ($topMostBundles as $name => $bundle) {
  675. $bundleMap = array($bundle);
  676. $hierarchy = array($name);
  677. while (isset($directChildren[$name])) {
  678. $name = $directChildren[$name];
  679. array_unshift($bundleMap, $this->bundles[$name]);
  680. $hierarchy[] = $name;
  681. }
  682. foreach ($hierarchy as $bundle) {
  683. $this->bundleMap[$bundle] = $bundleMap;
  684. array_pop($bundleMap);
  685. }
  686. }
  687. }
  688. protected function initializeContainer()
  689. {
  690. $class = $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
  691. $cache = new ConfigCache($this->getCacheDir(), $class, $this->debug);
  692. $fresh = false;
  693. if (!$cache->isFresh()) {
  694. $container = $this->buildContainer();
  695. $this->dumpContainer($cache, $container, $class);
  696. $fresh = true;
  697. }
  698. require_once $cache;
  699. $this->container = new $class();
  700. $this->container->set('kernel', $this);
  701. if ($fresh && 'cli' !== php_sapi_name()) {
  702. $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
  703. }
  704. }
  705. protected function getKernelParameters()
  706. {
  707. $bundles = array();
  708. foreach ($this->bundles as $name => $bundle) {
  709. $bundles[$name] = get_class($bundle);
  710. }
  711. return array_merge(
  712. array(
  713. 'kernel.root_dir' => $this->rootDir,
  714. 'kernel.environment' => $this->environment,
  715. 'kernel.debug' => $this->debug,
  716. 'kernel.name' => $this->name,
  717. 'kernel.cache_dir' => $this->getCacheDir(),
  718. 'kernel.logs_dir' => $this->getLogDir(),
  719. 'kernel.bundles' => $bundles,
  720. 'kernel.charset' => 'UTF-8',
  721. ),
  722. $this->getEnvParameters()
  723. );
  724. }
  725. protected function getEnvParameters()
  726. {
  727. $parameters = array();
  728. foreach ($_SERVER as $key => $value) {
  729. if ('SYMFONY__' === substr($key, 0, 9)) {
  730. $parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value;
  731. }
  732. }
  733. return $parameters;
  734. }
  735. protected function buildContainer()
  736. {
  737. $parameterBag = new ParameterBag($this->getKernelParameters());
  738. $container = new ContainerBuilder($parameterBag);
  739. foreach ($this->bundles as $bundle) {
  740. $bundle->build($container);
  741. if ($this->debug) {
  742. $container->addObjectResource($bundle);
  743. }
  744. }
  745. $container->addObjectResource($this);
  746. if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
  747. $container->merge($cont);
  748. }
  749. $container->compile();
  750. return $container;
  751. }
  752. protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class)
  753. {
  754. foreach (array('cache', 'logs') as $name) {
  755. $dir = $container->getParameter(sprintf('kernel.%s_dir', $name));
  756. if (!is_dir($dir)) {
  757. if (false === @mkdir($dir, 0777, true)) {
  758. die(sprintf("Unable to create the %s directory (%s)\n", $name, dirname($dir)));
  759. }
  760. } elseif (!is_writable($dir)) {
  761. die(sprintf("Unable to write in the %s directory (%s)\n", $name, $dir));
  762. }
  763. }
  764. $dumper = new PhpDumper($container);
  765. $content = $dumper->dump(array('class' => $class));
  766. if (!$this->debug) {
  767. $content = self::stripComments($content);
  768. }
  769. $cache->write($content, $container->getResources());
  770. }
  771. protected function getContainerLoader(ContainerInterface $container)
  772. {
  773. $resolver = new LoaderResolver(array(
  774. new XmlFileLoader($container, new FileLocator($this)),
  775. new YamlFileLoader($container, new FileLocator($this)),
  776. new IniFileLoader($container, new FileLocator($this)),
  777. new PhpFileLoader($container, new FileLocator($this)),
  778. new ClosureLoader($container, new FileLocator($this)),
  779. ));
  780. return new DelegatingLoader($resolver);
  781. }
  782. static public function stripComments($source)
  783. {
  784. if (!function_exists('token_get_all')) {
  785. return $source;
  786. }
  787. $output = '';
  788. foreach (token_get_all($source) as $token) {
  789. if (is_string($token)) {
  790. $output .= $token;
  791. } elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
  792. $output .= $token[1];
  793. }
  794. }
  795. $output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
  796. return $output;
  797. }
  798. public function serialize()
  799. {
  800. return serialize(array($this->environment, $this->debug));
  801. }
  802. public function unserialize($data)
  803. {
  804. list($environment, $debug) = unserialize($data);
  805. $this->__construct($environment, $debug);
  806. }
  807. }
  808. }
  809. namespace Symfony\Component\HttpFoundation
  810. {
  811. class ParameterBag
  812. {
  813. protected $parameters;
  814. public function __construct(array $parameters = array())
  815. {
  816. $this->parameters = $parameters;
  817. }
  818. public function all()
  819. {
  820. return $this->parameters;
  821. }
  822. public function keys()
  823. {
  824. return array_keys($this->parameters);
  825. }
  826. public function replace(array $parameters = array())
  827. {
  828. $this->parameters = $parameters;
  829. }
  830. public function add(array $parameters = array())
  831. {
  832. $this->parameters = array_replace($this->parameters, $parameters);
  833. }
  834. public function get($key, $default = null)
  835. {
  836. return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
  837. }
  838. public function set($key, $value)
  839. {
  840. $this->parameters[$key] = $value;
  841. }
  842. public function has($key)
  843. {
  844. return array_key_exists($key, $this->parameters);
  845. }
  846. public function remove($key)
  847. {
  848. unset($this->parameters[$key]);
  849. }
  850. public function getAlpha($key, $default = '')
  851. {
  852. return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default));
  853. }
  854. public function getAlnum($key, $default = '')
  855. {
  856. return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default));
  857. }
  858. public function getDigits($key, $default = '')
  859. {
  860. return preg_replace('/[^[:digit:]]/', '', $this->get($key, $default));
  861. }
  862. public function getInt($key, $default = 0)
  863. {
  864. return (int) $this->get($key, $default);
  865. }
  866. }
  867. }
  868. namespace Symfony\Component\HttpFoundation
  869. {
  870. use Symfony\Component\HttpFoundation\File\UploadedFile;
  871. class FileBag extends ParameterBag
  872. {
  873. private $fileKeys = array('error', 'name', 'size', 'tmp_name', 'type');
  874. public function __construct(array $parameters = array())
  875. {
  876. $this->replace($parameters);
  877. }
  878. public function replace(array $files = array())
  879. {
  880. $this->parameters = array();
  881. $this->add($files);
  882. }
  883. public function set($key, $value)
  884. {
  885. if (is_array($value) || $value instanceof UploadedFile) {
  886. parent::set($key, $this->convertFileInformation($value));
  887. }
  888. }
  889. public function add(array $files = array())
  890. {
  891. foreach ($files as $key => $file) {
  892. $this->set($key, $file);
  893. }
  894. }
  895. protected function convertFileInformation($file)
  896. {
  897. if ($file instanceof UploadedFile) {
  898. return $file;
  899. }
  900. $file = $this->fixPhpFilesArray($file);
  901. if (is_array($file)) {
  902. $keys = array_keys($file);
  903. sort($keys);
  904. if ($keys == $this->fileKeys) {
  905. $file['error'] = (int) $file['error'];
  906. }
  907. if ($keys != $this->fileKeys) {
  908. $file = array_map(array($this, 'convertFileInformation'), $file);
  909. } else
  910. if ($file['error'] === UPLOAD_ERR_NO_FILE) {
  911. $file = null;
  912. } else {
  913. $file = new UploadedFile($file['tmp_name'], $file['name'],
  914. $file['type'], $file['size'], $file['error']);
  915. }
  916. }
  917. return $file;
  918. }
  919. protected function fixPhpFilesArray($data)
  920. {
  921. if (! is_array($data)) {
  922. return $data;
  923. }
  924. $keys = array_keys($data);
  925. sort($keys);
  926. if ($this->fileKeys != $keys || ! isset($data['name']) ||
  927. ! is_array($data['name'])) {
  928. return $data;
  929. }
  930. $files = $data;
  931. foreach ($this->fileKeys as $k) {
  932. unset($files[$k]);
  933. }
  934. foreach (array_keys($data['name']) as $key) {
  935. $files[$key] = $this->fixPhpFilesArray(array(
  936. 'error' => $data['error'][$key],
  937. 'name' => $data['name'][$key], 'type' => $data['type'][$key],
  938. 'tmp_name' => $data['tmp_name'][$key],
  939. 'size' => $data['size'][$key]
  940. ));
  941. }
  942. return $files;
  943. }
  944. }
  945. }
  946. namespace Symfony\Component\HttpFoundation
  947. {
  948. class ServerBag extends ParameterBag
  949. {
  950. public function getHeaders()
  951. {
  952. $headers = array();
  953. foreach ($this->parameters as $key => $value) {
  954. if ('HTTP_' === substr($key, 0, 5)) {
  955. $headers[substr($key, 5)] = $value;
  956. }
  957. }
  958. return $headers;
  959. }
  960. }
  961. }
  962. namespace Symfony\Component\HttpFoundation
  963. {
  964. class HeaderBag
  965. {
  966. protected $headers;
  967. protected $cookies;
  968. protected $cacheControl;
  969. public function __construct(array $headers = array())
  970. {
  971. $this->cacheControl = array();
  972. $this->cookies = array();
  973. $this->headers = array();
  974. foreach ($headers as $key => $values) {
  975. $this->set($key, $values);
  976. }
  977. }
  978. public function all()
  979. {
  980. return $this->headers;
  981. }
  982. public function keys()
  983. {
  984. return array_keys($this->headers);
  985. }
  986. public function replace(array $headers = array())
  987. {
  988. $this->headers = array();
  989. $this->add($headers);
  990. }
  991. public function add(array $headers)
  992. {
  993. foreach ($headers as $key => $values) {
  994. $this->set($key, $values);
  995. }
  996. }
  997. public function get($key, $default = null, $first = true)
  998. {
  999. $key = strtr(strtolower($key), '_', '-');
  1000. if (!array_key_exists($key, $this->headers)) {
  1001. if (null === $default) {
  1002. return $first ? null : array();
  1003. } else {
  1004. return $first ? $default : array($default);
  1005. }
  1006. }
  1007. if ($first) {
  1008. return count($this->headers[$key]) ? $this->headers[$key][0] : $default;
  1009. } else {
  1010. return $this->headers[$key];
  1011. }
  1012. }
  1013. public function set($key, $values, $replace = true)
  1014. {
  1015. $key = strtr(strtolower($key), '_', '-');
  1016. if (!is_array($values)) {
  1017. $values = array($values);
  1018. }
  1019. if (true === $replace || !isset($this->headers[$key])) {
  1020. $this->headers[$key] = $values;
  1021. } else {
  1022. $this->headers[$key] = array_merge($this->headers[$key], $values);
  1023. }
  1024. if ('cache-control' === $key) {
  1025. $this->cacheControl = $this->parseCacheControl($values[0]);
  1026. }
  1027. }
  1028. public function has($key)
  1029. {
  1030. return array_key_exists(strtr(strtolower($key), '_', '-'), $this->headers);
  1031. }
  1032. public function contains($key, $value)
  1033. {
  1034. return in_array($value, $this->get($key, null, false));
  1035. }
  1036. public function remove($key)
  1037. {
  1038. $key = strtr(strtolower($key), '_', '-');
  1039. unset($this->headers[$key]);
  1040. if ('cache-control' === $key) {
  1041. $this->cacheControl = array();
  1042. }
  1043. }
  1044. public function setCookie(Cookie $cookie)
  1045. {
  1046. $this->cookies[$cookie->getName()] = $cookie;
  1047. }
  1048. public function removeCookie($name)
  1049. {
  1050. unset($this->cookies[$name]);
  1051. }
  1052. public function hasCookie($name)
  1053. {
  1054. return isset($this->cookies[$name]);
  1055. }
  1056. public function getCookie($name)
  1057. {
  1058. if (!$this->hasCookie($name)) {
  1059. throw new \InvalidArgumentException(sprintf('There is no cookie with name "%s".', $name));
  1060. }
  1061. return $this->cookies[$name];
  1062. }
  1063. public function getCookies()
  1064. {
  1065. return $this->cookies;
  1066. }
  1067. public function getDate($key, \DateTime $default = null)
  1068. {
  1069. if (null === $value = $this->get($key)) {
  1070. return $default;
  1071. }
  1072. if (false === $date = \DateTime::createFromFormat(DATE_RFC2822, $value)) {
  1073. throw new \RuntimeException(sprintf('The %s HTTP header is not parseable (%s).', $key, $value));
  1074. }
  1075. return $date;
  1076. }
  1077. public function addCacheControlDirective($key, $value = true)
  1078. {
  1079. $this->cacheControl[$key] = $value;
  1080. $this->set('Cache-Control', $this->getCacheControlHeader());
  1081. }
  1082. public function hasCacheControlDirective($key)
  1083. {
  1084. return array_key_exists($key, $this->cacheControl);
  1085. }
  1086. public function getCacheControlDirective($key)
  1087. {
  1088. return array_key_exists($key, $this->cacheControl) ? $this->cacheControl[$key] : null;
  1089. }
  1090. public function removeCacheControlDirective($key)
  1091. {
  1092. unset($this->cacheControl[$key]);
  1093. $this->set('Cache-Control', $this->getCacheControlHeader());
  1094. }
  1095. protected function getCacheControlHeader()
  1096. {
  1097. $parts = array();
  1098. ksort($this->cacheControl);
  1099. foreach ($this->cacheControl as $key => $value) {
  1100. if (true === $value) {
  1101. $parts[] = $key;
  1102. } else {
  1103. if (preg_match('#[^a-zA-Z0-9._-]#', $value)) {
  1104. $value = '"'.$value.'"';
  1105. }
  1106. $parts[] = "$key=$value";
  1107. }
  1108. }
  1109. return implode(', ', $parts);
  1110. }
  1111. protected function parseCacheControl($header)
  1112. {
  1113. $cacheControl = array();
  1114. preg_match_all('#([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?#', $header, $matches, PREG_SET_ORDER);
  1115. foreach ($matches as $match) {
  1116. $cacheControl[strtolower($match[1])] = isset($match[2]) && $match[2] ? $match[2] : (isset($match[3]) ? $match[3] : true);
  1117. }
  1118. return $cacheControl;
  1119. }
  1120. }
  1121. }
  1122. namespace Symfony\Component\HttpFoundation
  1123. {
  1124. use Symfony\Component\HttpFoundation\SessionStorage\NativeSessionStorage;
  1125. use Symfony\Component\HttpFoundation\File\UploadedFile;
  1126. class Request
  1127. {
  1128. public $attributes;
  1129. public $request;
  1130. public $query;
  1131. public $server;
  1132. public $files;
  1133. public $cookies;
  1134. public $headers;
  1135. protected $content;
  1136. protected $languages;
  1137. protected $charsets;
  1138. protected $acceptableContentTypes;
  1139. protected $pathInfo;
  1140. protected $requestUri;
  1141. protected $baseUrl;
  1142. protected $basePath;
  1143. protected $method;
  1144. protected $format;
  1145. protected $session;
  1146. static protected $formats;
  1147. public function __construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
  1148. {
  1149. $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content);
  1150. }
  1151. public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
  1152. {
  1153. $this->request = new ParameterBag($request);
  1154. $this->query = new ParameterBag($query);
  1155. $this->attributes = new ParameterBag($attributes);
  1156. $this->cookies = new ParameterBag($cookies);
  1157. $this->files = new FileBag($files);
  1158. $this->server = new ServerBag($server);
  1159. $this->headers = new HeaderBag($this->server->getHeaders());
  1160. $this->content = $content;
  1161. $this->languages = null;
  1162. $this->charsets = null;
  1163. $this->acceptableContentTypes = null;
  1164. $this->pathInfo = null;
  1165. $this->requestUri = null;
  1166. $this->baseUrl = null;
  1167. $this->basePath = null;
  1168. $this->method = null;
  1169. $this->format = null;
  1170. }
  1171. static public function createfromGlobals()
  1172. {
  1173. return new static($_GET, $_POST, array(), $_COOKIE, $_FILES, $_SERVER);
  1174. }
  1175. static public function create($uri, $method = 'GET', $parameters = array(), $cookies = array(), $files = array(), $server = array(), $content = null)
  1176. {
  1177. $defaults = array(
  1178. 'SERVER_NAME' => 'localhost',
  1179. 'SERVER_PORT' => 80,
  1180. 'HTTP_HOST' => 'localhost',
  1181. 'HTTP_USER_AGENT' => 'Symfony/2.X',
  1182. 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  1183. 'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
  1184. 'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
  1185. 'REMOTE_ADDR' => '127.0.0.1',
  1186. 'SCRIPT_NAME' => '',
  1187. 'SCRIPT_FILENAME' => '',
  1188. );
  1189. $components = parse_url($uri);
  1190. if (isset($components['host'])) {
  1191. $defaults['SERVER_NAME'] = $components['host'];
  1192. $defaults['HTTP_HOST'] = $components['host'];
  1193. }
  1194. if (isset($components['scheme'])) {
  1195. if ('https' === $components['scheme']) {
  1196. $defaults['HTTPS'] = 'on';
  1197. $defaults['SERVER_PORT'] = 443;
  1198. }
  1199. }
  1200. if (isset($components['port'])) {
  1201. $defaults['SERVER_PORT'] = $components['port'];
  1202. $defaults['HTTP_HOST'] = $defaults['HTTP_HOST'].':'.$components['port'];
  1203. }
  1204. if (in_array(strtoupper($method), array('POST', 'PUT', 'DELETE'))) {
  1205. $request = $parameters;
  1206. $query = array();
  1207. $defaults['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
  1208. } else {
  1209. $request = array();
  1210. $query = $parameters;
  1211. if (false !== $pos = strpos($uri, '?')) {
  1212. $qs = substr($uri, $pos + 1);
  1213. parse_str($qs, $params);
  1214. $query = array_merge($params, $query);
  1215. }
  1216. }
  1217. $queryString = isset($components['query']) ? html_entity_decode($components['query']) : '';
  1218. parse_str($queryString, $qs);
  1219. if (is_array($qs)) {
  1220. $query = array_replace($qs, $query);
  1221. }
  1222. $uri = $components['path'] . ($queryString ? '?'.$queryString : '');
  1223. $server = array_replace($defaults, $server, array(
  1224. 'REQUEST_METHOD' => strtoupper($method),
  1225. 'PATH_INFO' => '',
  1226. 'REQUEST_URI' => $uri,
  1227. 'QUERY_STRING' => $queryString,
  1228. ));
  1229. return new static($query, $request, array(), $cookies, $files, $server, $content);
  1230. }
  1231. public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
  1232. {
  1233. $dup = clone $this;
  1234. if ($query !== null) {
  1235. $dup->query = new ParameterBag($query);
  1236. }
  1237. if ($request !== null) {
  1238. $dup->request = new ParameterBag($request);
  1239. }
  1240. if ($attributes !== null) {
  1241. $dup->attributes = new ParameterBag($attributes);
  1242. }
  1243. if ($cookies !== null) {
  1244. $dup->cookies = new ParameterBag($cookies);
  1245. }
  1246. if ($files !== null) {
  1247. $dup->files = new FileBag($files);
  1248. }
  1249. if ($server !== null) {
  1250. $dup->server = new ServerBag($server);
  1251. $dup->headers = new HeaderBag($dup->server->getHeaders());
  1252. }
  1253. $this->languages = null;
  1254. $this->charsets = null;
  1255. $this->acceptableContentTypes = null;
  1256. $this->pathInfo = null;
  1257. $this->requestUri = null;
  1258. $this->baseUrl = null;
  1259. $this->basePath = null;
  1260. $this->method = null;
  1261. $this->format = null;
  1262. return $dup;
  1263. }
  1264. public function __clone()
  1265. {
  1266. $this->query = clone $this->query;
  1267. $this->request = clone $this->request;
  1268. $this->attributes = clone $this->attributes;
  1269. $this->cookies = clone $this->cookies;
  1270. $this->files = clone $this->files;
  1271. $this->server = clone $this->server;
  1272. $this->headers = clone $this->headers;
  1273. }
  1274. public function overrideGlobals()
  1275. {
  1276. $_GET = $this->query->all();
  1277. $_POST = $this->request->all();
  1278. $_SERVER = $this->server->all();
  1279. $_COOKIE = $this->cookies->all();
  1280. foreach ($this->headers->all() as $key => $value) {
  1281. $_SERVER['HTTP_'.strtoupper(str_replace('-', '_', $key))] = implode(', ', $value);
  1282. }
  1283. $_REQUEST = array_merge($_GET, $_POST);
  1284. }
  1285. public function get($key, $default = null)
  1286. {
  1287. return $this->query->get($key, $this->attributes->get($key, $this->request->get($key, $default)));
  1288. }
  1289. public function getSession()
  1290. {
  1291. return $this->session;
  1292. }
  1293. public function hasSession()
  1294. {
  1295. return $this->cookies->has(session_name());
  1296. }
  1297. public function setSession(Session $session)
  1298. {
  1299. $this->session = $session;
  1300. }
  1301. public function getClientIp($proxy = false)
  1302. {
  1303. if ($proxy) {
  1304. if ($this->server->has('HTTP_CLIENT_IP')) {
  1305. return $this->server->get('HTTP_CLIENT_IP');
  1306. } elseif ($this->server->has('HTTP_X_FORWARDED_FOR')) {
  1307. return $this->server->get('HTTP_X_FORWARDED_FOR');
  1308. }
  1309. }
  1310. return $this->server->get('REMOTE_ADDR');
  1311. }
  1312. public function getScriptName()
  1313. {
  1314. return $this->server->get('SCRIPT_NAME', $this->server->get('ORIG_SCRIPT_NAME', ''));
  1315. }
  1316. public function getPathInfo()
  1317. {
  1318. if (null === $this->pathInfo) {
  1319. $this->pathInfo = $this->preparePathInfo();
  1320. }
  1321. return $this->pathInfo;
  1322. }
  1323. public function getBasePath()
  1324. {
  1325. if (null === $this->basePath) {
  1326. $this->basePath = $this->prepareBasePath();
  1327. }
  1328. return $this->basePath;
  1329. }
  1330. public function getBaseUrl()
  1331. {
  1332. if (null === $this->baseUrl) {
  1333. $this->baseUrl = $this->prepareBaseUrl();
  1334. }
  1335. return $this->baseUrl;
  1336. }
  1337. public function getScheme()
  1338. {
  1339. return ($this->server->get('HTTPS') == 'on') ? 'https' : 'http';
  1340. }
  1341. public function getPort()
  1342. {
  1343. return $this->server->get('SERVER_PORT');
  1344. }
  1345. public function getHttpHost()
  1346. {
  1347. $host = $this->headers->get('HOST');
  1348. if (!empty($host)) {
  1349. return $host;
  1350. }
  1351. $scheme = $this->getScheme();
  1352. $name = $this->server->get('SERVER_NAME');
  1353. $port = $this->getPort();
  1354. if (('http' == $scheme && $port == 80) || ('https' == $scheme && $port == 443)) {
  1355. return $name;
  1356. } else {
  1357. return $name.':'.$port;
  1358. }
  1359. }
  1360. public function getRequestUri()
  1361. {
  1362. if (null === $this->requestUri) {
  1363. $this->requestUri = $this->prepareRequestUri();
  1364. }
  1365. return $this->requestUri;
  1366. }
  1367. public function getUri()
  1368. {
  1369. $qs = $this->getQueryString();
  1370. if (null !== $qs) {
  1371. $qs = '?'.$qs;
  1372. }
  1373. return $this->getScheme().'://'.$this->getHttpHost().$this->getBaseUrl().$this->getPathInfo().$qs;
  1374. }
  1375. public function getUriForPath($path)
  1376. {
  1377. return $this->getScheme().'://'.$this->getHttpHost().$this->getBaseUrl().$path;
  1378. }
  1379. public function getQueryString()
  1380. {
  1381. if (!$qs = $this->server->get('QUERY_STRING')) {
  1382. return null;
  1383. }
  1384. $parts = array();
  1385. $order = array();
  1386. foreach (explode('&', $qs) as $segment) {
  1387. if (false === strpos($segment, '=')) {
  1388. $parts[] = $segment;
  1389. $order[] = $segment;
  1390. } else {
  1391. $tmp = explode('=', urldecode($segment), 2);
  1392. $parts[] = urlencode($tmp[0]).'='.urlencode($tmp[1]);

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