update for version 1.0.1

This commit is contained in:
sujitprasad
2015-10-23 14:15:29 +05:30
parent 82b878e93b
commit 3d425dc380
8348 changed files with 10020 additions and 4171 deletions

View File

@@ -0,0 +1,36 @@
<?php namespace Illuminate\Http\Exception;
use RuntimeException;
use Symfony\Component\HttpFoundation\Response;
class HttpResponseException extends RuntimeException {
/**
* The underlying response instance.
*
* @var \Symfony\Component\HttpFoundation\Response
*/
protected $response;
/**
* Create a new HTTP response exception instance.
*
* @param \Symfony\Component\HttpFoundation\Response $response
* @return void
*/
public function __construct(Response $response)
{
$this->response = $response;
}
/**
* Get the underlying response instance.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function getResponse()
{
return $this->response;
}
}

View File

@@ -0,0 +1,5 @@
<?php namespace Illuminate\Http\Exception;
use Exception;
class PostTooLargeException extends Exception {}

View File

@@ -0,0 +1,79 @@
<?php namespace Illuminate\Http;
use Illuminate\Contracts\Support\Jsonable;
use Symfony\Component\HttpFoundation\JsonResponse as BaseJsonResponse;
class JsonResponse extends BaseJsonResponse {
use ResponseTrait;
/**
* The json encoding options.
*
* @var int
*/
protected $jsonOptions;
/**
* Constructor.
*
* @param mixed $data
* @param int $status
* @param array $headers
* @param int $options
*/
public function __construct($data = null, $status = 200, $headers = array(), $options = 0)
{
$this->jsonOptions = $options;
parent::__construct($data, $status, $headers);
}
/**
* Get the json_decoded data from the response.
*
* @param bool $assoc
* @param int $depth
* @return mixed
*/
public function getData($assoc = false, $depth = 512)
{
return json_decode($this->data, $assoc, $depth);
}
/**
* {@inheritdoc}
*/
public function setData($data = array())
{
$this->data = $data instanceof Jsonable
? $data->toJson($this->jsonOptions)
: json_encode($data, $this->jsonOptions);
return $this->update();
}
/**
* Get the JSON encoding options.
*
* @return int
*/
public function getJsonOptions()
{
return $this->jsonOptions;
}
/**
* Set the JSON encoding options.
*
* @param int $options
* @return mixed
*/
public function setJsonOptions($options)
{
$this->jsonOptions = $options;
return $this->setData($this->getData());
}
}

View File

@@ -0,0 +1,24 @@
<?php namespace Illuminate\Http\Middleware;
use Closure;
use Illuminate\Contracts\Routing\Middleware;
class FrameGuard implements Middleware {
/**
* Handle the given request and get the response.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Illuminate\Http\Response
*/
public function handle($request, Closure $next)
{
$response = $next($request);
$response->headers->set('X-Frame-Options', 'SAMEORIGIN', false);
return $response;
}
}

View File

