PageRenderTime 70ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 2ms

/bootstrap/compiled.php

https://github.com/edubuc/starter-kit-fr
PHP | 10076 lines | 9977 code | 99 blank | 0 comment | 806 complexity | 8995d61a038fe62ec7e519b7dea5514c MD5 | raw file

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

  1. <?php
  2. namespace Illuminate\Support;
  3. class ClassLoader
  4. {
  5. protected static $directories = array();
  6. protected static $registered = false;
  7. public static function load($class)
  8. {
  9. $class = static::normalizeClass($class);
  10. foreach (static::$directories as $directory) {
  11. if (file_exists($path = $directory . DIRECTORY_SEPARATOR . $class)) {
  12. require_once $path;
  13. return true;
  14. }
  15. }
  16. }
  17. public static function normalizeClass($class)
  18. {
  19. if ($class[0] == '\\') {
  20. $class = substr($class, 1);
  21. }
  22. return str_replace(array('\\', '_'), DIRECTORY_SEPARATOR, $class) . '.php';
  23. }
  24. public static function register()
  25. {
  26. if (!static::$registered) {
  27. spl_autoload_register(array('\\Illuminate\\Support\\ClassLoader', 'load'));
  28. static::$registered = true;
  29. }
  30. }
  31. public static function addDirectories($directories)
  32. {
  33. static::$directories = array_merge(static::$directories, (array) $directories);
  34. static::$directories = array_unique(static::$directories);
  35. }
  36. public static function removeDirectories($directories = null)
  37. {
  38. if (is_null($directories)) {
  39. static::$directories = array();
  40. } else {
  41. $directories = (array) $directories;
  42. static::$directories = array_filter(static::$directories, function ($directory) use($directories) {
  43. return !in_array($directory, $directories);
  44. });
  45. }
  46. }
  47. public static function getDirectories()
  48. {
  49. return static::$directories;
  50. }
  51. }
  52. namespace Illuminate\Container;
  53. use Closure, ArrayAccess, ReflectionParameter;
  54. class BindingResolutionException extends \Exception
  55. {
  56. }
  57. class Container implements ArrayAccess
  58. {
  59. protected $bindings = array();
  60. protected $instances = array();
  61. protected $aliases = array();
  62. protected $resolvingCallbacks = array();
  63. public function bound($abstract)
  64. {
  65. return isset($this[$abstract]) or isset($this->instances[$abstract]);
  66. }
  67. public function bind($abstract, $concrete = null, $shared = false)
  68. {
  69. if (is_array($abstract)) {
  70. list($abstract, $alias) = $this->extractAlias($abstract);
  71. $this->alias($abstract, $alias);
  72. }
  73. unset($this->instances[$abstract]);
  74. if (is_null($concrete)) {
  75. $concrete = $abstract;
  76. }
  77. if (!$concrete instanceof Closure) {
  78. $concrete = function ($c) use($abstract, $concrete) {
  79. $method = $abstract == $concrete ? 'build' : 'make';
  80. return $c->{$method}($concrete);
  81. };
  82. }
  83. $this->bindings[$abstract] = compact('concrete', 'shared');
  84. }
  85. public function bindIf($abstract, $concrete = null, $shared = false)
  86. {
  87. if (!$this->bound($abstract)) {
  88. $this->bind($abstract, $concrete, $shared);
  89. }
  90. }
  91. public function singleton($abstract, $concrete = null)
  92. {
  93. return $this->bind($abstract, $concrete, true);
  94. }
  95. public function share(Closure $closure)
  96. {
  97. return function ($container) use($closure) {
  98. static $object;
  99. if (is_null($object)) {
  100. $object = $closure($container);
  101. }
  102. return $object;
  103. };
  104. }
  105. public function extend($abstract, Closure $closure)
  106. {
  107. if (!isset($this->bindings[$abstract])) {
  108. throw new \InvalidArgumentException("Type {$abstract} is not bound.");
  109. }
  110. $resolver = $this->bindings[$abstract]['concrete'];
  111. $this->bind($abstract, function ($container) use($resolver, $closure) {
  112. return $closure($resolver($container), $container);
  113. }, $this->isShared($abstract));
  114. }
  115. public function instance($abstract, $instance)
  116. {
  117. if (is_array($abstract)) {
  118. list($abstract, $alias) = $this->extractAlias($abstract);
  119. $this->alias($abstract, $alias);
  120. }
  121. $this->instances[$abstract] = $instance;
  122. }
  123. public function alias($abstract, $alias)
  124. {
  125. $this->aliases[$alias] = $abstract;
  126. }
  127. protected function extractAlias(array $definition)
  128. {
  129. return array(key($definition), current($definition));
  130. }
  131. public function make($abstract, $parameters = array())
  132. {
  133. $abstract = $this->getAlias($abstract);
  134. if (isset($this->instances[$abstract])) {
  135. return $this->instances[$abstract];
  136. }
  137. $concrete = $this->getConcrete($abstract);
  138. if ($this->isBuildable($concrete, $abstract)) {
  139. $object = $this->build($concrete, $parameters);
  140. } else {
  141. $object = $this->make($concrete, $parameters);
  142. }
  143. if ($this->isShared($abstract)) {
  144. $this->instances[$abstract] = $object;
  145. }
  146. $this->fireResolvingCallbacks($object);
  147. return $object;
  148. }
  149. protected function getConcrete($abstract)
  150. {
  151. if (!isset($this->bindings[$abstract])) {
  152. return $abstract;
  153. } else {
  154. return $this->bindings[$abstract]['concrete'];
  155. }
  156. }
  157. public function build($concrete, $parameters = array())
  158. {
  159. if ($concrete instanceof Closure) {
  160. return $concrete($this, $parameters);
  161. }
  162. $reflector = new \ReflectionClass($concrete);
  163. if (!$reflector->isInstantiable()) {
  164. $message = "Target [{$concrete}] is not instantiable.";
  165. throw new BindingResolutionException($message);
  166. }
  167. $constructor = $reflector->getConstructor();
  168. if (is_null($constructor)) {
  169. return new $concrete();
  170. }
  171. $parameters = $constructor->getParameters();
  172. $dependencies = $this->getDependencies($parameters);
  173. return $reflector->newInstanceArgs($dependencies);
  174. }
  175. protected function getDependencies($parameters)
  176. {
  177. $dependencies = array();
  178. foreach ($parameters as $parameter) {
  179. $dependency = $parameter->getClass();
  180. if (is_null($dependency)) {
  181. $dependencies[] = $this->resolveNonClass($parameter);
  182. } else {
  183. $dependencies[] = $this->make($dependency->name);
  184. }
  185. }
  186. return (array) $dependencies;
  187. }
  188. protected function resolveNonClass(ReflectionParameter $parameter)
  189. {
  190. if ($parameter->isDefaultValueAvailable()) {
  191. return $parameter->getDefaultValue();
  192. } else {
  193. $message = "Unresolvable dependency resolving [{$parameter}].";
  194. throw new BindingResolutionException($message);
  195. }
  196. }
  197. public function resolving(Closure $callback)
  198. {
  199. $this->resolvingCallbacks[] = $callback;
  200. }
  201. protected function fireResolvingCallbacks($object)
  202. {
  203. foreach ($this->resolvingCallbacks as $callback) {
  204. call_user_func($callback, $object);
  205. }
  206. }
  207. protected function isShared($abstract)
  208. {
  209. $set = isset($this->bindings[$abstract]['shared']);
  210. return $set and $this->bindings[$abstract]['shared'] === true;
  211. }
  212. protected function isBuildable($concrete, $abstract)
  213. {
  214. return $concrete === $abstract or $concrete instanceof Closure;
  215. }
  216. protected function getAlias($abstract)
  217. {
  218. return isset($this->aliases[$abstract]) ? $this->aliases[$abstract] : $abstract;
  219. }
  220. public function getBindings()
  221. {
  222. return $this->bindings;
  223. }
  224. public function offsetExists($key)
  225. {
  226. return isset($this->bindings[$key]);
  227. }
  228. public function offsetGet($key)
  229. {
  230. return $this->make($key);
  231. }
  232. public function offsetSet($key, $value)
  233. {
  234. if (!$value instanceof Closure) {
  235. $value = function () use($value) {
  236. return $value;
  237. };
  238. }
  239. $this->bind($key, $value);
  240. }
  241. public function offsetUnset($key)
  242. {
  243. unset($this->bindings[$key]);
  244. }
  245. }
  246. namespace Symfony\Component\HttpKernel;
  247. use Symfony\Component\HttpFoundation\Request;
  248. use Symfony\Component\HttpFoundation\Response;
  249. interface HttpKernelInterface
  250. {
  251. const MASTER_REQUEST = 1;
  252. const SUB_REQUEST = 2;
  253. public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
  254. }
  255. namespace Illuminate\Support\Contracts;
  256. interface ResponsePreparerInterface
  257. {
  258. public function prepareResponse($value);
  259. }
  260. namespace Illuminate\Foundation;
  261. use Closure;
  262. use Illuminate\Http\Request;
  263. use Illuminate\Http\Response;
  264. use Illuminate\Routing\Route;
  265. use Illuminate\Routing\Router;
  266. use Illuminate\Config\FileLoader;
  267. use Illuminate\Container\Container;
  268. use Illuminate\Filesystem\Filesystem;
  269. use Illuminate\Support\Facades\Facade;
  270. use Illuminate\Support\ServiceProvider;
  271. use Illuminate\Events\EventServiceProvider;
  272. use Illuminate\Foundation\ProviderRepository;
  273. use Illuminate\Routing\RoutingServiceProvider;
  274. use Illuminate\Exception\ExceptionServiceProvider;
  275. use Symfony\Component\HttpFoundation\JsonResponse;
  276. use Symfony\Component\HttpKernel\HttpKernelInterface;
  277. use Symfony\Component\HttpFoundation\StreamedResponse;
  278. use Symfony\Component\HttpKernel\Exception\HttpException;
  279. use Illuminate\Support\Contracts\ResponsePreparerInterface;
  280. use Symfony\Component\HttpKernel\Exception\FatalErrorException;
  281. use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
  282. use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
  283. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  284. use Symfony\Component\HttpFoundation\RedirectResponse as SymfonyRedirect;
  285. class Application extends Container implements HttpKernelInterface, ResponsePreparerInterface
  286. {
  287. const VERSION = '4.0.0';
  288. protected $booted = false;
  289. protected $bootingCallbacks = array();
  290. protected $bootedCallbacks = array();
  291. protected $shutdownCallbacks = array();
  292. protected $serviceProviders = array();
  293. protected $loadedProviders = array();
  294. protected $deferredServices = array();
  295. public function __construct(Request $request = null)
  296. {
  297. $this['request'] = $this->createRequest($request);
  298. $this->register(new ExceptionServiceProvider($this));
  299. $this->register(new RoutingServiceProvider($this));
  300. $this->register(new EventServiceProvider($this));
  301. }
  302. protected function createRequest(Request $request = null)
  303. {
  304. return $request ?: Request::createFromGlobals();
  305. }
  306. public function setRequestForConsoleEnvironment()
  307. {
  308. $url = $this['config']->get('app.url', 'http://localhost');
  309. $this->instance('request', Request::create($url, 'GET', array(), array(), array(), $_SERVER));
  310. }
  311. public function redirectIfTrailingSlash()
  312. {
  313. if ($this->runningInConsole()) {
  314. return;
  315. }
  316. $path = $this['request']->getPathInfo();
  317. if ($path != '/' and ends_with($path, '/') and !ends_with($path, '//')) {
  318. with(new SymfonyRedirect($this['request']->fullUrl(), 301))->send();
  319. die;
  320. }
  321. }
  322. public function bindInstallPaths(array $paths)
  323. {
  324. $this->instance('path', realpath($paths['app']));
  325. foreach (array_except($paths, array('app')) as $key => $value) {
  326. $this->instance("path.{$key}", realpath($value));
  327. }
  328. }
  329. public static function getBootstrapFile()
  330. {
  331. return 'C:\\wamp\\www\\starter-kit-fr\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation' . '/start.php';
  332. }
  333. public function startExceptionHandling()
  334. {
  335. $this['exception']->register($this->environment());
  336. $this['exception']->setDebug($this['config']['app.debug']);
  337. }
  338. public function environment()
  339. {
  340. return $this['env'];
  341. }
  342. public function detectEnvironment($environments)
  343. {
  344. $base = $this['request']->getHost();
  345. $arguments = $this['request']->server->get('argv');
  346. if ($this->runningInConsole()) {
  347. return $this->detectConsoleEnvironment($base, $environments, $arguments);
  348. }
  349. return $this->detectWebEnvironment($base, $environments);
  350. }
  351. protected function detectWebEnvironment($base, $environments)
  352. {
  353. if ($environments instanceof Closure) {
  354. return $this['env'] = call_user_func($environments);
  355. }
  356. foreach ($environments as $environment => $hosts) {
  357. foreach ((array) $hosts as $host) {
  358. if (str_is($host, $base) or $this->isMachine($host)) {
  359. return $this['env'] = $environment;
  360. }
  361. }
  362. }
  363. return $this['env'] = 'production';
  364. }
  365. protected function detectConsoleEnvironment($base, $environments, $arguments)
  366. {
  367. foreach ($arguments as $key => $value) {
  368. if (starts_with($value, '--env=')) {
  369. $segments = array_slice(explode('=', $value), 1);
  370. return $this['env'] = head($segments);
  371. }
  372. }
  373. return $this->detectWebEnvironment($base, $environments);
  374. }
  375. protected function isMachine($name)
  376. {
  377. return str_is($name, gethostname());
  378. }
  379. public function runningInConsole()
  380. {
  381. return php_sapi_name() == 'cli';
  382. }
  383. public function runningUnitTests()
  384. {
  385. return $this['env'] == 'testing';
  386. }
  387. public function register($provider, $options = array())
  388. {
  389. if (is_string($provider)) {
  390. $provider = $this->resolveProviderClass($provider);
  391. }
  392. $provider->register();
  393. foreach ($options as $key => $value) {
  394. $this[$key] = $value;
  395. }
  396. $this->serviceProviders[] = $provider;
  397. $this->loadedProviders[get_class($provider)] = true;
  398. }
  399. protected function resolveProviderClass($provider)
  400. {
  401. return new $provider($this);
  402. }
  403. public function loadDeferredProviders()
  404. {
  405. foreach (array_unique($this->deferredServices) as $provider) {
  406. $this->register($instance = new $provider($this));
  407. if ($this->booted) {
  408. $instance->boot();
  409. }
  410. }
  411. $this->deferredServices = array();
  412. }
  413. protected function loadDeferredProvider($service)
  414. {
  415. $provider = $this->deferredServices[$service];
  416. if (!isset($this->loadedProviders[$provider])) {
  417. $this->register($instance = new $provider($this));
  418. unset($this->deferredServices[$service]);
  419. $this->setupDeferredBoot($instance);
  420. }
  421. }
  422. protected function setupDeferredBoot($instance)
  423. {
  424. if ($this->booted) {
  425. return $instance->boot();
  426. }
  427. $this->booting(function () use($instance) {
  428. $instance->boot();
  429. });
  430. }
  431. public function make($abstract, $parameters = array())
  432. {
  433. if (isset($this->deferredServices[$abstract])) {
  434. $this->loadDeferredProvider($abstract);
  435. }
  436. return parent::make($abstract, $parameters);
  437. }
  438. public function before($callback)
  439. {
  440. return $this['router']->before($callback);
  441. }
  442. public function after($callback)
  443. {
  444. return $this['router']->after($callback);
  445. }
  446. public function close($callback)
  447. {
  448. return $this['router']->close($callback);
  449. }
  450. public function finish($callback)
  451. {
  452. $this['router']->finish($callback);
  453. }
  454. public function shutdown($callback = null)
  455. {
  456. if (is_null($callback)) {
  457. $this->fireAppCallbacks($this->shutdownCallbacks);
  458. } else {
  459. $this->shutdownCallbacks[] = $callback;
  460. }
  461. }
  462. public function run()
  463. {
  464. $response = $this->dispatch($this['request']);
  465. $this['router']->callCloseFilter($this['request'], $response);
  466. $response->send();
  467. $this['router']->callFinishFilter($this['request'], $response);
  468. }
  469. public function dispatch(Request $request)
  470. {
  471. if ($this->isDownForMaintenance()) {
  472. $response = $this['events']->until('illuminate.app.down');
  473. return $this->prepareResponse($response, $request);
  474. } else {
  475. return $this['router']->dispatch($this->prepareRequest($request));
  476. }
  477. }
  478. public function handle(SymfonyRequest $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  479. {
  480. $this->instance('request', $request);
  481. Facade::clearResolvedInstance('request');
  482. return $this->dispatch($request);
  483. }
  484. public function boot()
  485. {
  486. if ($this->booted) {
  487. return;
  488. }
  489. foreach ($this->serviceProviders as $provider) {
  490. $provider->boot();
  491. }
  492. $this->fireAppCallbacks($this->bootingCallbacks);
  493. $this->booted = true;
  494. $this->fireAppCallbacks($this->bootedCallbacks);
  495. }
  496. public function booting($callback)
  497. {
  498. $this->bootingCallbacks[] = $callback;
  499. }
  500. public function booted($callback)
  501. {
  502. $this->bootedCallbacks[] = $callback;
  503. }
  504. protected function fireAppCallbacks(array $callbacks)
  505. {
  506. foreach ($callbacks as $callback) {
  507. call_user_func($callback, $this);
  508. }
  509. }
  510. public function prepareRequest(Request $request)
  511. {
  512. if (isset($this['session'])) {
  513. $request->setSessionStore($this['session']);
  514. }
  515. return $request;
  516. }
  517. public function prepareResponse($value)
  518. {
  519. if (!$value instanceof SymfonyResponse) {
  520. $value = new Response($value);
  521. }
  522. return $value->prepare($this['request']);
  523. }
  524. public function isDownForMaintenance()
  525. {
  526. return file_exists($this['path.storage'] . '/meta/down');
  527. }
  528. public function down(Closure $callback)
  529. {
  530. $this['events']->listen('illuminate.app.down', $callback);
  531. }
  532. public function abort($code, $message = '', array $headers = array())
  533. {
  534. if ($code == 404) {
  535. throw new NotFoundHttpException($message);
  536. } else {
  537. throw new HttpException($code, $message, null, $headers);
  538. }
  539. }
  540. public function missing(Closure $callback)
  541. {
  542. $this->error(function (NotFoundHttpException $e) use($callback) {
  543. return call_user_func($callback, $e);
  544. });
  545. }
  546. public function error(Closure $callback)
  547. {
  548. $this['exception']->error($callback);
  549. }
  550. public function fatal(Closure $callback)
  551. {
  552. $this->error(function (FatalErrorException $e) use($callback) {
  553. return call_user_func($callback, $e);
  554. });
  555. }
  556. public function getConfigLoader()
  557. {
  558. return new FileLoader(new Filesystem(), $this['path'] . '/config');
  559. }
  560. public function getProviderRepository()
  561. {
  562. $manifest = $this['config']['app.manifest'];
  563. return new ProviderRepository(new Filesystem(), $manifest);
  564. }
  565. public function setLocale($locale)
  566. {
  567. $this['config']->set('app.locale', $locale);
  568. $this['translator']->setLocale($locale);
  569. $this['events']->fire('locale.changed', array($locale));
  570. }
  571. public function getLoadedProviders()
  572. {
  573. return $this->loadedProviders;
  574. }
  575. public function setDeferredServices(array $services)
  576. {
  577. $this->deferredServices = $services;
  578. }
  579. public function __get($key)
  580. {
  581. return $this[$key];
  582. }
  583. public function __set($key, $value)
  584. {
  585. $this[$key] = $value;
  586. }
  587. }
  588. namespace Illuminate\Http;
  589. use Illuminate\Session\Store as SessionStore;
  590. use Symfony\Component\HttpFoundation\ParameterBag;
  591. class Request extends \Symfony\Component\HttpFoundation\Request
  592. {
  593. protected $json;
  594. protected $sessionStore;
  595. public function instance()
  596. {
  597. return $this;
  598. }
  599. public function root()
  600. {
  601. return rtrim($this->getSchemeAndHttpHost() . $this->getBaseUrl(), '/');
  602. }
  603. public function url()
  604. {
  605. return rtrim(preg_replace('/\\?.*/', '', $this->getUri()), '/');
  606. }
  607. public function fullUrl()
  608. {
  609. $query = $this->getQueryString();
  610. return $query ? $this->url() . '?' . $query : $this->url();
  611. }
  612. public function path()
  613. {
  614. $pattern = trim($this->getPathInfo(), '/');
  615. return $pattern == '' ? '/' : $pattern;
  616. }
  617. public function segment($index, $default = null)
  618. {
  619. $segments = explode('/', trim($this->getPathInfo(), '/'));
  620. $segments = array_filter($segments, function ($v) {
  621. return $v != '';
  622. });
  623. return array_get($segments, $index - 1, $default);
  624. }
  625. public function segments()
  626. {
  627. $path = $this->path();
  628. return $path == '/' ? array() : explode('/', $path);
  629. }
  630. public function is($pattern)
  631. {
  632. foreach (func_get_args() as $pattern) {
  633. if (str_is($pattern, $this->path())) {
  634. return true;
  635. }
  636. }
  637. return false;
  638. }
  639. public function ajax()
  640. {
  641. return $this->isXmlHttpRequest();
  642. }
  643. public function secure()
  644. {
  645. return $this->isSecure();
  646. }
  647. public function has($key)
  648. {
  649. if (count(func_get_args()) > 1) {
  650. foreach (func_get_args() as $value) {
  651. if (!$this->has($value)) {
  652. return false;
  653. }
  654. }
  655. return true;
  656. }
  657. if (is_array($this->input($key))) {
  658. return true;
  659. }
  660. return trim((string) $this->input($key)) !== '';
  661. }
  662. public function all()
  663. {
  664. return $this->input() + $this->files->all();
  665. }
  666. public function input($key = null, $default = null)
  667. {
  668. $input = $this->getInputSource()->all() + $this->query->all();
  669. return array_get($input, $key, $default);
  670. }
  671. public function only($keys)
  672. {
  673. $keys = is_array($keys) ? $keys : func_get_args();
  674. return array_only($this->input(), $keys) + array_fill_keys($keys, null);
  675. }
  676. public function except($keys)
  677. {
  678. $keys = is_array($keys) ? $keys : func_get_args();
  679. $results = $this->input();
  680. foreach ($keys as $key) {
  681. array_forget($results, $key);
  682. }
  683. return $results;
  684. }
  685. public function query($key = null, $default = null)
  686. {
  687. return $this->retrieveItem('query', $key, $default);
  688. }
  689. public function cookie($key = null, $default = null)
  690. {
  691. return $this->retrieveItem('cookies', $key, $default);
  692. }
  693. public function file($key = null, $default = null)
  694. {
  695. return $this->retrieveItem('files', $key, $default);
  696. }
  697. public function hasFile($key)
  698. {
  699. return $this->files->has($key) and !is_null($this->file($key));
  700. }
  701. public function header($key = null, $default = null)
  702. {
  703. return $this->retrieveItem('headers', $key, $default);
  704. }
  705. public function server($key = null, $default = null)
  706. {
  707. return $this->retrieveItem('server', $key, $default);
  708. }
  709. public function old($key = null, $default = null)
  710. {
  711. return $this->getSessionStore()->getOldInput($key, $default);
  712. }
  713. public function flash($filter = null, $keys = array())
  714. {
  715. $flash = !is_null($filter) ? $this->{$filter}($keys) : $this->input();
  716. $this->getSessionStore()->flashInput($flash);
  717. }
  718. public function flashOnly($keys)
  719. {
  720. $keys = is_array($keys) ? $keys : func_get_args();
  721. return $this->flash('only', $keys);
  722. }
  723. public function flashExcept($keys)
  724. {
  725. $keys = is_array($keys) ? $keys : func_get_args();
  726. return $this->flash('except', $keys);
  727. }
  728. public function flush()
  729. {
  730. $this->getSessionStore()->flashInput(array());
  731. }
  732. protected function retrieveItem($source, $key, $default)
  733. {
  734. if (is_null($key)) {
  735. return $this->{$source}->all();
  736. } else {
  737. return $this->{$source}->get($key, $default, true);
  738. }
  739. }
  740. public function merge(array $input)
  741. {
  742. $this->getInputSource()->add($input);
  743. }
  744. public function replace(array $input)
  745. {
  746. $this->getInputSource()->replace($input);
  747. }
  748. public function json($key = null, $default = null)
  749. {
  750. if (!isset($this->json)) {
  751. $this->json = new ParameterBag((array) json_decode($this->getContent(), true));
  752. }
  753. if (is_null($key)) {
  754. return $this->json;
  755. }
  756. return array_get($this->json->all(), $key, $default);
  757. }
  758. protected function getInputSource()
  759. {
  760. if ($this->isJson()) {
  761. return $this->json();
  762. }
  763. return $this->getMethod() == 'GET' ? $this->query : $this->request;
  764. }
  765. public function isJson()
  766. {
  767. return str_contains($this->header('CONTENT_TYPE'), '/json');
  768. }
  769. public function wantsJson()
  770. {
  771. $acceptable = $this->getAcceptableContentTypes();
  772. return isset($acceptable[0]) and $acceptable[0] == 'application/json';
  773. }
  774. public function getSessionStore()
  775. {
  776. if (!isset($this->sessionStore)) {
  777. throw new \RuntimeException('Session store not set on request.');
  778. }
  779. return $this->sessionStore;
  780. }
  781. public function setSessionStore(SessionStore $session)
  782. {
  783. $this->sessionStore = $session;
  784. }
  785. public function hasSessionStore()
  786. {
  787. return isset($this->sessionStore);
  788. }
  789. }
  790. namespace Symfony\Component\HttpFoundation;
  791. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  792. class Request
  793. {
  794. const HEADER_CLIENT_IP = 'client_ip';
  795. const HEADER_CLIENT_HOST = 'client_host';
  796. const HEADER_CLIENT_PROTO = 'client_proto';
  797. const HEADER_CLIENT_PORT = 'client_port';
  798. protected static $trustedProxies = array();
  799. protected static $trustedHeaders = array(self::HEADER_CLIENT_IP => 'X_FORWARDED_FOR', self::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST', self::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO', self::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT');
  800. protected static $httpMethodParameterOverride = false;
  801. public $attributes;
  802. public $request;
  803. public $query;
  804. public $server;
  805. public $files;
  806. public $cookies;
  807. public $headers;
  808. protected $content;
  809. protected $languages;
  810. protected $charsets;
  811. protected $acceptableContentTypes;
  812. protected $pathInfo;
  813. protected $requestUri;
  814. protected $baseUrl;
  815. protected $basePath;
  816. protected $method;
  817. protected $format;
  818. protected $session;
  819. protected $locale;
  820. protected $defaultLocale = 'en';
  821. protected static $formats;
  822. public function __construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
  823. {
  824. $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content);
  825. }
  826. public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
  827. {
  828. $this->request = new ParameterBag($request);
  829. $this->query = new ParameterBag($query);
  830. $this->attributes = new ParameterBag($attributes);
  831. $this->cookies = new ParameterBag($cookies);
  832. $this->files = new FileBag($files);
  833. $this->server = new ServerBag($server);
  834. $this->headers = new HeaderBag($this->server->getHeaders());
  835. $this->content = $content;
  836. $this->languages = null;
  837. $this->charsets = null;
  838. $this->acceptableContentTypes = null;
  839. $this->pathInfo = null;
  840. $this->requestUri = null;
  841. $this->baseUrl = null;
  842. $this->basePath = null;
  843. $this->method = null;
  844. $this->format = null;
  845. }
  846. public static function createFromGlobals()
  847. {
  848. $request = new static($_GET, $_POST, array(), $_COOKIE, $_FILES, $_SERVER);
  849. if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), array('PUT', 'DELETE', 'PATCH'))) {
  850. parse_str($request->getContent(), $data);
  851. $request->request = new ParameterBag($data);
  852. }
  853. return $request;
  854. }
  855. public static function create($uri, $method = 'GET', $parameters = array(), $cookies = array(), $files = array(), $server = array(), $content = null)
  856. {
  857. $server = array_replace(array('SERVER_NAME' => 'localhost', 'SERVER_PORT' => 80, 'HTTP_HOST' => 'localhost', 'HTTP_USER_AGENT' => 'Symfony/2.X', 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5', 'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '', 'SCRIPT_FILENAME' => '', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_TIME' => time()), $server);
  858. $server['PATH_INFO'] = '';
  859. $server['REQUEST_METHOD'] = strtoupper($method);
  860. $components = parse_url($uri);
  861. if (isset($components['host'])) {
  862. $server['SERVER_NAME'] = $components['host'];
  863. $server['HTTP_HOST'] = $components['host'];
  864. }
  865. if (isset($components['scheme'])) {
  866. if ('https' === $components['scheme']) {
  867. $server['HTTPS'] = 'on';
  868. $server['SERVER_PORT'] = 443;
  869. } else {
  870. unset($server['HTTPS']);
  871. $server['SERVER_PORT'] = 80;
  872. }
  873. }
  874. if (isset($components['port'])) {
  875. $server['SERVER_PORT'] = $components['port'];
  876. $server['HTTP_HOST'] = $server['HTTP_HOST'] . ':' . $components['port'];
  877. }
  878. if (isset($components['user'])) {
  879. $server['PHP_AUTH_USER'] = $components['user'];
  880. }
  881. if (isset($components['pass'])) {
  882. $server['PHP_AUTH_PW'] = $components['pass'];
  883. }
  884. if (!isset($components['path'])) {
  885. $components['path'] = '/';
  886. }
  887. switch (strtoupper($method)) {
  888. case 'POST':
  889. case 'PUT':
  890. case 'DELETE':
  891. if (!isset($server['CONTENT_TYPE'])) {
  892. $server['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
  893. }
  894. case 'PATCH':
  895. $request = $parameters;
  896. $query = array();
  897. break;
  898. default:
  899. $request = array();
  900. $query = $parameters;
  901. break;
  902. }
  903. if (isset($components['query'])) {
  904. parse_str(html_entity_decode($components['query']), $qs);
  905. $query = array_replace($qs, $query);
  906. }
  907. $queryString = http_build_query($query, '', '&');
  908. $server['REQUEST_URI'] = $components['path'] . ('' !== $queryString ? '?' . $queryString : '');
  909. $server['QUERY_STRING'] = $queryString;
  910. return new static($query, $request, array(), $cookies, $files, $server, $content);
  911. }
  912. public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
  913. {
  914. $dup = clone $this;
  915. if ($query !== null) {
  916. $dup->query = new ParameterBag($query);
  917. }
  918. if ($request !== null) {
  919. $dup->request = new ParameterBag($request);
  920. }
  921. if ($attributes !== null) {
  922. $dup->attributes = new ParameterBag($attributes);
  923. }
  924. if ($cookies !== null) {
  925. $dup->cookies = new ParameterBag($cookies);
  926. }
  927. if ($files !== null) {
  928. $dup->files = new FileBag($files);
  929. }
  930. if ($server !== null) {
  931. $dup->server = new ServerBag($server);
  932. $dup->headers = new HeaderBag($dup->server->getHeaders());
  933. }
  934. $dup->languages = null;
  935. $dup->charsets = null;
  936. $dup->acceptableContentTypes = null;
  937. $dup->pathInfo = null;
  938. $dup->requestUri = null;
  939. $dup->baseUrl = null;
  940. $dup->basePath = null;
  941. $dup->method = null;
  942. $dup->format = null;
  943. return $dup;
  944. }
  945. public function __clone()
  946. {
  947. $this->query = clone $this->query;
  948. $this->request = clone $this->request;
  949. $this->attributes = clone $this->attributes;
  950. $this->cookies = clone $this->cookies;
  951. $this->files = clone $this->files;
  952. $this->server = clone $this->server;
  953. $this->headers = clone $this->headers;
  954. }
  955. public function __toString()
  956. {
  957. return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL')) . '
  958. ' . $this->headers . '
  959. ' . $this->getContent();
  960. }
  961. public function overrideGlobals()
  962. {
  963. $_GET = $this->query->all();
  964. $_POST = $this->request->all();
  965. $_SERVER = $this->server->all();
  966. $_COOKIE = $this->cookies->all();
  967. foreach ($this->headers->all() as $key => $value) {
  968. $key = strtoupper(str_replace('-', '_', $key));
  969. if (in_array($key, array('CONTENT_TYPE', 'CONTENT_LENGTH'))) {
  970. $_SERVER[$key] = implode(', ', $value);
  971. } else {
  972. $_SERVER['HTTP_' . $key] = implode(', ', $value);
  973. }
  974. }
  975. $request = array('g' => $_GET, 'p' => $_POST, 'c' => $_COOKIE);
  976. $requestOrder = ini_get('request_order') ?: ini_get('variable_order');
  977. $requestOrder = preg_replace('#[^cgp]#', '', strtolower($requestOrder)) ?: 'gp';
  978. $_REQUEST = array();
  979. foreach (str_split($requestOrder) as $order) {
  980. $_REQUEST = array_merge($_REQUEST, $request[$order]);
  981. }
  982. }
  983. public static function setTrustedProxies(array $proxies)
  984. {
  985. self::$trustedProxies = $proxies;
  986. }
  987. public static function getTrustedProxies()
  988. {
  989. return self::$trustedProxies;
  990. }
  991. public static function setTrustedHeaderName($key, $value)
  992. {
  993. if (!array_key_exists($key, self::$trustedHeaders)) {
  994. throw new \InvalidArgumentException(sprintf('Unable to set the trusted header name for key "%s".', $key));
  995. }
  996. self::$trustedHeaders[$key] = $value;
  997. }
  998. public static function getTrustedHeaderName($key)
  999. {
  1000. if (!array_key_exists($key, self::$trustedHeaders)) {
  1001. throw new \InvalidArgumentException(sprintf('Unable to get the trusted header name for key "%s".', $key));
  1002. }
  1003. return self::$trustedHeaders[$key];
  1004. }
  1005. public static function normalizeQueryString($qs)
  1006. {
  1007. if ('' == $qs) {
  1008. return '';
  1009. }
  1010. $parts = array();
  1011. $order = array();
  1012. foreach (explode('&', $qs) as $param) {
  1013. if ('' === $param || '=' === $param[0]) {
  1014. continue;
  1015. }
  1016. $keyValuePair = explode('=', $param, 2);
  1017. $parts[] = isset($keyValuePair[1]) ? rawurlencode(urldecode($keyValuePair[0])) . '=' . rawurlencode(urldecode($keyValuePair[1])) : rawurlencode(urldecode($keyValuePair[0]));
  1018. $order[] = urldecode($keyValuePair[0]);
  1019. }
  1020. array_multisort($order, SORT_ASC, $parts);
  1021. return implode('&', $parts);
  1022. }
  1023. public static function enableHttpMethodParameterOverride()
  1024. {
  1025. self::$httpMethodParameterOverride = true;
  1026. }
  1027. public static function getHttpMethodParameterOverride()
  1028. {
  1029. return self::$httpMethodParameterOverride;
  1030. }
  1031. public function get($key, $default = null, $deep = false)
  1032. {
  1033. return $this->query->get($key, $this->attributes->get($key, $this->request->get($key, $default, $deep), $deep), $deep);
  1034. }
  1035. public function getSession()
  1036. {
  1037. return $this->session;
  1038. }
  1039. public function hasPreviousSession()
  1040. {
  1041. return $this->hasSession() && $this->cookies->has($this->session->getName());
  1042. }
  1043. public function hasSession()
  1044. {
  1045. return null !== $this->session;
  1046. }
  1047. public function setSession(SessionInterface $session)
  1048. {
  1049. $this->session = $session;
  1050. }
  1051. public function getClientIps()
  1052. {
  1053. $ip = $this->server->get('REMOTE_ADDR');
  1054. if (!self::$trustedProxies) {
  1055. return array($ip);
  1056. }
  1057. if (!self::$trustedHeaders[self::HEADER_CLIENT_IP] || !$this->headers->has(self::$trustedHeaders[self::HEADER_CLIENT_IP])) {
  1058. return array($ip);
  1059. }
  1060. $clientIps = array_map('trim', explode(',', $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_IP])));
  1061. $clientIps[] = $ip;
  1062. $trustedProxies = !self::$trustedProxies ? array($ip) : self::$trustedProxies;
  1063. $ip = $clientIps[0];
  1064. foreach ($clientIps as $key => $clientIp) {
  1065. if (IpUtils::checkIp($clientIp, $trustedProxies)) {
  1066. unset($clientIps[$key]);
  1067. continue;
  1068. }
  1069. }
  1070. return $clientIps ? array_reverse($clientIps) : array($ip);
  1071. }
  1072. public function getClientIp()
  1073. {
  1074. $ipAddresses = $this->getClientIps();
  1075. return $ipAddresses[0];
  1076. }
  1077. public function getScriptName()
  1078. {
  1079. return $this->server->get('SCRIPT_NAME', $this->server->get('ORIG_SCRIPT_NAME', ''));
  1080. }
  1081. public function getPathInfo()
  1082. {
  1083. if (null === $this->pathInfo) {
  1084. $this->pathInfo = $this->preparePathInfo();
  1085. }
  1086. return $this->pathInfo;
  1087. }
  1088. public function getBasePath()
  1089. {
  1090. if (null === $this->basePath) {
  1091. $this->basePath = $this->prepareBasePath();
  1092. }
  1093. return $this->basePath;
  1094. }
  1095. public function getBaseUrl()
  1096. {
  1097. if (null === $this->baseUrl) {
  1098. $this->baseUrl = $this->prepareBaseUrl();
  1099. }
  1100. return $this->baseUrl;
  1101. }
  1102. public function getScheme()
  1103. {
  1104. return $this->isSecure() ? 'https' : 'http';
  1105. }
  1106. public function getPort()
  1107. {
  1108. if (self::$trustedProxies) {
  1109. if (self::$trustedHeaders[self::HEADER_CLIENT_PORT] && ($port = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PORT]))) {
  1110. return $port;
  1111. }
  1112. if (self::$trustedHeaders[self::HEADER_CLIENT_PROTO] && 'https' === $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO], 'http')) {
  1113. return 443;
  1114. }
  1115. }
  1116. return $this->server->get('SERVER_PORT');
  1117. }
  1118. public function getUser()
  1119. {
  1120. return $this->server->get('PHP_AUTH_USER');
  1121. }
  1122. public function getPassword()
  1123. {
  1124. return $this->server->get('PHP_AUTH_PW');
  1125. }
  1126. public function getUserInfo()
  1127. {
  1128. $userinfo = $this->getUser();
  1129. $pass = $this->getPassword();
  1130. if ('' != $pass) {
  1131. $userinfo .= ":{$pass}";
  1132. }
  1133. return $userinfo;
  1134. }
  1135. public function getHttpHost()
  1136. {
  1137. $scheme = $this->getScheme();
  1138. $port = $this->getPort();
  1139. if ('http' == $scheme && $port == 80 || 'https' == $scheme && $port == 443) {
  1140. return $this->getHost();
  1141. }
  1142. return $this->getHost() . ':' . $port;
  1143. }
  1144. public function getRequestUri()
  1145. {
  1146. if (null === $this->requestUri) {
  1147. $this->requestUri = $this->prepareRequestUri();
  1148. }
  1149. return $this->requestUri;
  1150. }
  1151. public function getSchemeAndHttpHost()
  1152. {
  1153. return $this->getScheme() . '://' . $this->getHttpHost();
  1154. }
  1155. public function getUri()
  1156. {
  1157. if (null !== ($qs = $this->getQueryString())) {
  1158. $qs = '?' . $qs;
  1159. }
  1160. return $this->getSchemeAndHttpHost() . $this->getBaseUrl() . $this->getPathInfo() . $qs;
  1161. }
  1162. public function getUriForPath($path)
  1163. {
  1164. return $this->getSchemeAndHttpHost() . $this->getBaseUrl() . $path;
  1165. }
  1166. public function getQueryString()
  1167. {
  1168. $qs = static::normalizeQueryString($this->server->get('QUERY_STRING'));
  1169. return '' === $qs ? null : $qs;
  1170. }
  1171. public function isSecure()
  1172. {
  1173. if (self::$trustedProxies && self::$trustedHeaders[self::HEADER_CLIENT_PROTO] && ($proto = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO]))) {
  1174. return in_array(strtolower($proto), array('https', 'on', '1'));
  1175. }
  1176. return 'on' == strtolower($this->server->get('HTTPS')) || 1 == $this->server->get('HTTPS');
  1177. }
  1178. public function getHost()
  1179. {
  1180. if (self::$trustedProxies && self::$trustedHeaders[self::HEADER_CLIENT_HOST] && ($host = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_HOST]))) {
  1181. $elements = explode(',', $host);
  1182. $host = $elements[count($elements) - 1];
  1183. } elseif (!($host = $this->headers->get('HOST'))) {
  1184. if (!($host = $this->server->get('SERVER_NAME'))) {
  1185. $host = $this->server->get('SERVER_ADDR', '');
  1186. }
  1187. }
  1188. $host = strtolower(preg_replace('/:\\d+$/', '', trim($host)));
  1189. if ($host && !preg_match('/^\\[?(?:[a-zA-Z0-9-:\\]_]+\\.?)+$/', $host)) {
  1190. throw new \UnexpectedValueException('Invalid Host');
  1191. }
  1192. return $host;
  1193. }
  1194. public function setMethod($method)
  1195. {
  1196. $this->method = null;
  1197. $this->server->set('REQUEST_METHOD', $method);
  1198. }
  1199. public function getMethod()
  1200. {
  1201. if (null === $this->method) {
  1202. $this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
  1203. if ('POST' === $this->method) {
  1204. if ($method = $this->headers->get('X-HTTP-METHOD-OVERRIDE')) {
  1205. $this->method = strtoupper($method);
  1206. } elseif (self::$httpMethodParameterOverride) {
  1207. $this->method = strtoupper($this->request->get('_method', $this->query->get('_method', 'POST')));
  1208. }
  1209. }
  1210. }
  1211. return $this->method;
  1212. }
  1213. public function getRealMethod()
  1214. {
  1215. return strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
  1216. }
  1217. public function getMimeType($format)
  1218. {
  1219. if (null === static::$formats) {
  1220. static::initializeFormats();
  1221. }
  1222. return isset(static::$formats[$format]) ? static::$formats[$format][0] : null;
  1223. }
  1224. public function getFormat($mimeType)
  1225. {
  1226. if (false !== ($pos = strpos($mimeType, ';'))) {
  1227. $mimeType = substr($mimeType, 0, $pos);
  1228. }
  1229. if (null === static::$formats) {
  1230. static::initializeFormats();
  1231. }
  1232. foreach (static::$formats as $format => $mimeTypes) {
  1233. if (in_array($mimeType, (array) $mimeTypes)) {
  1234. return $format;
  1235. }
  1236. }
  1237. return null;
  1238. }
  1239. public function setFormat($format, $mimeTypes)
  1240. {
  1241. if (null === static::$formats) {
  1242. static::initializeFormats();
  1243. }
  1244. static::$formats[$format] = is_array($mimeTypes) ? $mimeTypes : array($mimeTypes);
  1245. }
  1246. public function getRequestFormat($default = 'html')
  1247. {
  1248. if (null === $this->format) {
  1249. $this->format = $this->get('_format', $default);
  1250. }
  1251. return $this->format;
  1252. }
  1253. public function setRequestFormat($format)
  1254. {
  1255. $this->format = $format;
  1256. }
  1257. public function getContentType()
  1258. {
  1259. return $this->getFormat($this->headers->get('CONTENT_TYPE'));
  1260. }
  1261. public function setDefaultLocale($locale)
  1262. {
  1263. $this->defaultLocale = $locale;
  1264. if (null === $this->locale) {
  1265. $this->setPhpDefaultLocale($locale);
  1266. }
  1267. }
  1268. public function setLocale($locale)
  1269. {
  1270. $this->setPhpDefaultLocale($this->locale = $locale);
  1271. }
  1272. public function getLocale()
  1273. {
  1274. return null === $this->locale ? $this->defaultLocale : $this->locale;
  1275. }
  1276. public function isMethod($method)
  1277. {
  1278. return $this->getMethod() === strtoupper($method);
  1279. }
  1280. public function isMethodSafe()
  1281. {
  1282. return in_array($this->getMethod(), array('GET', 'HEAD'));
  1283. }
  1284. public function getContent($asResource = false)
  1285. {
  1286. if (false === $this->content || true === $asResource && null !== $this->content) {
  1287. throw new \LogicException('getContent() can only be called once when using the resource return type.');
  1288. }
  1289. if (true === $asResource) {
  1290. $this->content = false;
  1291. return fopen('php://input', 'rb');
  1292. }
  1293. if (null === $this->content) {
  1294. $this->content = file_get_contents('php://input');
  1295. }
  1296. return $this->content;
  1297. }
  1298. public function getETags()
  1299. {
  1300. return preg_split('/\\s*,\\s*/', $this->headers->get('if_none_match'), null, PREG_SPLIT_NO_EMPTY);
  1301. }
  1302. public function isNoCache()
  1303. {
  1304. return $this->headers->hasCacheControlDirective('no-cache') || 'no-cache' == $this->headers->get('Pragma');
  1305. }
  1306. public function getPreferredLanguage(array $locales = null)
  1307. {
  1308. $preferredLanguages = $this->getLanguages();
  1309. if (empty($locales)) {
  1310. return isset($preferredLanguages[0]) ? $preferredLanguages[0] : null;
  1311. }
  1312. if (!$preferredLanguages) {
  1313. return $locales[0];
  1314. }
  1315. $extendedPreferredLanguages = array();
  1316. foreach ($preferredLanguages as $language) {
  1317. $extendedPreferredLanguages[] = $language;
  1318. if (false !== ($position = strpos($language, '_'))) {
  1319. $superLanguage = substr($language, 0, $position);
  1320. if (!in_array($superLanguage, $preferredLanguages)) {
  1321. $extendedPreferredLanguages[] = $superLanguage;
  1322. }
  1323. }
  1324. }
  1325. $preferredLanguages = array_values(array_intersect($extendedPreferredLanguages, $locales));
  1326. return isset($preferredLanguages[0]) ? $preferredLanguages[0] : $locales[0];
  1327. }
  1328. public function getLanguages()
  1329. {
  1330. if (null !== $this->languages) {
  1331. return $this->languages;
  1332. }
  1333. $languages = AcceptHeader::fromString($this->headers->get('Accept-Language'))->all();
  1334. $this->languages = array();
  1335. foreach (array_keys($languages) as $lang) {
  1336. if (strstr($lang, '-')) {
  1337. $codes = explode('-', $lang);
  1338. if ($codes[0] == 'i') {
  1339. if (count($codes) > 1) {
  1340. $lang = $codes[1];
  1341. }
  1342. } else {
  1343. for ($i = 0, $max = count($codes); $i < $max; $i++) {
  1344. if ($i == 0) {
  1345. $lang = strtolower($codes[0]);
  1346. } else {
  1347. $lang .= '_' . strtoupper($codes[$i]);
  1348. }
  1349. }
  1350. }
  1351. }
  1352. $this->languages[] = $lang;
  1353. }
  1354. return $this->languages;
  1355. }
  1356. public function getCharsets()
  1357. {
  1358. if (null !== $this->charsets) {
  1359. return $this->charsets;
  1360. }
  1361. return $this->charsets = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Charset'))->all());
  1362. }
  1363. public function getAcceptableContentTypes()
  1364. {
  1365. if (null !== $this->acceptableContentTypes) {
  1366. return $this->acceptableContentTypes;
  1367. }
  1368. return $this->acceptableContentTypes = array_keys(AcceptHeader::fromString($this->headers->get('Accept'))->all());
  1369. }
  1370. public function isXmlHttpRequest()
  1371. {
  1372. return 'XMLHttpRequest' == $this->headers->get('X-Requested-With');
  1373. }
  1374. protected function prepareRequestUri()
  1375. {
  1376. $requestUri = '';
  1377. if ($this->headers->has('X_ORIGINAL_URL')) {
  1378. $requestUri = $this->headers->get('X_ORIGINAL_URL');
  1379. $this->headers->remove('X_ORIGINAL_URL');
  1380. $this->server->remove('HTTP_X_ORIGINAL_URL');
  1381. $this->server->remove('UNENCODED_URL');
  1382. $this->server->remove('IIS_WasUrlRewritten');
  1383. } elseif ($this->headers->has('X_REWRITE_URL')) {
  1384. $requestUri = $this->headers->get('X_REWRITE_URL');
  1385. $this->headers->remove('X_REWRITE_URL');
  1386. } elseif ($this->server->get('IIS_WasUrlRewritten') == '1' && $this->server->get('UNENCODED_URL') != '') {
  1387. $requestUri = $this->server->get('UNENCODED_URL');
  1388. $this->server->remove('UNENCODED_URL');
  1389. $this->server->remove('IIS_WasUrlRewritten');
  1390. } elseif ($this->server->has('REQUEST_URI')) {
  1391. $requestUri = $this->server->get('REQUEST_URI');
  1392. $schemeAndHttpHost = $this->getSchemeAndHttpHost();
  1393. if (strpos($requestUri, $schemeAndHttpHost) === 0) {
  1394. $requestUri = substr($requestUri, strlen($schemeAndHttpHost));
  1395. }
  1396. } elseif ($this->server->has('ORIG_PATH_INFO')) {
  1397. $requestUri = $this->server->get('ORIG_PATH_INFO');
  1398. if ('' != $this->server->get('QUERY_STRING')) {
  1399. $requestUri .= '?' . $this->server->get('QUERY_STRING');
  1400. }
  1401. $this->server->remove('ORIG_PATH_INFO');
  1402. }
  1403. $this->server->set('REQUEST_URI', $requestUri);
  1404. return $requestUri;
  1405. }
  1406. protected function prepareBaseUrl()
  1407. {
  1408. $filename = basename($this->server->get('SCRIPT_FILENAME'));
  1409. if (basename($this->server->get('SCRIPT_NAME')) === $filename) {
  1410. $baseUrl = $this->server->get('SCRIPT_NAME');
  1411. } elseif (basename($this->server->get('PHP_SELF')) === $filename) {
  1412. $baseUrl = $this->server->get('PHP_SELF');
  1413. } elseif (basename($this->server->get('ORIG_SCRIPT_NAME')) === $filename) {
  1414. $baseUrl = $this->server->get('ORIG_SCRIPT_NAME');
  1415. } else {

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