/bootstrap/compiled.php
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
- <?php
- namespace Illuminate\Support;
- class ClassLoader
- {
- protected static $directories = array();
- protected static $registered = false;
- public static function load($class)
- {
- $class = static::normalizeClass($class);
- foreach (static::$directories as $directory) {
- if (file_exists($path = $directory . DIRECTORY_SEPARATOR . $class)) {
- require_once $path;
- return true;
- }
- }
- }
- public static function normalizeClass($class)
- {
- if ($class[0] == '\\') {
- $class = substr($class, 1);
- }
- return str_replace(array('\\', '_'), DIRECTORY_SEPARATOR, $class) . '.php';
- }
- public static function register()
- {
- if (!static::$registered) {
- spl_autoload_register(array('\\Illuminate\\Support\\ClassLoader', 'load'));
- static::$registered = true;
- }
- }
- public static function addDirectories($directories)
- {
- static::$directories = array_merge(static::$directories, (array) $directories);
- static::$directories = array_unique(static::$directories);
- }
- public static function removeDirectories($directories = null)
- {
- if (is_null($directories)) {
- static::$directories = array();
- } else {
- $directories = (array) $directories;
- static::$directories = array_filter(static::$directories, function ($directory) use($directories) {
- return !in_array($directory, $directories);
- });
- }
- }
- public static function getDirectories()
- {
- return static::$directories;
- }
- }
- namespace Illuminate\Container;
- use Closure, ArrayAccess, ReflectionParameter;
- class BindingResolutionException extends \Exception
- {
-
- }
- class Container implements ArrayAccess
- {
- protected $bindings = array();
- protected $instances = array();
- protected $aliases = array();
- protected $resolvingCallbacks = array();
- public function bound($abstract)
- {
- return isset($this[$abstract]) or isset($this->instances[$abstract]);
- }
- public function bind($abstract, $concrete = null, $shared = false)
- {
- if (is_array($abstract)) {
- list($abstract, $alias) = $this->extractAlias($abstract);
- $this->alias($abstract, $alias);
- }
- unset($this->instances[$abstract]);
- if (is_null($concrete)) {
- $concrete = $abstract;
- }
- if (!$concrete instanceof Closure) {
- $concrete = function ($c) use($abstract, $concrete) {
- $method = $abstract == $concrete ? 'build' : 'make';
- return $c->{$method}($concrete);
- };
- }
- $this->bindings[$abstract] = compact('concrete', 'shared');
- }
- public function bindIf($abstract, $concrete = null, $shared = false)
- {
- if (!$this->bound($abstract)) {
- $this->bind($abstract, $concrete, $shared);
- }
- }
- public function singleton($abstract, $concrete = null)
- {
- return $this->bind($abstract, $concrete, true);
- }
- public function share(Closure $closure)
- {
- return function ($container) use($closure) {
- static $object;
- if (is_null($object)) {
- $object = $closure($container);
- }
- return $object;
- };
- }
- public function extend($abstract, Closure $closure)
- {
- if (!isset($this->bindings[$abstract])) {
- throw new \InvalidArgumentException("Type {$abstract} is not bound.");
- }
- $resolver = $this->bindings[$abstract]['concrete'];
- $this->bind($abstract, function ($container) use($resolver, $closure) {
- return $closure($resolver($container), $container);
- }, $this->isShared($abstract));
- }
- public function instance($abstract, $instance)
- {
- if (is_array($abstract)) {
- list($abstract, $alias) = $this->extractAlias($abstract);
- $this->alias($abstract, $alias);
- }
- $this->instances[$abstract] = $instance;
- }
- public function alias($abstract, $alias)
- {
- $this->aliases[$alias] = $abstract;
- }
- protected function extractAlias(array $definition)
- {
- return array(key($definition), current($definition));
- }
- public function make($abstract, $parameters = array())
- {
- $abstract = $this->getAlias($abstract);
- if (isset($this->instances[$abstract])) {
- return $this->instances[$abstract];
- }
- $concrete = $this->getConcrete($abstract);
- if ($this->isBuildable($concrete, $abstract)) {
- $object = $this->build($concrete, $parameters);
- } else {
- $object = $this->make($concrete, $parameters);
- }
- if ($this->isShared($abstract)) {
- $this->instances[$abstract] = $object;
- }
- $this->fireResolvingCallbacks($object);
- return $object;
- }
- protected function getConcrete($abstract)
- {
- if (!isset($this->bindings[$abstract])) {
- return $abstract;
- } else {
- return $this->bindings[$abstract]['concrete'];
- }
- }
- public function build($concrete, $parameters = array())
- {
- if ($concrete instanceof Closure) {
- return $concrete($this, $parameters);
- }
- $reflector = new \ReflectionClass($concrete);
- if (!$reflector->isInstantiable()) {
- $message = "Target [{$concrete}] is not instantiable.";
- throw new BindingResolutionException($message);
- }
- $constructor = $reflector->getConstructor();
- if (is_null($constructor)) {
- return new $concrete();
- }
- $parameters = $constructor->getParameters();
- $dependencies = $this->getDependencies($parameters);
- return $reflector->newInstanceArgs($dependencies);
- }
- protected function getDependencies($parameters)
- {
- $dependencies = array();
- foreach ($parameters as $parameter) {
- $dependency = $parameter->getClass();
- if (is_null($dependency)) {
- $dependencies[] = $this->resolveNonClass($parameter);
- } else {
- $dependencies[] = $this->make($dependency->name);
- }
- }
- return (array) $dependencies;
- }
- protected function resolveNonClass(ReflectionParameter $parameter)
- {
- if ($parameter->isDefaultValueAvailable()) {
- return $parameter->getDefaultValue();
- } else {
- $message = "Unresolvable dependency resolving [{$parameter}].";
- throw new BindingResolutionException($message);
- }
- }
- public function resolving(Closure $callback)
- {
- $this->resolvingCallbacks[] = $callback;
- }
- protected function fireResolvingCallbacks($object)
- {
- foreach ($this->resolvingCallbacks as $callback) {
- call_user_func($callback, $object);
- }
- }
- protected function isShared($abstract)
- {
- $set = isset($this->bindings[$abstract]['shared']);
- return $set and $this->bindings[$abstract]['shared'] === true;
- }
- protected function isBuildable($concrete, $abstract)
- {
- return $concrete === $abstract or $concrete instanceof Closure;
- }
- protected function getAlias($abstract)
- {
- return isset($this->aliases[$abstract]) ? $this->aliases[$abstract] : $abstract;
- }
- public function getBindings()
- {
- return $this->bindings;
- }
- public function offsetExists($key)
- {
- return isset($this->bindings[$key]);
- }
- public function offsetGet($key)
- {
- return $this->make($key);
- }
- public function offsetSet($key, $value)
- {
- if (!$value instanceof Closure) {
- $value = function () use($value) {
- return $value;
- };
- }
- $this->bind($key, $value);
- }
- public function offsetUnset($key)
- {
- unset($this->bindings[$key]);
- }
- }
- namespace Symfony\Component\HttpKernel;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- interface HttpKernelInterface
- {
- const MASTER_REQUEST = 1;
- const SUB_REQUEST = 2;
- public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
- }
- namespace Illuminate\Support\Contracts;
- interface ResponsePreparerInterface
- {
- public function prepareResponse($value);
- }
- namespace Illuminate\Foundation;
- use Closure;
- use Illuminate\Http\Request;
- use Illuminate\Http\Response;
- use Illuminate\Routing\Route;
- use Illuminate\Routing\Router;
- use Illuminate\Config\FileLoader;
- use Illuminate\Container\Container;
- use Illuminate\Filesystem\Filesystem;
- use Illuminate\Support\Facades\Facade;
- use Illuminate\Support\ServiceProvider;
- use Illuminate\Events\EventServiceProvider;
- use Illuminate\Foundation\ProviderRepository;
- use Illuminate\Routing\RoutingServiceProvider;
- use Illuminate\Exception\ExceptionServiceProvider;
- use Symfony\Component\HttpFoundation\JsonResponse;
- use Symfony\Component\HttpKernel\HttpKernelInterface;
- use Symfony\Component\HttpFoundation\StreamedResponse;
- use Symfony\Component\HttpKernel\Exception\HttpException;
- use Illuminate\Support\Contracts\ResponsePreparerInterface;
- use Symfony\Component\HttpKernel\Exception\FatalErrorException;
- use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
- use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
- use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
- use Symfony\Component\HttpFoundation\RedirectResponse as SymfonyRedirect;
- class Application extends Container implements HttpKernelInterface, ResponsePreparerInterface
- {
- const VERSION = '4.0.0';
- protected $booted = false;
- protected $bootingCallbacks = array();
- protected $bootedCallbacks = array();
- protected $shutdownCallbacks = array();
- protected $serviceProviders = array();
- protected $loadedProviders = array();
- protected $deferredServices = array();
- public function __construct(Request $request = null)
- {
- $this['request'] = $this->createRequest($request);
- $this->register(new ExceptionServiceProvider($this));
- $this->register(new RoutingServiceProvider($this));
- $this->register(new EventServiceProvider($this));
- }
- protected function createRequest(Request $request = null)
- {
- return $request ?: Request::createFromGlobals();
- }
- public function setRequestForConsoleEnvironment()
- {
- $url = $this['config']->get('app.url', 'http://localhost');
- $this->instance('request', Request::create($url, 'GET', array(), array(), array(), $_SERVER));
- }
- public function redirectIfTrailingSlash()
- {
- if ($this->runningInConsole()) {
- return;
- }
- $path = $this['request']->getPathInfo();
- if ($path != '/' and ends_with($path, '/') and !ends_with($path, '//')) {
- with(new SymfonyRedirect($this['request']->fullUrl(), 301))->send();
- die;
- }
- }
- public function bindInstallPaths(array $paths)
- {
- $this->instance('path', realpath($paths['app']));
- foreach (array_except($paths, array('app')) as $key => $value) {
- $this->instance("path.{$key}", realpath($value));
- }
- }
- public static function getBootstrapFile()
- {
- return 'C:\\wamp\\www\\starter-kit-fr\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation' . '/start.php';
- }
- public function startExceptionHandling()
- {
- $this['exception']->register($this->environment());
- $this['exception']->setDebug($this['config']['app.debug']);
- }
- public function environment()
- {
- return $this['env'];
- }
- public function detectEnvironment($environments)
- {
- $base = $this['request']->getHost();
- $arguments = $this['request']->server->get('argv');
- if ($this->runningInConsole()) {
- return $this->detectConsoleEnvironment($base, $environments, $arguments);
- }
- return $this->detectWebEnvironment($base, $environments);
- }
- protected function detectWebEnvironment($base, $environments)
- {
- if ($environments instanceof Closure) {
- return $this['env'] = call_user_func($environments);
- }
- foreach ($environments as $environment => $hosts) {
- foreach ((array) $hosts as $host) {
- if (str_is($host, $base) or $this->isMachine($host)) {
- return $this['env'] = $environment;
- }
- }
- }
- return $this['env'] = 'production';
- }
- protected function detectConsoleEnvironment($base, $environments, $arguments)
- {
- foreach ($arguments as $key => $value) {
- if (starts_with($value, '--env=')) {
- $segments = array_slice(explode('=', $value), 1);
- return $this['env'] = head($segments);
- }
- }
- return $this->detectWebEnvironment($base, $environments);
- }
- protected function isMachine($name)
- {
- return str_is($name, gethostname());
- }
- public function runningInConsole()
- {
- return php_sapi_name() == 'cli';
- }
- public function runningUnitTests()
- {
- return $this['env'] == 'testing';
- }
- public function register($provider, $options = array())
- {
- if (is_string($provider)) {
- $provider = $this->resolveProviderClass($provider);
- }
- $provider->register();
- foreach ($options as $key => $value) {
- $this[$key] = $value;
- }
- $this->serviceProviders[] = $provider;
- $this->loadedProviders[get_class($provider)] = true;
- }
- protected function resolveProviderClass($provider)
- {
- return new $provider($this);
- }
- public function loadDeferredProviders()
- {
- foreach (array_unique($this->deferredServices) as $provider) {
- $this->register($instance = new $provider($this));
- if ($this->booted) {
- $instance->boot();
- }
- }
- $this->deferredServices = array();
- }
- protected function loadDeferredProvider($service)
- {
- $provider = $this->deferredServices[$service];
- if (!isset($this->loadedProviders[$provider])) {
- $this->register($instance = new $provider($this));
- unset($this->deferredServices[$service]);
- $this->setupDeferredBoot($instance);
- }
- }
- protected function setupDeferredBoot($instance)
- {
- if ($this->booted) {
- return $instance->boot();
- }
- $this->booting(function () use($instance) {
- $instance->boot();
- });
- }
- public function make($abstract, $parameters = array())
- {
- if (isset($this->deferredServices[$abstract])) {
- $this->loadDeferredProvider($abstract);
- }
- return parent::make($abstract, $parameters);
- }
- public function before($callback)
- {
- return $this['router']->before($callback);
- }
- public function after($callback)
- {
- return $this['router']->after($callback);
- }
- public function close($callback)
- {
- return $this['router']->close($callback);
- }
- public function finish($callback)
- {
- $this['router']->finish($callback);
- }
- public function shutdown($callback = null)
- {
- if (is_null($callback)) {
- $this->fireAppCallbacks($this->shutdownCallbacks);
- } else {
- $this->shutdownCallbacks[] = $callback;
- }
- }
- public function run()
- {
- $response = $this->dispatch($this['request']);
- $this['router']->callCloseFilter($this['request'], $response);
- $response->send();
- $this['router']->callFinishFilter($this['request'], $response);
- }
- public function dispatch(Request $request)
- {
- if ($this->isDownForMaintenance()) {
- $response = $this['events']->until('illuminate.app.down');
- return $this->prepareResponse($response, $request);
- } else {
- return $this['router']->dispatch($this->prepareRequest($request));
- }
- }
- public function handle(SymfonyRequest $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
- {
- $this->instance('request', $request);
- Facade::clearResolvedInstance('request');
- return $this->dispatch($request);
- }
- public function boot()
- {
- if ($this->booted) {
- return;
- }
- foreach ($this->serviceProviders as $provider) {
- $provider->boot();
- }
- $this->fireAppCallbacks($this->bootingCallbacks);
- $this->booted = true;
- $this->fireAppCallbacks($this->bootedCallbacks);
- }
- public function booting($callback)
- {
- $this->bootingCallbacks[] = $callback;
- }
- public function booted($callback)
- {
- $this->bootedCallbacks[] = $callback;
- }
- protected function fireAppCallbacks(array $callbacks)
- {
- foreach ($callbacks as $callback) {
- call_user_func($callback, $this);
- }
- }
- public function prepareRequest(Request $request)
- {
- if (isset($this['session'])) {
- $request->setSessionStore($this['session']);
- }
- return $request;
- }
- public function prepareResponse($value)
- {
- if (!$value instanceof SymfonyResponse) {
- $value = new Response($value);
- }
- return $value->prepare($this['request']);
- }
- public function isDownForMaintenance()
- {
- return file_exists($this['path.storage'] . '/meta/down');
- }
- public function down(Closure $callback)
- {
- $this['events']->listen('illuminate.app.down', $callback);
- }
- public function abort($code, $message = '', array $headers = array())
- {
- if ($code == 404) {
- throw new NotFoundHttpException($message);
- } else {
- throw new HttpException($code, $message, null, $headers);
- }
- }
- public function missing(Closure $callback)
- {
- $this->error(function (NotFoundHttpException $e) use($callback) {
- return call_user_func($callback, $e);
- });
- }
- public function error(Closure $callback)
- {
- $this['exception']->error($callback);
- }
- public function fatal(Closure $callback)
- {
- $this->error(function (FatalErrorException $e) use($callback) {
- return call_user_func($callback, $e);
- });
- }
- public function getConfigLoader()
- {
- return new FileLoader(new Filesystem(), $this['path'] . '/config');
- }
- public function getProviderRepository()
- {
- $manifest = $this['config']['app.manifest'];
- return new ProviderRepository(new Filesystem(), $manifest);
- }
- public function setLocale($locale)
- {
- $this['config']->set('app.locale', $locale);
- $this['translator']->setLocale($locale);
- $this['events']->fire('locale.changed', array($locale));
- }
- public function getLoadedProviders()
- {
- return $this->loadedProviders;
- }
- public function setDeferredServices(array $services)
- {
- $this->deferredServices = $services;
- }
- public function __get($key)
- {
- return $this[$key];
- }
- public function __set($key, $value)
- {
- $this[$key] = $value;
- }
- }
- namespace Illuminate\Http;
- use Illuminate\Session\Store as SessionStore;
- use Symfony\Component\HttpFoundation\ParameterBag;
- class Request extends \Symfony\Component\HttpFoundation\Request
- {
- protected $json;
- protected $sessionStore;
- public function instance()
- {
- return $this;
- }
- public function root()
- {
- return rtrim($this->getSchemeAndHttpHost() . $this->getBaseUrl(), '/');
- }
- public function url()
- {
- return rtrim(preg_replace('/\\?.*/', '', $this->getUri()), '/');
- }
- public function fullUrl()
- {
- $query = $this->getQueryString();
- return $query ? $this->url() . '?' . $query : $this->url();
- }
- public function path()
- {
- $pattern = trim($this->getPathInfo(), '/');
- return $pattern == '' ? '/' : $pattern;
- }
- public function segment($index, $default = null)
- {
- $segments = explode('/', trim($this->getPathInfo(), '/'));
- $segments = array_filter($segments, function ($v) {
- return $v != '';
- });
- return array_get($segments, $index - 1, $default);
- }
- public function segments()
- {
- $path = $this->path();
- return $path == '/' ? array() : explode('/', $path);
- }
- public function is($pattern)
- {
- foreach (func_get_args() as $pattern) {
- if (str_is($pattern, $this->path())) {
- return true;
- }
- }
- return false;
- }
- public function ajax()
- {
- return $this->isXmlHttpRequest();
- }
- public function secure()
- {
- return $this->isSecure();
- }
- public function has($key)
- {
- if (count(func_get_args()) > 1) {
- foreach (func_get_args() as $value) {
- if (!$this->has($value)) {
- return false;
- }
- }
- return true;
- }
- if (is_array($this->input($key))) {
- return true;
- }
- return trim((string) $this->input($key)) !== '';
- }
- public function all()
- {
- return $this->input() + $this->files->all();
- }
- public function input($key = null, $default = null)
- {
- $input = $this->getInputSource()->all() + $this->query->all();
- return array_get($input, $key, $default);
- }
- public function only($keys)
- {
- $keys = is_array($keys) ? $keys : func_get_args();
- return array_only($this->input(), $keys) + array_fill_keys($keys, null);
- }
- public function except($keys)
- {
- $keys = is_array($keys) ? $keys : func_get_args();
- $results = $this->input();
- foreach ($keys as $key) {
- array_forget($results, $key);
- }
- return $results;
- }
- public function query($key = null, $default = null)
- {
- return $this->retrieveItem('query', $key, $default);
- }
- public function cookie($key = null, $default = null)
- {
- return $this->retrieveItem('cookies', $key, $default);
- }
- public function file($key = null, $default = null)
- {
- return $this->retrieveItem('files', $key, $default);
- }
- public function hasFile($key)
- {
- return $this->files->has($key) and !is_null($this->file($key));
- }
- public function header($key = null, $default = null)
- {
- return $this->retrieveItem('headers', $key, $default);
- }
- public function server($key = null, $default = null)
- {
- return $this->retrieveItem('server', $key, $default);
- }
- public function old($key = null, $default = null)
- {
- return $this->getSessionStore()->getOldInput($key, $default);
- }
- public function flash($filter = null, $keys = array())
- {
- $flash = !is_null($filter) ? $this->{$filter}($keys) : $this->input();
- $this->getSessionStore()->flashInput($flash);
- }
- public function flashOnly($keys)
- {
- $keys = is_array($keys) ? $keys : func_get_args();
- return $this->flash('only', $keys);
- }
- public function flashExcept($keys)
- {
- $keys = is_array($keys) ? $keys : func_get_args();
- return $this->flash('except', $keys);
- }
- public function flush()
- {
- $this->getSessionStore()->flashInput(array());
- }
- protected function retrieveItem($source, $key, $default)
- {
- if (is_null($key)) {
- return $this->{$source}->all();
- } else {
- return $this->{$source}->get($key, $default, true);
- }
- }
- public function merge(array $input)
- {
- $this->getInputSource()->add($input);
- }
- public function replace(array $input)
- {
- $this->getInputSource()->replace($input);
- }
- public function json($key = null, $default = null)
- {
- if (!isset($this->json)) {
- $this->json = new ParameterBag((array) json_decode($this->getContent(), true));
- }
- if (is_null($key)) {
- return $this->json;
- }
- return array_get($this->json->all(), $key, $default);
- }
- protected function getInputSource()
- {
- if ($this->isJson()) {
- return $this->json();
- }
- return $this->getMethod() == 'GET' ? $this->query : $this->request;
- }
- public function isJson()
- {
- return str_contains($this->header('CONTENT_TYPE'), '/json');
- }
- public function wantsJson()
- {
- $acceptable = $this->getAcceptableContentTypes();
- return isset($acceptable[0]) and $acceptable[0] == 'application/json';
- }
- public function getSessionStore()
- {
- if (!isset($this->sessionStore)) {
- throw new \RuntimeException('Session store not set on request.');
- }
- return $this->sessionStore;
- }
- public function setSessionStore(SessionStore $session)
- {
- $this->sessionStore = $session;
- }
- public function hasSessionStore()
- {
- return isset($this->sessionStore);
- }
- }
- namespace Symfony\Component\HttpFoundation;
- use Symfony\Component\HttpFoundation\Session\SessionInterface;
- class Request
- {
- const HEADER_CLIENT_IP = 'client_ip';
- const HEADER_CLIENT_HOST = 'client_host';
- const HEADER_CLIENT_PROTO = 'client_proto';
- const HEADER_CLIENT_PORT = 'client_port';
- protected static $trustedProxies = array();
- 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');
- protected static $httpMethodParameterOverride = false;
- public $attributes;
- public $request;
- public $query;
- public $server;
- public $files;
- public $cookies;
- public $headers;
- protected $content;
- protected $languages;
- protected $charsets;
- protected $acceptableContentTypes;
- protected $pathInfo;
- protected $requestUri;
- protected $baseUrl;
- protected $basePath;
- protected $method;
- protected $format;
- protected $session;
- protected $locale;
- protected $defaultLocale = 'en';
- protected static $formats;
- public function __construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
- {
- $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content);
- }
- public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
- {
- $this->request = new ParameterBag($request);
- $this->query = new ParameterBag($query);
- $this->attributes = new ParameterBag($attributes);
- $this->cookies = new ParameterBag($cookies);
- $this->files = new FileBag($files);
- $this->server = new ServerBag($server);
- $this->headers = new HeaderBag($this->server->getHeaders());
- $this->content = $content;
- $this->languages = null;
- $this->charsets = null;
- $this->acceptableContentTypes = null;
- $this->pathInfo = null;
- $this->requestUri = null;
- $this->baseUrl = null;
- $this->basePath = null;
- $this->method = null;
- $this->format = null;
- }
- public static function createFromGlobals()
- {
- $request = new static($_GET, $_POST, array(), $_COOKIE, $_FILES, $_SERVER);
- 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'))) {
- parse_str($request->getContent(), $data);
- $request->request = new ParameterBag($data);
- }
- return $request;
- }
- public static function create($uri, $method = 'GET', $parameters = array(), $cookies = array(), $files = array(), $server = array(), $content = null)
- {
- $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);
- $server['PATH_INFO'] = '';
- $server['REQUEST_METHOD'] = strtoupper($method);
- $components = parse_url($uri);
- if (isset($components['host'])) {
- $server['SERVER_NAME'] = $components['host'];
- $server['HTTP_HOST'] = $components['host'];
- }
- if (isset($components['scheme'])) {
- if ('https' === $components['scheme']) {
- $server['HTTPS'] = 'on';
- $server['SERVER_PORT'] = 443;
- } else {
- unset($server['HTTPS']);
- $server['SERVER_PORT'] = 80;
- }
- }
- if (isset($components['port'])) {
- $server['SERVER_PORT'] = $components['port'];
- $server['HTTP_HOST'] = $server['HTTP_HOST'] . ':' . $components['port'];
- }
- if (isset($components['user'])) {
- $server['PHP_AUTH_USER'] = $components['user'];
- }
- if (isset($components['pass'])) {
- $server['PHP_AUTH_PW'] = $components['pass'];
- }
- if (!isset($components['path'])) {
- $components['path'] = '/';
- }
- switch (strtoupper($method)) {
- case 'POST':
- case 'PUT':
- case 'DELETE':
- if (!isset($server['CONTENT_TYPE'])) {
- $server['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
- }
- case 'PATCH':
- $request = $parameters;
- $query = array();
- break;
- default:
- $request = array();
- $query = $parameters;
- break;
- }
- if (isset($components['query'])) {
- parse_str(html_entity_decode($components['query']), $qs);
- $query = array_replace($qs, $query);
- }
- $queryString = http_build_query($query, '', '&');
- $server['REQUEST_URI'] = $components['path'] . ('' !== $queryString ? '?' . $queryString : '');
- $server['QUERY_STRING'] = $queryString;
- return new static($query, $request, array(), $cookies, $files, $server, $content);
- }
- public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
- {
- $dup = clone $this;
- if ($query !== null) {
- $dup->query = new ParameterBag($query);
- }
- if ($request !== null) {
- $dup->request = new ParameterBag($request);
- }
- if ($attributes !== null) {
- $dup->attributes = new ParameterBag($attributes);
- }
- if ($cookies !== null) {
- $dup->cookies = new ParameterBag($cookies);
- }
- if ($files !== null) {
- $dup->files = new FileBag($files);
- }
- if ($server !== null) {
- $dup->server = new ServerBag($server);
- $dup->headers = new HeaderBag($dup->server->getHeaders());
- }
- $dup->languages = null;
- $dup->charsets = null;
- $dup->acceptableContentTypes = null;
- $dup->pathInfo = null;
- $dup->requestUri = null;
- $dup->baseUrl = null;
- $dup->basePath = null;
- $dup->method = null;
- $dup->format = null;
- return $dup;
- }
- public function __clone()
- {
- $this->query = clone $this->query;
- $this->request = clone $this->request;
- $this->attributes = clone $this->attributes;
- $this->cookies = clone $this->cookies;
- $this->files = clone $this->files;
- $this->server = clone $this->server;
- $this->headers = clone $this->headers;
- }
- public function __toString()
- {
- return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL')) . '
- ' . $this->headers . '
- ' . $this->getContent();
- }
- public function overrideGlobals()
- {
- $_GET = $this->query->all();
- $_POST = $this->request->all();
- $_SERVER = $this->server->all();
- $_COOKIE = $this->cookies->all();
- foreach ($this->headers->all() as $key => $value) {
- $key = strtoupper(str_replace('-', '_', $key));
- if (in_array($key, array('CONTENT_TYPE', 'CONTENT_LENGTH'))) {
- $_SERVER[$key] = implode(', ', $value);
- } else {
- $_SERVER['HTTP_' . $key] = implode(', ', $value);
- }
- }
- $request = array('g' => $_GET, 'p' => $_POST, 'c' => $_COOKIE);
- $requestOrder = ini_get('request_order') ?: ini_get('variable_order');
- $requestOrder = preg_replace('#[^cgp]#', '', strtolower($requestOrder)) ?: 'gp';
- $_REQUEST = array();
- foreach (str_split($requestOrder) as $order) {
- $_REQUEST = array_merge($_REQUEST, $request[$order]);
- }
- }
- public static function setTrustedProxies(array $proxies)
- {
- self::$trustedProxies = $proxies;
- }
- public static function getTrustedProxies()
- {
- return self::$trustedProxies;
- }
- public static function setTrustedHeaderName($key, $value)
- {
- if (!array_key_exists($key, self::$trustedHeaders)) {
- throw new \InvalidArgumentException(sprintf('Unable to set the trusted header name for key "%s".', $key));
- }
- self::$trustedHeaders[$key] = $value;
- }
- public static function getTrustedHeaderName($key)
- {
- if (!array_key_exists($key, self::$trustedHeaders)) {
- throw new \InvalidArgumentException(sprintf('Unable to get the trusted header name for key "%s".', $key));
- }
- return self::$trustedHeaders[$key];
- }
- public static function normalizeQueryString($qs)
- {
- if ('' == $qs) {
- return '';
- }
- $parts = array();
- $order = array();
- foreach (explode('&', $qs) as $param) {
- if ('' === $param || '=' === $param[0]) {
- continue;
- }
- $keyValuePair = explode('=', $param, 2);
- $parts[] = isset($keyValuePair[1]) ? rawurlencode(urldecode($keyValuePair[0])) . '=' . rawurlencode(urldecode($keyValuePair[1])) : rawurlencode(urldecode($keyValuePair[0]));
- $order[] = urldecode($keyValuePair[0]);
- }
- array_multisort($order, SORT_ASC, $parts);
- return implode('&', $parts);
- }
- public static function enableHttpMethodParameterOverride()
- {
- self::$httpMethodParameterOverride = true;
- }
- public static function getHttpMethodParameterOverride()
- {
- return self::$httpMethodParameterOverride;
- }
- public function get($key, $default = null, $deep = false)
- {
- return $this->query->get($key, $this->attributes->get($key, $this->request->get($key, $default, $deep), $deep), $deep);
- }
- public function getSession()
- {
- return $this->session;
- }
- public function hasPreviousSession()
- {
- return $this->hasSession() && $this->cookies->has($this->session->getName());
- }
- public function hasSession()
- {
- return null !== $this->session;
- }
- public function setSession(SessionInterface $session)
- {
- $this->session = $session;
- }
- public function getClientIps()
- {
- $ip = $this->server->get('REMOTE_ADDR');
- if (!self::$trustedProxies) {
- return array($ip);
- }
- if (!self::$trustedHeaders[self::HEADER_CLIENT_IP] || !$this->headers->has(self::$trustedHeaders[self::HEADER_CLIENT_IP])) {
- return array($ip);
- }
- $clientIps = array_map('trim', explode(',', $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_IP])));
- $clientIps[] = $ip;
- $trustedProxies = !self::$trustedProxies ? array($ip) : self::$trustedProxies;
- $ip = $clientIps[0];
- foreach ($clientIps as $key => $clientIp) {
- if (IpUtils::checkIp($clientIp, $trustedProxies)) {
- unset($clientIps[$key]);
- continue;
- }
- }
- return $clientIps ? array_reverse($clientIps) : array($ip);
- }
- public function getClientIp()
- {
- $ipAddresses = $this->getClientIps();
- return $ipAddresses[0];
- }
- public function getScriptName()
- {
- return $this->server->get('SCRIPT_NAME', $this->server->get('ORIG_SCRIPT_NAME', ''));
- }
- public function getPathInfo()
- {
- if (null === $this->pathInfo) {
- $this->pathInfo = $this->preparePathInfo();
- }
- return $this->pathInfo;
- }
- public function getBasePath()
- {
- if (null === $this->basePath) {
- $this->basePath = $this->prepareBasePath();
- }
- return $this->basePath;
- }
- public function getBaseUrl()
- {
- if (null === $this->baseUrl) {
- $this->baseUrl = $this->prepareBaseUrl();
- }
- return $this->baseUrl;
- }
- public function getScheme()
- {
- return $this->isSecure() ? 'https' : 'http';
- }
- public function getPort()
- {
- if (self::$trustedProxies) {
- if (self::$trustedHeaders[self::HEADER_CLIENT_PORT] && ($port = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PORT]))) {
- return $port;
- }
- if (self::$trustedHeaders[self::HEADER_CLIENT_PROTO] && 'https' === $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO], 'http')) {
- return 443;
- }
- }
- return $this->server->get('SERVER_PORT');
- }
- public function getUser()
- {
- return $this->server->get('PHP_AUTH_USER');
- }
- public function getPassword()
- {
- return $this->server->get('PHP_AUTH_PW');
- }
- public function getUserInfo()
- {
- $userinfo = $this->getUser();
- $pass = $this->getPassword();
- if ('' != $pass) {
- $userinfo .= ":{$pass}";
- }
- return $userinfo;
- }
- public function getHttpHost()
- {
- $scheme = $this->getScheme();
- $port = $this->getPort();
- if ('http' == $scheme && $port == 80 || 'https' == $scheme && $port == 443) {
- return $this->getHost();
- }
- return $this->getHost() . ':' . $port;
- }
- public function getRequestUri()
- {
- if (null === $this->requestUri) {
- $this->requestUri = $this->prepareRequestUri();
- }
- return $this->requestUri;
- }
- public function getSchemeAndHttpHost()
- {
- return $this->getScheme() . '://' . $this->getHttpHost();
- }
- public function getUri()
- {
- if (null !== ($qs = $this->getQueryString())) {
- $qs = '?' . $qs;
- }
- return $this->getSchemeAndHttpHost() . $this->getBaseUrl() . $this->getPathInfo() . $qs;
- }
- public function getUriForPath($path)
- {
- return $this->getSchemeAndHttpHost() . $this->getBaseUrl() . $path;
- }
- public function getQueryString()
- {
- $qs = static::normalizeQueryString($this->server->get('QUERY_STRING'));
- return '' === $qs ? null : $qs;
- }
- public function isSecure()
- {
- if (self::$trustedProxies && self::$trustedHeaders[self::HEADER_CLIENT_PROTO] && ($proto = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO]))) {
- return in_array(strtolower($proto), array('https', 'on', '1'));
- }
- return 'on' == strtolower($this->server->get('HTTPS')) || 1 == $this->server->get('HTTPS');
- }
- public function getHost()
- {
- if (self::$trustedProxies && self::$trustedHeaders[self::HEADER_CLIENT_HOST] && ($host = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_HOST]))) {
- $elements = explode(',', $host);
- $host = $elements[count($elements) - 1];
- } elseif (!($host = $this->headers->get('HOST'))) {
- if (!($host = $this->server->get('SERVER_NAME'))) {
- $host = $this->server->get('SERVER_ADDR', '');
- }
- }
- $host = strtolower(preg_replace('/:\\d+$/', '', trim($host)));
- if ($host && !preg_match('/^\\[?(?:[a-zA-Z0-9-:\\]_]+\\.?)+$/', $host)) {
- throw new \UnexpectedValueException('Invalid Host');
- }
- return $host;
- }
- public function setMethod($method)
- {
- $this->method = null;
- $this->server->set('REQUEST_METHOD', $method);
- }
- public function getMethod()
- {
- if (null === $this->method) {
- $this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
- if ('POST' === $this->method) {
- if ($method = $this->headers->get('X-HTTP-METHOD-OVERRIDE')) {
- $this->method = strtoupper($method);
- } elseif (self::$httpMethodParameterOverride) {
- $this->method = strtoupper($this->request->get('_method', $this->query->get('_method', 'POST')));
- }
- }
- }
- return $this->method;
- }
- public function getRealMethod()
- {
- return strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
- }
- public function getMimeType($format)
- {
- if (null === static::$formats) {
- static::initializeFormats();
- }
- return isset(static::$formats[$format]) ? static::$formats[$format][0] : null;
- }
- public function getFormat($mimeType)
- {
- if (false !== ($pos = strpos($mimeType, ';'))) {
- $mimeType = substr($mimeType, 0, $pos);
- }
- if (null === static::$formats) {
- static::initializeFormats();
- }
- foreach (static::$formats as $format => $mimeTypes) {
- if (in_array($mimeType, (array) $mimeTypes)) {
- return $format;
- }
- }
- return null;
- }
- public function setFormat($format, $mimeTypes)
- {
- if (null === static::$formats) {
- static::initializeFormats();
- }
- static::$formats[$format] = is_array($mimeTypes) ? $mimeTypes : array($mimeTypes);
- }
- public function getRequestFormat($default = 'html')
- {
- if (null === $this->format) {
- $this->format = $this->get('_format', $default);
- }
- return $this->format;
- }
- public function setRequestFormat($format)
- {
- $this->format = $format;
- }
- public function getContentType()
- {
- return $this->getFormat($this->headers->get('CONTENT_TYPE'));
- }
- public function setDefaultLocale($locale)
- {
- $this->defaultLocale = $locale;
- if (null === $this->locale) {
- $this->setPhpDefaultLocale($locale);
- }
- }
- public function setLocale($locale)
- {
- $this->setPhpDefaultLocale($this->locale = $locale);
- }
- public function getLocale()
- {
- return null === $this->locale ? $this->defaultLocale : $this->locale;
- }
- public function isMethod($method)
- {
- return $this->getMethod() === strtoupper($method);
- }
- public function isMethodSafe()
- {
- return in_array($this->getMethod(), array('GET', 'HEAD'));
- }
- public function getContent($asResource = false)
- {
- if (false === $this->content || true === $asResource && null !== $this->content) {
- throw new \LogicException('getContent() can only be called once when using the resource return type.');
- }
- if (true === $asResource) {
- $this->content = false;
- return fopen('php://input', 'rb');
- }
- if (null === $this->content) {
- $this->content = file_get_contents('php://input');
- }
- return $this->content;
- }
- public function getETags()
- {
- return preg_split('/\\s*,\\s*/', $this->headers->get('if_none_match'), null, PREG_SPLIT_NO_EMPTY);
- }
- public function isNoCache()
- {
- return $this->headers->hasCacheControlDirective('no-cache') || 'no-cache' == $this->headers->get('Pragma');
- }
- public function getPreferredLanguage(array $locales = null)
- {
- $preferredLanguages = $this->getLanguages();
- if (empty($locales)) {
- return isset($preferredLanguages[0]) ? $preferredLanguages[0] : null;
- }
- if (!$preferredLanguages) {
- return $locales[0];
- }
- $extendedPreferredLanguages = array();
- foreach ($preferredLanguages as $language) {
- $extendedPreferredLanguages[] = $language;
- if (false !== ($position = strpos($language, '_'))) {
- $superLanguage = substr($language, 0, $position);
- if (!in_array($superLanguage, $preferredLanguages)) {
- $extendedPreferredLanguages[] = $superLanguage;
- }
- }
- }
- $preferredLanguages = array_values(array_intersect($extendedPreferredLanguages, $locales));
- return isset($preferredLanguages[0]) ? $preferredLanguages[0] : $locales[0];
- }
- public function getLanguages()
- {
- if (null !== $this->languages) {
- return $this->languages;
- }
- $languages = AcceptHeader::fromString($this->headers->get('Accept-Language'))->all();
- $this->languages = array();
- foreach (array_keys($languages) as $lang) {
- if (strstr($lang, '-')) {
- $codes = explode('-', $lang);
- if ($codes[0] == 'i') {
- if (count($codes) > 1) {
- $lang = $codes[1];
- }
- } else {
- for ($i = 0, $max = count($codes); $i < $max; $i++) {
- if ($i == 0) {
- $lang = strtolower($codes[0]);
- } else {
- $lang .= '_' . strtoupper($codes[$i]);
- }
- }
- }
- }
- $this->languages[] = $lang;
- }
- return $this->languages;
- }
- public function getCharsets()
- {
- if (null !== $this->charsets) {
- return $this->charsets;
- }
- return $this->charsets = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Charset'))->all());
- }
- public function getAcceptableContentTypes()
- {
- if (null !== $this->acceptableContentTypes) {
- return $this->acceptableContentTypes;
- }
- return $this->acceptableContentTypes = array_keys(AcceptHeader::fromString($this->headers->get('Accept'))->all());
- }
- public function isXmlHttpRequest()
- {
- return 'XMLHttpRequest' == $this->headers->get('X-Requested-With');
- }
- protected function prepareRequestUri()
- {
- $requestUri = '';
- if ($this->headers->has('X_ORIGINAL_URL')) {
- $requestUri = $this->headers->get('X_ORIGINAL_URL');
- $this->headers->remove('X_ORIGINAL_URL');
- $this->server->remove('HTTP_X_ORIGINAL_URL');
- $this->server->remove('UNENCODED_URL');
- $this->server->remove('IIS_WasUrlRewritten');
- } elseif ($this->headers->has('X_REWRITE_URL')) {
- $requestUri = $this->headers->get('X_REWRITE_URL');
- $this->headers->remove('X_REWRITE_URL');
- } elseif ($this->server->get('IIS_WasUrlRewritten') == '1' && $this->server->get('UNENCODED_URL') != '') {
- $requestUri = $this->server->get('UNENCODED_URL');
- $this->server->remove('UNENCODED_URL');
- $this->server->remove('IIS_WasUrlRewritten');
- } elseif ($this->server->has('REQUEST_URI')) {
- $requestUri = $this->server->get('REQUEST_URI');
- $schemeAndHttpHost = $this->getSchemeAndHttpHost();
- if (strpos($requestUri, $schemeAndHttpHost) === 0) {
- $requestUri = substr($requestUri, strlen($schemeAndHttpHost));
- }
- } elseif ($this->server->has('ORIG_PATH_INFO')) {
- $requestUri = $this->server->get('ORIG_PATH_INFO');
- if ('' != $this->server->get('QUERY_STRING')) {
- $requestUri .= '?' . $this->server->get('QUERY_STRING');
- }
- $this->server->remove('ORIG_PATH_INFO');
- }
- $this->server->set('REQUEST_URI', $requestUri);
- return $requestUri;
- }
- protected function prepareBaseUrl()
- {
- $filename = basename($this->server->get('SCRIPT_FILENAME'));
- if (basename($this->server->get('SCRIPT_NAME')) === $filename) {
- $baseUrl = $this->server->get('SCRIPT_NAME');
- } elseif (basename($this->server->get('PHP_SELF')) === $filename) {
- $baseUrl = $this->server->get('PHP_SELF');
- } elseif (basename($this->server->get('ORIG_SCRIPT_NAME')) === $filename) {
- $baseUrl = $this->server->get('ORIG_SCRIPT_NAME');
- } else {
- …
Large files files are truncated, but you can click here to view the full file