@@ -0,0 +1,204 @@
<?php namespace Illuminate\Http;
use BadMethodCallException;
use Illuminate\Support\MessageBag;
use Illuminate\Support\ViewErrorBag;
use Illuminate\Session\Store as SessionStore;
use Illuminate\Contracts\Support\MessageProvider;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\RedirectResponse as BaseRedirectResponse;
class RedirectResponse extends BaseRedirectResponse {
use ResponseTrait;
/**
* The request instance.
*
* @var \Illuminate\Http\Request
*/
protected $request;
/**
* The session store implementation.
*
* @var \Illuminate\Session\Store
*/
protected $session;
/**
* Flash a piece of data to the session.
*
* @param string $key
* @param mixed $value
* @return \Illuminate\Http\RedirectResponse
*/
public function with($key, $value = null)
{
$key = is_array($key) ? $key : [$key => $value];
foreach ($key as $k => $v)
{
$this->session->flash($k, $v);
}
return $this;
}
/**
* Add multiple cookies to the response.
*
* @param array $cookies
* @return $this
*/
public function withCookies(array $cookies)
{
foreach ($cookies as $cookie)
{
$this->headers->setCookie($cookie);
}
return $this;
}
/**
* Flash an array of input to the session.
*
* @param array $input
* @return $this
*/
public function withInput(array $input = null)
{
$input = $input ?: $this->request->input();
$this->session->flashInput($data = array_filter($input, $callback = function (&$value) use (&$callback)
{
if (is_array($value))
{
$value = array_filter($value, $callback);
}
return ! $value instanceof UploadedFile;
}));
return $this;
}
/**
* Flash an array of input to the session.
*
* @param mixed string
* @return $this
*/
public function onlyInput()
{
return $this->withInput($this->request->only(func_get_args()));
}
/**
* Flash an array of input to the session.
*
* @param mixed string
* @return \Illuminate\Http\RedirectResponse
*/
public function exceptInput()
{
return $this->withInput($this->request->except(func_get_args()));
}
/**
* Flash a container of errors to the session.
*
* @param \Illuminate\Contracts\Support\MessageProvider|array|string $provider
* @param string $key
* @return $this
*/
public function withErrors($provider, $key = 'default')
{
$value = $this->parseErrors($provider);
$this->session->flash(
'errors', $this->session->get('errors', new ViewErrorBag)->put($key, $value)
);
return $this;
}
/**
* Parse the given errors into an appropriate value.
*
* @param \Illuminate\Contracts\Support\MessageProvider|array|string $provider
* @return \Illuminate\Support\MessageBag
*/
protected function parseErrors($provider)
{
if ($provider instanceof MessageProvider)
{
return $provider->getMessageBag();
}
return new MessageBag((array) $provider);
}
/**
* Get the request instance.
*
* @return \Illuminate\Http\Request
*/
public function getRequest()
{
return $this->request;
}
/**
* Set the request instance.
*
* @param \Illuminate\Http\Request $request
* @return void
*/
public function setRequest(Request $request)
{
$this->request = $request;
}
/**
* Get the session store implementation.
*
* @return \Illuminate\Session\Store
*/
public function getSession()
{
return $this->session;
}
/**
* Set the session store implementation.
*
* @param \Illuminate\Session\Store $session
* @return void
*/
public function setSession(SessionStore $session)
{
$this->session = $session;
}
/**
* Dynamically bind flash data in the session.
*
* @param string $method
* @param array $parameters
* @return void
*
* @throws \BadMethodCallException
*/
public function __call($method, $parameters)
{
if (starts_with($method, 'with'))
{
return $this->with(snake_case(substr($method, 4)), $parameters[0]);
}
throw new BadMethodCallException("Method [$method] does not exist on Redirect.");
}
}

View File

