Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663
This commit is contained in:
parent
eb34d130a8
commit
f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions
32
vendor/zendframework/zend-diactoros/src/Response/EmitterInterface.php
vendored
Normal file
32
vendor/zendframework/zend-diactoros/src/Response/EmitterInterface.php
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
interface EmitterInterface
|
||||
{
|
||||
/**
|
||||
* Emit a response.
|
||||
*
|
||||
* Emits a response, including status line, headers, and the message body,
|
||||
* according to the environment.
|
||||
*
|
||||
* Implementations of this method may be written in such a way as to have
|
||||
* side effects, such as usage of header() or pushing output to the
|
||||
* output buffer.
|
||||
*
|
||||
* Implementations MAY raise exceptions if they are unable to emit the
|
||||
* response; e.g., if headers have already been sent.
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
*/
|
||||
public function emit(ResponseInterface $response);
|
||||
}
|
42
vendor/zendframework/zend-diactoros/src/Response/EmptyResponse.php
vendored
Normal file
42
vendor/zendframework/zend-diactoros/src/Response/EmptyResponse.php
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
/**
|
||||
* A class representing empty HTTP responses.
|
||||
*/
|
||||
class EmptyResponse extends Response
|
||||
{
|
||||
/**
|
||||
* Create an empty response with the given status code.
|
||||
*
|
||||
* @param int $status Status code for the response, if any.
|
||||
* @param array $headers Headers for the response, if any.
|
||||
*/
|
||||
public function __construct($status = 204, array $headers = [])
|
||||
{
|
||||
$body = new Stream('php://temp', 'r');
|
||||
parent::__construct($body, $status, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an empty response with the given headers.
|
||||
*
|
||||
* @param array $headers Headers for the response.
|
||||
* @return EmptyResponse
|
||||
*/
|
||||
public static function withHeaders(array $headers)
|
||||
{
|
||||
return new static(204, $headers);
|
||||
}
|
||||
}
|
73
vendor/zendframework/zend-diactoros/src/Response/HtmlResponse.php
vendored
Normal file
73
vendor/zendframework/zend-diactoros/src/Response/HtmlResponse.php
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
/**
|
||||
* HTML response.
|
||||
*
|
||||
* Allows creating a response by passing an HTML string to the constructor;
|
||||
* by default, sets a status code of 200 and sets the Content-Type header to
|
||||
* text/html.
|
||||
*/
|
||||
class HtmlResponse extends Response
|
||||
{
|
||||
use InjectContentTypeTrait;
|
||||
|
||||
/**
|
||||
* Create an HTML response.
|
||||
*
|
||||
* Produces an HTML response with a Content-Type of text/html and a default
|
||||
* status of 200.
|
||||
*
|
||||
* @param string|StreamInterface $html HTML or stream for the message body.
|
||||
* @param int $status Integer status code for the response; 200 by default.
|
||||
* @param array $headers Array of headers to use at initialization.
|
||||
* @throws InvalidArgumentException if $html is neither a string or stream.
|
||||
*/
|
||||
public function __construct($html, $status = 200, array $headers = [])
|
||||
{
|
||||
parent::__construct(
|
||||
$this->createBody($html),
|
||||
$status,
|
||||
$this->injectContentType('text/html', $headers)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the message body.
|
||||
*
|
||||
* @param string|StreamInterface $html
|
||||
* @return StreamInterface
|
||||
* @throws InvalidArgumentException if $html is neither a string or stream.
|
||||
*/
|
||||
private function createBody($html)
|
||||
{
|
||||
if ($html instanceof StreamInterface) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
if (! is_string($html)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Invalid content (%s) provided to %s',
|
||||
(is_object($html) ? get_class($html) : gettype($html)),
|
||||
__CLASS__
|
||||
));
|
||||
}
|
||||
|
||||
$body = new Stream('php://temp', 'wb+');
|
||||
$body->write($html);
|
||||
return $body;
|
||||
}
|
||||
}
|
33
vendor/zendframework/zend-diactoros/src/Response/InjectContentTypeTrait.php
vendored
Normal file
33
vendor/zendframework/zend-diactoros/src/Response/InjectContentTypeTrait.php
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
trait InjectContentTypeTrait
|
||||
{
|
||||
/**
|
||||
* Inject the provided Content-Type, if none is already present.
|
||||
*
|
||||
* @param string $contentType
|
||||
* @param array $headers
|
||||
* @return array Headers with injected Content-Type
|
||||
*/
|
||||
private function injectContentType($contentType, array $headers)
|
||||
{
|
||||
$hasContentType = array_reduce(array_keys($headers), function ($carry, $item) {
|
||||
return $carry ?: (strtolower($item) === 'content-type');
|
||||
}, false);
|
||||
|
||||
if (! $hasContentType) {
|
||||
$headers['content-type'] = [$contentType];
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
}
|
83
vendor/zendframework/zend-diactoros/src/Response/JsonResponse.php
vendored
Normal file
83
vendor/zendframework/zend-diactoros/src/Response/JsonResponse.php
vendored
Normal file
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
/**
|
||||
* JSON response.
|
||||
*
|
||||
* Allows creating a response by passing data to the constructor; by default,
|
||||
* serializes the data to JSON, sets a status code of 200 and sets the
|
||||
* Content-Type header to application/json.
|
||||
*/
|
||||
class JsonResponse extends Response
|
||||
{
|
||||
use InjectContentTypeTrait;
|
||||
|
||||
/**
|
||||
* Create a JSON response with the given data.
|
||||
*
|
||||
* Default JSON encoding is performed with the following options, which
|
||||
* produces RFC4627-compliant JSON, capable of embedding into HTML.
|
||||
*
|
||||
* - JSON_HEX_TAG
|
||||
* - JSON_HEX_APOS
|
||||
* - JSON_HEX_AMP
|
||||
* - JSON_HEX_QUOT
|
||||
*
|
||||
* @param mixed $data Data to convert to JSON.
|
||||
* @param int $status Integer status code for the response; 200 by default.
|
||||
* @param array $headers Array of headers to use at initialization.
|
||||
* @param int $encodingOptions JSON encoding options to use.
|
||||
* @throws InvalidArgumentException if unable to encode the $data to JSON.
|
||||
*/
|
||||
public function __construct($data, $status = 200, array $headers = [], $encodingOptions = 15)
|
||||
{
|
||||
$body = new Stream('php://temp', 'wb+');
|
||||
$body->write($this->jsonEncode($data, $encodingOptions));
|
||||
|
||||
$headers = $this->injectContentType('application/json', $headers);
|
||||
|
||||
parent::__construct($body, $status, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the provided data to JSON.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param int $encodingOptions
|
||||
* @return string
|
||||
* @throws InvalidArgumentException if unable to encode the $data to JSON.
|
||||
*/
|
||||
private function jsonEncode($data, $encodingOptions)
|
||||
{
|
||||
if (is_resource($data)) {
|
||||
throw new InvalidArgumentException('Cannot JSON encode resources');
|
||||
}
|
||||
|
||||
// Clear json_last_error()
|
||||
json_encode(null);
|
||||
|
||||
$json = json_encode($data, $encodingOptions);
|
||||
|
||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Unable to encode data to JSON in %s: %s',
|
||||
__CLASS__,
|
||||
json_last_error_msg()
|
||||
));
|
||||
}
|
||||
|
||||
return $json;
|
||||
}
|
||||
}
|
47
vendor/zendframework/zend-diactoros/src/Response/RedirectResponse.php
vendored
Normal file
47
vendor/zendframework/zend-diactoros/src/Response/RedirectResponse.php
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
/**
|
||||
* Produce a redirect response.
|
||||
*/
|
||||
class RedirectResponse extends Response
|
||||
{
|
||||
/**
|
||||
* Create a redirect response.
|
||||
*
|
||||
* Produces a redirect response with a Location header and the given status
|
||||
* (302 by default).
|
||||
*
|
||||
* Note: this method overwrites the `location` $headers value.
|
||||
*
|
||||
* @param string|UriInterface $uri URI for the Location header.
|
||||
* @param int $status Integer status code for the redirect; 302 by default.
|
||||
* @param array $headers Array of headers to use at initialization.
|
||||
*/
|
||||
public function __construct($uri, $status = 302, array $headers = [])
|
||||
{
|
||||
if (! is_string($uri) && ! $uri instanceof UriInterface) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Uri provided to %s MUST be a string or Psr\Http\Message\UriInterface instance; received "%s"',
|
||||
__CLASS__,
|
||||
(is_object($uri) ? get_class($uri) : gettype($uri))
|
||||
));
|
||||
}
|
||||
|
||||
$headers['location'] = [(string) $uri];
|
||||
parent::__construct('php://temp', $status, $headers);
|
||||
}
|
||||
}
|
116
vendor/zendframework/zend-diactoros/src/Response/SapiEmitter.php
vendored
Normal file
116
vendor/zendframework/zend-diactoros/src/Response/SapiEmitter.php
vendored
Normal file
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use RuntimeException;
|
||||
|
||||
class SapiEmitter implements EmitterInterface
|
||||
{
|
||||
/**
|
||||
* Emits a response for a PHP SAPI environment.
|
||||
*
|
||||
* Emits the status line and headers via the header() function, and the
|
||||
* body content via the output buffer.
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
* @param null|int $maxBufferLevel Maximum output buffering level to unwrap.
|
||||
*/
|
||||
public function emit(ResponseInterface $response, $maxBufferLevel = null)
|
||||
{
|
||||
if (headers_sent()) {
|
||||
throw new RuntimeException('Unable to emit response; headers already sent');
|
||||
}
|
||||
|
||||
$this->emitStatusLine($response);
|
||||
$this->emitHeaders($response);
|
||||
$this->emitBody($response, $maxBufferLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit the status line.
|
||||
*
|
||||
* Emits the status line using the protocol version and status code from
|
||||
* the response; if a reason phrase is availble, it, too, is emitted.
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
*/
|
||||
private function emitStatusLine(ResponseInterface $response)
|
||||
{
|
||||
$reasonPhrase = $response->getReasonPhrase();
|
||||
header(sprintf(
|
||||
'HTTP/%s %d%s',
|
||||
$response->getProtocolVersion(),
|
||||
$response->getStatusCode(),
|
||||
($reasonPhrase ? ' ' . $reasonPhrase : '')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit response headers.
|
||||
*
|
||||
* Loops through each header, emitting each; if the header value
|
||||
* is an array with multiple values, ensures that each is sent
|
||||
* in such a way as to create aggregate headers (instead of replace
|
||||
* the previous).
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
*/
|
||||
private function emitHeaders(ResponseInterface $response)
|
||||
{
|
||||
foreach ($response->getHeaders() as $header => $values) {
|
||||
$name = $this->filterHeader($header);
|
||||
$first = true;
|
||||
foreach ($values as $value) {
|
||||
header(sprintf(
|
||||
'%s: %s',
|
||||
$name,
|
||||
$value
|
||||
), $first);
|
||||
$first = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit the message body.
|
||||
*
|
||||
* Loops through the output buffer, flushing each, before emitting
|
||||
* the response body using `echo()`.
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
* @param int $maxBufferLevel Flush up to this buffer level.
|
||||
*/
|
||||
private function emitBody(ResponseInterface $response, $maxBufferLevel)
|
||||
{
|
||||
if (null === $maxBufferLevel) {
|
||||
$maxBufferLevel = ob_get_level();
|
||||
}
|
||||
|
||||
while (ob_get_level() > $maxBufferLevel) {
|
||||
ob_end_flush();
|
||||
}
|
||||
|
||||
echo $response->getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a header name to wordcase
|
||||
*
|
||||
* @param string $header
|
||||
* @return string
|
||||
*/
|
||||
private function filterHeader($header)
|
||||
{
|
||||
$filtered = str_replace('-', ' ', $header);
|
||||
$filtered = ucwords($filtered);
|
||||
return str_replace(' ', '-', $filtered);
|
||||
}
|
||||
}
|
111
vendor/zendframework/zend-diactoros/src/Response/Serializer.php
vendored
Normal file
111
vendor/zendframework/zend-diactoros/src/Response/Serializer.php
vendored
Normal file
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Diactoros\Response;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use UnexpectedValueException;
|
||||
use Zend\Diactoros\AbstractSerializer;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
final class Serializer extends AbstractSerializer
|
||||
{
|
||||
/**
|
||||
* Deserialize a response string to a response instance.
|
||||
*
|
||||
* @param string $message
|
||||
* @return Response
|
||||
* @throws UnexpectedValueException when errors occur parsing the message.
|
||||
*/
|
||||
public static function fromString($message)
|
||||
{
|
||||
$stream = new Stream('php://temp', 'wb+');
|
||||
$stream->write($message);
|
||||
return static::fromStream($stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a response from a stream.
|
||||
*
|
||||
* @param StreamInterface $stream
|
||||
* @return ResponseInterface
|
||||
* @throws InvalidArgumentException when the stream is not readable.
|
||||
* @throws UnexpectedValueException when errors occur parsing the message.
|
||||
*/
|
||||
public static function fromStream(StreamInterface $stream)
|
||||
{
|
||||
if (! $stream->isReadable() || ! $stream->isSeekable()) {
|
||||
throw new InvalidArgumentException('Message stream must be both readable and seekable');
|
||||
}
|
||||
|
||||
$stream->rewind();
|
||||
|
||||
list($version, $status, $reasonPhrase) = self::getStatusLine($stream);
|
||||
list($headers, $body) = self::splitStream($stream);
|
||||
|
||||
return (new Response($body, $status, $headers))
|
||||
->withProtocolVersion($version)
|
||||
->withStatus($status, $reasonPhrase);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a string representation of a response.
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
* @return string
|
||||
*/
|
||||
public static function toString(ResponseInterface $response)
|
||||
{
|
||||
$reasonPhrase = $response->getReasonPhrase();
|
||||
$headers = self::serializeHeaders($response->getHeaders());
|
||||
$body = (string) $response->getBody();
|
||||
$format = 'HTTP/%s %d%s%s%s';
|
||||
|
||||
if (! empty($headers)) {
|
||||
$headers = "\r\n" . $headers;
|
||||
}
|
||||
if (! empty($body)) {
|
||||
$headers .= "\r\n\r\n";
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
$format,
|
||||
$response->getProtocolVersion(),
|
||||
$response->getStatusCode(),
|
||||
($reasonPhrase ? ' ' . $reasonPhrase : ''),
|
||||
$headers,
|
||||
$body
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the status line for the message.
|
||||
*
|
||||
* @param StreamInterface $stream
|
||||
* @return array Array with three elements: 0 => version, 1 => status, 2 => reason
|
||||
* @throws UnexpectedValueException if line is malformed
|
||||
*/
|
||||
private static function getStatusLine(StreamInterface $stream)
|
||||
{
|
||||
$line = self::getLine($stream);
|
||||
|
||||
if (! preg_match(
|
||||
'#^HTTP/(?P<version>[1-9]\d*\.\d) (?P<status>[1-5]\d{2})(\s+(?P<reason>.+))?$#',
|
||||
$line,
|
||||
$matches
|
||||
)) {
|
||||
throw new UnexpectedValueException('No status line detected');
|
||||
}
|
||||
|
||||
return [$matches['version'], $matches['status'], isset($matches['reason']) ? $matches['reason'] : ''];
|
||||
}
|
||||
}
|
Reference in a new issue