@@ -0,0 +1,793 @@
<?php namespace Illuminate\Http;
use Closure;
use ArrayAccess;
use SplFileInfo;
use RuntimeException;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
class Request extends SymfonyRequest implements ArrayAccess {
/**
* The decoded JSON content for the request.
*
* @var string
*/
protected $json;
/**
* The Illuminate session store implementation.
*
* @var \Illuminate\Session\Store
*/
protected $sessionStore;
/**
* The user resolver callback.
*
* @var \Closure
*/
protected $userResolver;
/**
* The route resolver callback.
*
* @var \Closure
*/
protected $routeResolver;
/**
* Create a new Illuminate HTTP request from server variables.
*
* @return static
*/
public static function capture()
{
static::enableHttpMethodParameterOverride();
return static::createFromBase(SymfonyRequest::createFromGlobals());
}
/**
* Return the Request instance.
*
* @return $this
*/
public function instance()
{
return $this;
}
/**
* Get the request method.
*
* @return string
*/
public function method()
{
return $this->getMethod();
}
/**
* Get the root URL for the application.
*
* @return string
*/
public function root()
{
return rtrim($this->getSchemeAndHttpHost().$this->getBaseUrl(), '/');
}
/**
* Get the URL (no query string) for the request.
*
* @return string
*/
public function url()
{
return rtrim(preg_replace('/\?.*/', '', $this->getUri()), '/');
}
/**
* Get the full URL for the request.
*
* @return string
*/
public function fullUrl()
{
$query = $this->getQueryString();
return $query ? $this->url().'?'.$query : $this->url();
}
/**
* Get the current path info for the request.
*
* @return string
*/
public function path()
{
$pattern = trim($this->getPathInfo(), '/');
return $pattern == '' ? '/' : $pattern;
}
/**
* Get the current encoded path info for the request.
*
* @return string
*/
public function decodedPath()
{
return rawurldecode($this->path());
}
/**
* Get a segment from the URI (1 based index).
*
* @param int $index
* @param mixed $default
* @return string
*/
public function segment($index, $default = null)
{
return array_get($this->segments(), $index - 1, $default);
}
/**
* Get all of the segments for the request path.
*
* @return array
*/
public function segments()
{
$segments = explode('/', $this->path());
return array_values(array_filter($segments, function($v) { return $v != ''; }));
}
/**
* Determine if the current request URI matches a pattern.
*
* @param mixed string
* @return bool
*/
public function is()
{
foreach (func_get_args() as $pattern)
{
if (str_is($pattern, urldecode($this->path())))
{
return true;
}
}
return false;
}
/**
* Determine if the request is the result of an AJAX call.
*
* @return bool
*/
public function ajax()
{
return $this->isXmlHttpRequest();
}
/**
* Determine if the request is the result of an PJAX call.
*
* @return bool
*/
public function pjax()
{
return $this->headers->get('X-PJAX') == true;
}
/**
* Determine if the request is over HTTPS.
*
* @return bool
*/
public function secure()
{
return $this->isSecure();
}
/**
* Returns the client IP address.
*
* @return string
*/
public function ip()
{
return $this->getClientIp();
}
/**
* Returns the client IP addresses.
*
* @return array
*/
public function ips()
{
return $this->getClientIps();
}
/**
* Determine if the request contains a given input item key.
*
* @param string|array $key
* @return bool
*/
public function exists($key)
{
$keys = is_array($key) ? $key : func_get_args();
$input = $this->all();
foreach ($keys as $value)
{
if ( ! array_key_exists($value, $input)) return false;
}
return true;
}
/**
* Determine if the request contains a non-empty value for an input item.
*
* @param string|array $key
* @return bool
*/
public function has($key)
{
$keys = is_array($key) ? $key : func_get_args();
foreach ($keys as $value)
{
if ($this->isEmptyString($value)) return false;
}
return true;
}
/**
* Determine if the given input key is an empty string for "has".
*
* @param string $key
* @return bool
*/
protected function isEmptyString($key)
{
$boolOrArray = is_bool($this->input($key)) || is_array($this->input($key));
return ! $boolOrArray && trim((string) $this->input($key)) === '';
}
/**
* Get all of the input and files for the request.
*
* @return array
*/
public function all()
{
return array_replace_recursive($this->input(), $this->files->all());
}
/**
* Retrieve an input item from the request.
*
* @param string $key
* @param mixed $default
* @return string|array
*/
public function input($key = null, $default = null)
{
$input = $this->getInputSource()->all() + $this->query->all();
return array_get($input, $key, $default);
}
/**
* Get a subset of the items from the input data.
*
* @param array $keys
* @return array
*/
public function only($keys)
{
$keys = is_array($keys) ? $keys : func_get_args();
$results = [];
$input = $this->all();
foreach ($keys as $key)
{
array_set($results, $key, array_get($input, $key));
}
return $results;
}
/**
* Get all of the input except for a specified array of items.
*
* @param array $keys
* @return array
*/
public function except($keys)
{
$keys = is_array($keys) ? $keys : func_get_args();
$results = $this->all();
array_forget($results, $keys);
return $results;
}
/**
* Retrieve a query string item from the request.
*
* @param string $key
* @param mixed $default
* @return string|array
*/
public function query($key = null, $default = null)
{
return $this->retrieveItem('query', $key, $default);
}
/**
* Determine if a cookie is set on the request.
*
* @param string $key
* @return bool
*/
public function hasCookie($key)
{
return ! is_null($this->cookie($key));
}
/**
* Retrieve a cookie from the request.
*
* @param string $key
* @param mixed $default
* @return string|array
*/
public function cookie($key = null, $default = null)
{
return $this->retrieveItem('cookies', $key, $default);
}
/**
* Retrieve a file from the request.
*
* @param string $key
* @param mixed $default
* @return \Symfony\Component\HttpFoundation\File\UploadedFile|array
*/
public function file($key = null, $default = null)
{
return array_get($this->files->all(), $key, $default);
}
/**
* Determine if the uploaded data contains a file.
*
* @param string $key
* @return bool
*/
public function hasFile($key)
{
if ( ! is_array($files = $this->file($key))) $files = array($files);
foreach ($files as $file)
{
if ($this->isValidFile($file)) return true;
}
return false;
}
/**
* Check that the given file is a valid file instance.
*
* @param mixed $file
* @return bool
*/
protected function isValidFile($file)
{
return $file instanceof SplFileInfo && $file->getPath() != '';
}
/**
* Retrieve a header from the request.
*
* @param string $key
* @param mixed $default
* @return string|array
*/
public function header($key = null, $default = null)
{
return $this->retrieveItem('headers', $key, $default);
}
/**
* Retrieve a server variable from the request.
*
* @param string $key
* @param mixed $default
* @return string|array
*/
public function server($key = null, $default = null)
{
return $this->retrieveItem('server', $key, $default);
}
/**
* Retrieve an old input item.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function old($key = null, $default = null)
{
return $this->session()->getOldInput($key, $default);
}
/**
* Flash the input for the current request to the session.
*
* @param string $filter
* @param array $keys
* @return void
*/
public function flash($filter = null, $keys = array())
{
$flash = ( ! is_null($filter)) ? $this->$filter($keys) : $this->input();
$this->session()->flashInput($flash);
}
/**
* Flash only some of the input to the session.
*
* @param mixed string
* @return void
*/
public function flashOnly($keys)
{
$keys = is_array($keys) ? $keys : func_get_args();
return $this->flash('only', $keys);
}
/**
* Flash only some of the input to the session.
*
* @param mixed string
* @return void
*/
public function flashExcept($keys)
{
$keys = is_array($keys) ? $keys : func_get_args();
return $this->flash('except', $keys);
}
/**
* Flush all of the old input from the session.
*
* @return void
*/
public function flush()
{
$this->session()->flashInput(array());
}
/**
* Retrieve a parameter item from a given source.
*
* @param string $source
* @param string $key
* @param mixed $default
* @return string|array
*/
protected function retrieveItem($source, $key, $default)
{
if (is_null($key))
{
return $this->$source->all();
}
return $this->$source->get($key, $default, true);
}
/**
* Merge new input into the current request's input array.
*
* @param array $input
* @return void
*/
public function merge(array $input)
{
$this->getInputSource()->add($input);
}
/**
* Replace the input for the current request.
*
* @param array $input
* @return void
*/
public function replace(array $input)
{
$this->getInputSource()->replace($input);
}
/**
* Get the JSON payload for the request.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
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);
}
/**
* Get the input source for the request.
*
* @return \Symfony\Component\HttpFoundation\ParameterBag
*/
protected function getInputSource()
{
if ($this->isJson()) return $this->json();
return $this->getMethod() == 'GET' ? $this->query : $this->request;
}
/**
* Determine if the request is sending JSON.
*
* @return bool
*/
public function isJson()
{
return str_contains($this->header('CONTENT_TYPE'), '/json');
}
/**
* Determine if the current request is asking for JSON in return.
*
* @return bool
*/
public function wantsJson()
{
$acceptable = $this->getAcceptableContentTypes();
return isset($acceptable[0]) && $acceptable[0] == 'application/json';
}
/**
* Get the data format expected in the response.
*
* @param string $default
* @return string
*/
public function format($default = 'html')
{
foreach ($this->getAcceptableContentTypes() as $type)
{
if ($format = $this->getFormat($type)) return $format;
}
return $default;
}
/**
* Create an Illuminate request from a Symfony instance.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @return \Illuminate\Http\Request
*/
public static function createFromBase(SymfonyRequest $request)
{
if ($request instanceof static) return $request;
$content = $request->content;
$request = (new static)->duplicate(
$request->query->all(), $request->request->all(), $request->attributes->all(),
$request->cookies->all(), $request->files->all(), $request->server->all()
);
$request->content = $content;
$request->request = $request->getInputSource();
return $request;
}
/**
* {@inheritdoc}
*/
public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
{
return parent::duplicate($query, $request, $attributes, $cookies, array_filter((array) $files), $server);
}
/**
* Get the session associated with the request.
*
* @return \Illuminate\Session\Store
*
* @throws \RuntimeException
*/
public function session()
{
if ( ! $this->hasSession())
{
throw new RuntimeException("Session store not set on request.");
}
return $this->getSession();
}
/**
* Get the user making the request.
*
* @return mixed
*/
public function user()
{
return call_user_func($this->getUserResolver());
}
/**
* Get the route handling the request.
*
* @return \Illuminate\Routing\Route|null
*/
public function route()
{
if (func_num_args() == 1)
{
return $this->route()->parameter(func_get_arg(0));
}
else
{
return call_user_func($this->getRouteResolver());
}
}
/**
* Get the user resolver callback.
*
* @return \Closure
*/
public function getUserResolver()
{
return $this->userResolver ?: function() {};
}
/**
* Set the user resolver callback.
*
* @param \Closure $callback
* @return $this
*/
public function setUserResolver(Closure $callback)
{
$this->userResolver = $callback;
return $this;
}
/**
* Get the route resolver callback.
*
* @return \Closure
*/
public function getRouteResolver()
{
return $this->routeResolver ?: function() {};
}
/**
* Set the route resolver callback.
*
* @param \Closure $callback
* @return $this
*/
public function setRouteResolver(Closure $callback)
{
$this->routeResolver = $callback;
return $this;
}
/**
* Determine if the given offset exists.
*
* @param string $offset
* @return bool
*/
public function offsetExists($offset)
{
return array_key_exists($offset, $this->all());
}
/**
* Get the value at the given offset.
*
* @param string $offset
* @return mixed
*/
public function offsetGet($offset)
{
return $this->input($offset);
}
/**
* Set the value at the given offset.
*
* @param string $offset
* @param mixed $value
* @return void
*/
public function offsetSet($offset, $value)
{
return $this->getInputSource()->set($offset, $value);
}
/**
* Remove the value at the given offset.
*
* @param string $offset
* @return void
*/
public function offsetUnset($offset)
{
return $this->getInputSource()->remove($offset);
}
/**
* Get an input element from the request.
*
* @param string $key
* @return mixed
*/
public function __get($key)
{
$input = $this->input();
if (array_key_exists($key, $input))
{
return $this->input($key);
}
elseif ( ! is_null($this->route()))
{
return $this->route()->parameter($key);
}
}
}

View File

@@ -0,0 +1,86 @@
<?php namespace Illuminate\Http;
use ArrayObject;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Contracts\Support\Renderable;
use Symfony\Component\HttpFoundation\Response as BaseResponse;
class Response extends BaseResponse {
use ResponseTrait;
/**
* The original content of the response.
*
* @var mixed
*/
public $original;
/**
* Set the content on the response.
*
* @param mixed $content
* @return $this
*/
public function setContent($content)
{
$this->original = $content;
// If the content is "JSONable" we will set the appropriate header and convert
// the content to JSON. This is useful when returning something like models
// from routes that will be automatically transformed to their JSON form.
if ($this->shouldBeJson($content))
{
$this->header('Content-Type', 'application/json');
$content = $this->morphToJson($content);
}
// If this content implements the "Renderable" interface then we will call the
// render method on the object so we will avoid any "__toString" exceptions
// that might be thrown and have their errors obscured by PHP's handling.
elseif ($content instanceof Renderable)
{
$content = $content->render();
}
return parent::setContent($content);
}
/**
* Morph the given content into JSON.
*
* @param mixed $content
* @return string
*/
protected function morphToJson($content)
{
if ($content instanceof Jsonable) return $content->toJson();
return json_encode($content);
}
/**
* Determine if the given content should be turned into JSON.
*
* @param mixed $content
* @return bool
*/
protected function shouldBeJson($content)
{
return $content instanceof Jsonable ||
$content instanceof ArrayObject ||
is_array($content);
}
/**
* Get the original response content.
*
* @return mixed
*/
public function getOriginalContent()
{
return $this->original;
}
}

View File

@@ -0,0 +1,35 @@
<?php namespace Illuminate\Http;
use Symfony\Component\HttpFoundation\Cookie;
trait ResponseTrait {
/**
* Set a header on the Response.
*
* @param string $key
* @param string $value
* @param bool $replace
* @return $this
*/
public function header($key, $value, $replace = true)
{
$this->headers->set($key, $value, $replace);
return $this;
}
/**
* Add a cookie to the response.
*
* @param \Symfony\Component\HttpFoundation\Cookie $cookie
* @return $this
*/
public function withCookie(Cookie $cookie)
{
$this->headers->setCookie($cookie);
return $this;
}
}

View File

@@ -0,0 +1,34 @@
{
"name": "illuminate/http",
"description": "The Illuminate Http package.",
"license": "MIT",
"homepage": "http://laravel.com",
"support": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"authors": [
{
"name": "Taylor Otwell",
"email": "taylorotwell@gmail.com"
}
],
"require": {
"php": ">=5.4.0",
"illuminate/session": "5.0.*",
"illuminate/support": "5.0.*",
"symfony/http-foundation": "2.6.*",
"symfony/http-kernel": "2.6.*"
},
"autoload": {
"psr-4": {
"Illuminate\\Http\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "5.0-dev"
}
},
"minimum-stability": "dev"
}