Initial Commit
This commit is contained in:
253
dependencies/mpdf/psr-http-message-shim/src/Request.php
vendored
Normal file
253
dependencies/mpdf/psr-http-message-shim/src/Request.php
vendored
Normal file
@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Ultimo\Dependencies\Mpdf\PsrHttpMessageShim;
|
||||
|
||||
use WP_Ultimo\Dependencies\Psr\Http\Message\MessageInterface;
|
||||
use WP_Ultimo\Dependencies\Psr\Http\Message\RequestInterface;
|
||||
use WP_Ultimo\Dependencies\Psr\Http\Message\StreamInterface;
|
||||
use WP_Ultimo\Dependencies\Psr\Http\Message\UriInterface;
|
||||
/**
|
||||
* PSR-7 URI implementation ported from nyholm/psr7 and adapted for PHP 5.6
|
||||
*
|
||||
* @link https://github.com/Nyholm/psr7/blob/master/src/Uri.php
|
||||
*/
|
||||
class Request implements \WP_Ultimo\Dependencies\Psr\Http\Message\RequestInterface
|
||||
{
|
||||
/** @var string */
|
||||
private $method;
|
||||
/** @var null|string */
|
||||
private $requestTarget;
|
||||
/** @var null|UriInterface */
|
||||
private $uri;
|
||||
/** @var array Map of all registered headers, as original name => array of values */
|
||||
private $headers = [];
|
||||
/** @var array Map of lowercase header name => original name at registration */
|
||||
private $headerNames = [];
|
||||
/** @var string */
|
||||
private $protocol;
|
||||
/** @var StreamInterface */
|
||||
private $stream;
|
||||
/**
|
||||
* @param string $method HTTP method
|
||||
* @param string|UriInterface $uri URI
|
||||
* @param array $headers Request headers
|
||||
* @param string|null|resource|StreamInterface $body Request body
|
||||
* @param string $version Protocol version
|
||||
*/
|
||||
public function __construct($method, $uri, array $headers = [], $body = null, $version = '1.1')
|
||||
{
|
||||
if (!$uri instanceof UriInterface) {
|
||||
$uri = new Uri($uri);
|
||||
}
|
||||
$this->method = $method;
|
||||
$this->uri = $uri;
|
||||
$this->setHeaders($headers);
|
||||
$this->protocol = $version;
|
||||
if (!$this->hasHeader('Host')) {
|
||||
$this->updateHostFromUri();
|
||||
}
|
||||
if ($body !== '' && $body !== null) {
|
||||
$this->stream = Stream::create($body);
|
||||
}
|
||||
}
|
||||
public function getRequestTarget() : string
|
||||
{
|
||||
if ($this->requestTarget !== null) {
|
||||
return $this->requestTarget;
|
||||
}
|
||||
$target = $this->uri->getPath();
|
||||
if ($target == '') {
|
||||
$target = '/';
|
||||
}
|
||||
if ($this->uri->getQuery() != '') {
|
||||
$target .= '?' . $this->uri->getQuery();
|
||||
}
|
||||
return $target;
|
||||
}
|
||||
public function withRequestTarget(string $requestTarget) : RequestInterface
|
||||
{
|
||||
if (\preg_match('#\\s#', $requestTarget)) {
|
||||
throw new \InvalidArgumentException('Invalid request target provided; cannot contain whitespace');
|
||||
}
|
||||
$new = clone $this;
|
||||
$new->requestTarget = $requestTarget;
|
||||
return $new;
|
||||
}
|
||||
public function getMethod() : string
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
public function withMethod(string $method) : RequestInterface
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->method = $method;
|
||||
return $new;
|
||||
}
|
||||
public function getUri() : UriInterface
|
||||
{
|
||||
return $this->uri;
|
||||
}
|
||||
public function withUri(UriInterface $uri, bool $preserveHost = \false) : RequestInterface
|
||||
{
|
||||
if ($uri === $this->uri) {
|
||||
return $this;
|
||||
}
|
||||
$new = clone $this;
|
||||
$new->uri = $uri;
|
||||
if (!$preserveHost || !$this->hasHeader('Host')) {
|
||||
$new->updateHostFromUri();
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
private function updateHostFromUri()
|
||||
{
|
||||
$host = $this->uri->getHost();
|
||||
if ($host == '') {
|
||||
return;
|
||||
}
|
||||
if (($port = $this->uri->getPort()) !== null) {
|
||||
$host .= ':' . $port;
|
||||
}
|
||||
if (isset($this->headerNames['host'])) {
|
||||
$header = $this->headerNames['host'];
|
||||
} else {
|
||||
$header = 'Host';
|
||||
$this->headerNames['host'] = 'Host';
|
||||
}
|
||||
// Ensure Host is the first header.
|
||||
// See: http://tools.ietf.org/html/rfc7230#section-5.4
|
||||
$this->headers = [$header => [$host]] + $this->headers;
|
||||
}
|
||||
public function getProtocolVersion() : string
|
||||
{
|
||||
return $this->protocol;
|
||||
}
|
||||
public function withProtocolVersion(string $version) : MessageInterface
|
||||
{
|
||||
if ($this->protocol === $version) {
|
||||
return $this;
|
||||
}
|
||||
$new = clone $this;
|
||||
$new->protocol = $version;
|
||||
return $new;
|
||||
}
|
||||
public function getHeaders() : array
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
public function hasHeader(string $header) : bool
|
||||
{
|
||||
return isset($this->headerNames[\strtolower($header)]);
|
||||
}
|
||||
public function getHeader(string $header) : array
|
||||
{
|
||||
$header = \strtolower($header);
|
||||
if (!isset($this->headerNames[$header])) {
|
||||
return [];
|
||||
}
|
||||
$header = $this->headerNames[$header];
|
||||
return $this->headers[$header];
|
||||
}
|
||||
public function getHeaderLine(string $header) : string
|
||||
{
|
||||
return \implode(', ', $this->getHeader($header));
|
||||
}
|
||||
public function withHeader(string $header, $value) : MessageInterface
|
||||
{
|
||||
if (!\is_array($value)) {
|
||||
$value = [$value];
|
||||
}
|
||||
$value = $this->trimHeaderValues($value);
|
||||
$normalized = \strtolower($header);
|
||||
$new = clone $this;
|
||||
if (isset($new->headerNames[$normalized])) {
|
||||
unset($new->headers[$new->headerNames[$normalized]]);
|
||||
}
|
||||
$new->headerNames[$normalized] = $header;
|
||||
$new->headers[$header] = $value;
|
||||
return $new;
|
||||
}
|
||||
public function withAddedHeader(string $header, $value) : MessageInterface
|
||||
{
|
||||
if (!\is_array($value)) {
|
||||
$value = [$value];
|
||||
}
|
||||
$value = $this->trimHeaderValues($value);
|
||||
$normalized = \strtolower($header);
|
||||
$new = clone $this;
|
||||
if (isset($new->headerNames[$normalized])) {
|
||||
$header = $this->headerNames[$normalized];
|
||||
$new->headers[$header] = \array_merge($this->headers[$header], $value);
|
||||
} else {
|
||||
$new->headerNames[$normalized] = $header;
|
||||
$new->headers[$header] = $value;
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
public function withoutHeader(string $header) : MessageInterface
|
||||
{
|
||||
$normalized = \strtolower($header);
|
||||
if (!isset($this->headerNames[$normalized])) {
|
||||
return $this;
|
||||
}
|
||||
$header = $this->headerNames[$normalized];
|
||||
$new = clone $this;
|
||||
unset($new->headers[$header], $new->headerNames[$normalized]);
|
||||
return $new;
|
||||
}
|
||||
public function getBody() : StreamInterface
|
||||
{
|
||||
if (!$this->stream) {
|
||||
$this->stream = Stream::create('');
|
||||
$this->stream->rewind();
|
||||
}
|
||||
return $this->stream;
|
||||
}
|
||||
public function withBody(StreamInterface $body) : MessageInterface
|
||||
{
|
||||
if ($body === $this->stream) {
|
||||
return $this;
|
||||
}
|
||||
$new = clone $this;
|
||||
$new->stream = $body;
|
||||
return $new;
|
||||
}
|
||||
private function setHeaders(array $headers)
|
||||
{
|
||||
$this->headerNames = $this->headers = [];
|
||||
foreach ($headers as $header => $value) {
|
||||
if (!\is_array($value)) {
|
||||
$value = [$value];
|
||||
}
|
||||
$value = $this->trimHeaderValues($value);
|
||||
$normalized = \strtolower($header);
|
||||
if (isset($this->headerNames[$normalized])) {
|
||||
$header = $this->headerNames[$normalized];
|
||||
$this->headers[$header] = \array_merge($this->headers[$header], $value);
|
||||
} else {
|
||||
$this->headerNames[$normalized] = $header;
|
||||
$this->headers[$header] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Trims whitespace from the header values.
|
||||
*
|
||||
* Spaces and tabs ought to be excluded by parsers when extracting the field value from a header field.
|
||||
*
|
||||
* header-field = field-name ":" OWS field-value OWS
|
||||
* OWS = *( SP / HTAB )
|
||||
*
|
||||
* @param string[] $values Header values
|
||||
*
|
||||
* @return string[] Trimmed header values
|
||||
*
|
||||
* @see https://tools.ietf.org/html/rfc7230#section-3.2.4
|
||||
*/
|
||||
private function trimHeaderValues(array $values)
|
||||
{
|
||||
return \array_map(function ($value) {
|
||||
return \trim($value, " \t");
|
||||
}, $values);
|
||||
}
|
||||
}
|
207
dependencies/mpdf/psr-http-message-shim/src/Response.php
vendored
Normal file
207
dependencies/mpdf/psr-http-message-shim/src/Response.php
vendored
Normal file
@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Ultimo\Dependencies\Mpdf\PsrHttpMessageShim;
|
||||
|
||||
use WP_Ultimo\Dependencies\Psr\Http\Message\StreamInterface;
|
||||
use WP_Ultimo\Dependencies\Psr\Http\Message\ResponseInterface;
|
||||
use WP_Ultimo\Dependencies\Psr\Http\Message\MessageInterface;
|
||||
/**
|
||||
* PSR-7 URI implementation ported from nyholm/psr7 and adapted for PHP 5.6
|
||||
*
|
||||
* @link https://github.com/Nyholm/psr7/blob/master/src/Uri.php
|
||||
*/
|
||||
class Response implements \WP_Ultimo\Dependencies\Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
/** @var array Map of standard HTTP status code/reason phrases */
|
||||
private static $phrases = [100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-status', 208 => 'Already Reported', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Switch Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', 425 => 'Unordered Collection', 426 => 'Upgrade Required', 428 => 'Precondition Required', 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large', 451 => 'Unavailable For Legal Reasons', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported', 506 => 'Variant Also Negotiates', 507 => 'Insufficient Storage', 508 => 'Loop Detected', 511 => 'Network Authentication Required'];
|
||||
/** @var string */
|
||||
private $reasonPhrase;
|
||||
/** @var int */
|
||||
private $statusCode;
|
||||
/** @var array Map of all registered headers, as original name => array of values */
|
||||
private $headers = [];
|
||||
/** @var array Map of lowercase header name => original name at registration */
|
||||
private $headerNames = [];
|
||||
/** @var string */
|
||||
private $protocol;
|
||||
/** @var \Psr\Http\Message\StreamInterface */
|
||||
private $stream;
|
||||
/**
|
||||
* @param int $status Status code
|
||||
* @param array $headers Response headers
|
||||
* @param string|resource|StreamInterface|null $body Response body
|
||||
* @param string $version Protocol version
|
||||
* @param string|null $reason Reason phrase (when empty a default will be used based on the status code)
|
||||
*/
|
||||
public function __construct($status = 200, array $headers = [], $body = null, $version = '1.1', $reason = null)
|
||||
{
|
||||
// If we got no body, defer initialization of the stream until Response::getBody()
|
||||
if ('' !== $body && null !== $body) {
|
||||
$this->stream = Stream::create($body);
|
||||
}
|
||||
$this->statusCode = $status;
|
||||
$this->setHeaders($headers);
|
||||
if (null === $reason && isset(self::$phrases[$this->statusCode])) {
|
||||
$this->reasonPhrase = self::$phrases[$status];
|
||||
} else {
|
||||
$this->reasonPhrase = isset($reason) ? $reason : '';
|
||||
}
|
||||
$this->protocol = $version;
|
||||
}
|
||||
public function getStatusCode() : int
|
||||
{
|
||||
return $this->statusCode;
|
||||
}
|
||||
public function getReasonPhrase() : string
|
||||
{
|
||||
return $this->reasonPhrase;
|
||||
}
|
||||
public function withStatus(int $code, string $reasonPhrase = '') : ResponseInterface
|
||||
{
|
||||
if (!\is_int($code) && !\is_string($code)) {
|
||||
throw new \InvalidArgumentException('Status code has to be an integer');
|
||||
}
|
||||
$code = (int) $code;
|
||||
if ($code < 100 || $code > 599) {
|
||||
throw new \InvalidArgumentException(\sprintf('Status code has to be an integer between 100 and 599. A status code of %d was given', $code));
|
||||
}
|
||||
$new = clone $this;
|
||||
$new->statusCode = $code;
|
||||
if ((null === $reasonPhrase || '' === $reasonPhrase) && isset(self::$phrases[$new->statusCode])) {
|
||||
$reasonPhrase = self::$phrases[$new->statusCode];
|
||||
}
|
||||
$new->reasonPhrase = $reasonPhrase;
|
||||
return $new;
|
||||
}
|
||||
public function getProtocolVersion() : string
|
||||
{
|
||||
return $this->protocol;
|
||||
}
|
||||
public function withProtocolVersion(string $version) : MessageInterface
|
||||
{
|
||||
if ($this->protocol === $version) {
|
||||
return $this;
|
||||
}
|
||||
$new = clone $this;
|
||||
$new->protocol = $version;
|
||||
return $new;
|
||||
}
|
||||
public function getHeaders() : array
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
public function hasHeader(string $header) : bool
|
||||
{
|
||||
return isset($this->headerNames[\strtolower($header)]);
|
||||
}
|
||||
public function getHeader(string $header) : array
|
||||
{
|
||||
$header = \strtolower($header);
|
||||
if (!isset($this->headerNames[$header])) {
|
||||
return [];
|
||||
}
|
||||
$header = $this->headerNames[$header];
|
||||
return $this->headers[$header];
|
||||
}
|
||||
public function getHeaderLine(string $header) : string
|
||||
{
|
||||
return \implode(', ', $this->getHeader($header));
|
||||
}
|
||||
public function withHeader(string $header, $value) : MessageInterface
|
||||
{
|
||||
if (!\is_array($value)) {
|
||||
$value = [$value];
|
||||
}
|
||||
$value = $this->trimHeaderValues($value);
|
||||
$normalized = \strtolower($header);
|
||||
$new = clone $this;
|
||||
if (isset($new->headerNames[$normalized])) {
|
||||
unset($new->headers[$new->headerNames[$normalized]]);
|
||||
}
|
||||
$new->headerNames[$normalized] = $header;
|
||||
$new->headers[$header] = $value;
|
||||
return $new;
|
||||
}
|
||||
public function withAddedHeader(string $header, $value) : MessageInterface
|
||||
{
|
||||
if (!\is_array($value)) {
|
||||
$value = [$value];
|
||||
}
|
||||
$value = $this->trimHeaderValues($value);
|
||||
$normalized = \strtolower($header);
|
||||
$new = clone $this;
|
||||
if (isset($new->headerNames[$normalized])) {
|
||||
$header = $this->headerNames[$normalized];
|
||||
$new->headers[$header] = \array_merge($this->headers[$header], $value);
|
||||
} else {
|
||||
$new->headerNames[$normalized] = $header;
|
||||
$new->headers[$header] = $value;
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
public function withoutHeader(string $header) : MessageInterface
|
||||
{
|
||||
$normalized = \strtolower($header);
|
||||
if (!isset($this->headerNames[$normalized])) {
|
||||
return $this;
|
||||
}
|
||||
$header = $this->headerNames[$normalized];
|
||||
$new = clone $this;
|
||||
unset($new->headers[$header], $new->headerNames[$normalized]);
|
||||
return $new;
|
||||
}
|
||||
public function getBody() : StreamInterface
|
||||
{
|
||||
if (!$this->stream) {
|
||||
$this->stream = Stream::create('');
|
||||
}
|
||||
return $this->stream;
|
||||
}
|
||||
public function withBody(StreamInterface $body) : MessageInterface
|
||||
{
|
||||
if ($body === $this->stream) {
|
||||
return $this;
|
||||
}
|
||||
$new = clone $this;
|
||||
$new->stream = $body;
|
||||
return $new;
|
||||
}
|
||||
private function setHeaders(array $headers)
|
||||
{
|
||||
$this->headerNames = $this->headers = [];
|
||||
foreach ($headers as $header => $value) {
|
||||
if (!\is_array($value)) {
|
||||
$value = [$value];
|
||||
}
|
||||
$value = $this->trimHeaderValues($value);
|
||||
$normalized = \strtolower($header);
|
||||
if (isset($this->headerNames[$normalized])) {
|
||||
$header = $this->headerNames[$normalized];
|
||||
$this->headers[$header] = \array_merge($this->headers[$header], $value);
|
||||
} else {
|
||||
$this->headerNames[$normalized] = $header;
|
||||
$this->headers[$header] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Trims whitespace from the header values.
|
||||
*
|
||||
* Spaces and tabs ought to be excluded by parsers when extracting the field value from a header field.
|
||||
*
|
||||
* header-field = field-name ":" OWS field-value OWS
|
||||
* OWS = *( SP / HTAB )
|
||||
*
|
||||
* @param string[] $values Header values
|
||||
*
|
||||
* @return string[] Trimmed header values
|
||||
*
|
||||
* @see https://tools.ietf.org/html/rfc7230#section-3.2.4
|
||||
*/
|
||||
private function trimHeaderValues(array $values)
|
||||
{
|
||||
return \array_map(function ($value) {
|
||||
return \trim($value, " \t");
|
||||
}, $values);
|
||||
}
|
||||
}
|
209
dependencies/mpdf/psr-http-message-shim/src/Stream.php
vendored
Normal file
209
dependencies/mpdf/psr-http-message-shim/src/Stream.php
vendored
Normal file
@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Ultimo\Dependencies\Mpdf\PsrHttpMessageShim;
|
||||
|
||||
/**
|
||||
* @link nyholm/psr7
|
||||
*/
|
||||
class Stream implements \WP_Ultimo\Dependencies\Psr\Http\Message\StreamInterface
|
||||
{
|
||||
/**
|
||||
* A resource reference.
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $stream;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $seekable;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $readable;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $writable;
|
||||
/**
|
||||
* @var array|mixed|null|void
|
||||
*/
|
||||
private $uri;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $size;
|
||||
/** @var array Hash of readable and writable stream types */
|
||||
private static $readWriteHash = ['read' => ['r' => \true, 'w+' => \true, 'r+' => \true, 'x+' => \true, 'c+' => \true, 'rb' => \true, 'w+b' => \true, 'r+b' => \true, 'x+b' => \true, 'c+b' => \true, 'rt' => \true, 'w+t' => \true, 'r+t' => \true, 'x+t' => \true, 'c+t' => \true, 'a+' => \true], 'write' => ['w' => \true, 'w+' => \true, 'rw' => \true, 'r+' => \true, 'x+' => \true, 'c+' => \true, 'wb' => \true, 'w+b' => \true, 'r+b' => \true, 'x+b' => \true, 'c+b' => \true, 'w+t' => \true, 'r+t' => \true, 'x+t' => \true, 'c+t' => \true, 'a' => \true, 'a+' => \true]];
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @param resource $resource
|
||||
*
|
||||
* @return Stream
|
||||
*/
|
||||
public static function createFromResource($resource)
|
||||
{
|
||||
if (!\is_resource($resource)) {
|
||||
throw new \InvalidArgumentException('Stream must be a resource');
|
||||
}
|
||||
$obj = new self();
|
||||
$obj->stream = $resource;
|
||||
$meta = \stream_get_meta_data($obj->stream);
|
||||
$obj->seekable = $meta['seekable'];
|
||||
$obj->readable = isset(self::$readWriteHash['read'][$meta['mode']]);
|
||||
$obj->writable = isset(self::$readWriteHash['write'][$meta['mode']]);
|
||||
$obj->uri = $obj->getMetadata('uri');
|
||||
return $obj;
|
||||
}
|
||||
/**
|
||||
* @param string $content
|
||||
*
|
||||
* @return Stream
|
||||
*/
|
||||
public static function create($content)
|
||||
{
|
||||
$resource = \fopen('php://temp', 'rwb+');
|
||||
$stream = self::createFromResource($resource);
|
||||
$stream->write($content);
|
||||
$stream->seek(0);
|
||||
return $stream;
|
||||
}
|
||||
/**
|
||||
* Closes the stream when the destructed.
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->close();
|
||||
}
|
||||
public function __toString() : string
|
||||
{
|
||||
try {
|
||||
if ($this->isSeekable()) {
|
||||
$this->seek(0);
|
||||
}
|
||||
return $this->getContents();
|
||||
} catch (\Exception $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
public function close() : void
|
||||
{
|
||||
if (isset($this->stream)) {
|
||||
if (\is_resource($this->stream)) {
|
||||
\fclose($this->stream);
|
||||
}
|
||||
$this->detach();
|
||||
}
|
||||
}
|
||||
public function detach()
|
||||
{
|
||||
if (!isset($this->stream)) {
|
||||
return;
|
||||
}
|
||||
$result = $this->stream;
|
||||
unset($this->stream);
|
||||
$this->size = $this->uri = null;
|
||||
$this->readable = $this->writable = $this->seekable = \false;
|
||||
return $result;
|
||||
}
|
||||
public function getSize() : ?int
|
||||
{
|
||||
if ($this->size !== null) {
|
||||
return $this->size;
|
||||
}
|
||||
if (!isset($this->stream)) {
|
||||
return null;
|
||||
}
|
||||
// Clear the stat cache if the stream has a URI
|
||||
if ($this->uri) {
|
||||
\clearstatcache(\true, $this->uri);
|
||||
}
|
||||
$stats = \fstat($this->stream);
|
||||
if (isset($stats['size'])) {
|
||||
$this->size = $stats['size'];
|
||||
return $this->size;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function tell() : int
|
||||
{
|
||||
$result = \ftell($this->stream);
|
||||
if ($result === \false) {
|
||||
throw new \RuntimeException('Unable to determine stream position');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function eof() : bool
|
||||
{
|
||||
return !$this->stream || \feof($this->stream);
|
||||
}
|
||||
public function isSeekable() : bool
|
||||
{
|
||||
return $this->seekable;
|
||||
}
|
||||
public function seek(int $offset, int $whence = \SEEK_SET) : void
|
||||
{
|
||||
if (!$this->seekable) {
|
||||
throw new \RuntimeException('Stream is not seekable');
|
||||
}
|
||||
if (\fseek($this->stream, $offset, $whence) === -1) {
|
||||
throw new \RuntimeException('Unable to seek to stream position ' . $offset . ' with whence ' . \var_export($whence, \true));
|
||||
}
|
||||
}
|
||||
public function rewind() : void
|
||||
{
|
||||
$this->seek(0);
|
||||
}
|
||||
public function isWritable() : bool
|
||||
{
|
||||
return $this->writable;
|
||||
}
|
||||
public function write(string $string) : int
|
||||
{
|
||||
if (!$this->writable) {
|
||||
throw new \RuntimeException('Cannot write to a non-writable stream');
|
||||
}
|
||||
// We can't know the size after writing anything
|
||||
$this->size = null;
|
||||
$result = \fwrite($this->stream, $string);
|
||||
if ($result === \false) {
|
||||
throw new \RuntimeException('Unable to write to stream');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function isReadable() : bool
|
||||
{
|
||||
return $this->readable;
|
||||
}
|
||||
public function read(int $length) : string
|
||||
{
|
||||
if (!$this->readable) {
|
||||
throw new \RuntimeException('Cannot read from non-readable stream');
|
||||
}
|
||||
return \fread($this->stream, $length);
|
||||
}
|
||||
public function getContents() : string
|
||||
{
|
||||
if (!isset($this->stream)) {
|
||||
throw new \RuntimeException('Unable to read stream contents');
|
||||
}
|
||||
$contents = \stream_get_contents($this->stream);
|
||||
if ($contents === \false) {
|
||||
throw new \RuntimeException('Unable to read stream contents');
|
||||
}
|
||||
return $contents;
|
||||
}
|
||||
public function getMetadata(?string $key = null) : bool
|
||||
{
|
||||
if (!isset($this->stream)) {
|
||||
return $key ? null : [];
|
||||
}
|
||||
if ($key === null) {
|
||||
return \stream_get_meta_data($this->stream);
|
||||
}
|
||||
$meta = \stream_get_meta_data($this->stream);
|
||||
return isset($meta[$key]) ? $meta[$key] : null;
|
||||
}
|
||||
}
|
240
dependencies/mpdf/psr-http-message-shim/src/Uri.php
vendored
Normal file
240
dependencies/mpdf/psr-http-message-shim/src/Uri.php
vendored
Normal file
@ -0,0 +1,240 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Ultimo\Dependencies\Mpdf\PsrHttpMessageShim;
|
||||
|
||||
use WP_Ultimo\Dependencies\Psr\Http\Message\UriInterface;
|
||||
/**
|
||||
* PSR-7 URI implementation ported from nyholm/psr7 and adapted for PHP 5.6
|
||||
*
|
||||
* @link https://github.com/Nyholm/psr7/blob/master/src/Uri.php
|
||||
*/
|
||||
final class Uri implements UriInterface
|
||||
{
|
||||
private static $schemes = ['http' => 80, 'https' => 443];
|
||||
const CHAR_UNRESERVED = 'a-zA-Z0-9_\\-\\.~';
|
||||
const CHAR_SUB_DELIMS = '!\\$&\'\\(\\)\\*\\+,;=';
|
||||
/** @var string Uri scheme. */
|
||||
private $scheme = '';
|
||||
/** @var string Uri user info. */
|
||||
private $userInfo = '';
|
||||
/** @var string Uri host. */
|
||||
private $host = '';
|
||||
/** @var int|null Uri port. */
|
||||
private $port;
|
||||
/** @var string Uri path. */
|
||||
private $path = '';
|
||||
/** @var string Uri query string. */
|
||||
private $query = '';
|
||||
/** @var string Uri fragment. */
|
||||
private $fragment = '';
|
||||
public function __construct($uri = '')
|
||||
{
|
||||
if ('' !== $uri) {
|
||||
if (\false === ($parts = \parse_url($uri))) {
|
||||
throw new \InvalidArgumentException(\sprintf('Unable to parse URI: "%s"', $uri));
|
||||
}
|
||||
// Apply parse_url parts to a URI.
|
||||
$this->scheme = isset($parts['scheme']) ? \strtr($parts['scheme'], 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') : '';
|
||||
$this->userInfo = isset($parts['user']) ? $parts['user'] : '';
|
||||
$this->host = isset($parts['host']) ? \strtr($parts['host'], 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') : '';
|
||||
$this->port = isset($parts['port']) ? $this->filterPort($parts['port']) : null;
|
||||
$this->path = isset($parts['path']) ? $this->filterPath($parts['path']) : '';
|
||||
$this->query = isset($parts['query']) ? $this->filterQueryAndFragment($parts['query']) : '';
|
||||
$this->fragment = isset($parts['fragment']) ? $this->filterQueryAndFragment($parts['fragment']) : '';
|
||||
if (isset($parts['pass'])) {
|
||||
$this->userInfo .= ':' . $parts['pass'];
|
||||
}
|
||||
}
|
||||
}
|
||||
public function __toString() : string
|
||||
{
|
||||
return self::createUriString($this->scheme, $this->getAuthority(), $this->path, $this->query, $this->fragment);
|
||||
}
|
||||
public function getScheme() : string
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
public function getAuthority() : string
|
||||
{
|
||||
if ('' === $this->host) {
|
||||
return '';
|
||||
}
|
||||
$authority = $this->host;
|
||||
if ('' !== $this->userInfo) {
|
||||
$authority = $this->userInfo . '@' . $authority;
|
||||
}
|
||||
if (null !== $this->port) {
|
||||
$authority .= ':' . $this->port;
|
||||
}
|
||||
return $authority;
|
||||
}
|
||||
public function getUserInfo() : string
|
||||
{
|
||||
return $this->userInfo;
|
||||
}
|
||||
public function getHost() : string
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
public function getPort() : ?int
|
||||
{
|
||||
return $this->port;
|
||||
}
|
||||
public function getPath() : string
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
public function getQuery() : string
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
public function getFragment() : string
|
||||
{
|
||||
return $this->fragment;
|
||||
}
|
||||
public function withScheme(string $scheme) : UriInterface
|
||||
{
|
||||
if (!\is_string($scheme)) {
|
||||
throw new \InvalidArgumentException('Scheme must be a string');
|
||||
}
|
||||
if ($this->scheme === ($scheme = \strtr($scheme, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))) {
|
||||
return $this;
|
||||
}
|
||||
$new = clone $this;
|
||||
$new->scheme = $scheme;
|
||||
$new->port = $new->filterPort($new->port);
|
||||
return $new;
|
||||
}
|
||||
public function withUserInfo(string $user, ?string $password = null) : UriInterface
|
||||
{
|
||||
$info = $user;
|
||||
if (null !== $password && '' !== $password) {
|
||||
$info .= ':' . $password;
|
||||
}
|
||||
if ($this->userInfo === $info) {
|
||||
return $this;
|
||||
}
|
||||
$new = clone $this;
|
||||
$new->userInfo = $info;
|
||||
return $new;
|
||||
}
|
||||
public function withHost(string $host) : UriInterface
|
||||
{
|
||||
if (!\is_string($host)) {
|
||||
throw new \InvalidArgumentException('Host must be a string');
|
||||
}
|
||||
if ($this->host === ($host = \strtr($host, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))) {
|
||||
return $this;
|
||||
}
|
||||
$new = clone $this;
|
||||
$new->host = $host;
|
||||
return $new;
|
||||
}
|
||||
public function withPort(?int $port) : UriInterface
|
||||
{
|
||||
if ($this->port === ($port = $this->filterPort($port))) {
|
||||
return $this;
|
||||
}
|
||||
$new = clone $this;
|
||||
$new->port = $port;
|
||||
return $new;
|
||||
}
|
||||
public function withPath(string $path) : UriInterface
|
||||
{
|
||||
if ($this->path === ($path = $this->filterPath($path))) {
|
||||
return $this;
|
||||
}
|
||||
$new = clone $this;
|
||||
$new->path = $path;
|
||||
return $new;
|
||||
}
|
||||
public function withQuery(string $query) : UriInterface
|
||||
{
|
||||
if ($this->query === ($query = $this->filterQueryAndFragment($query))) {
|
||||
return $this;
|
||||
}
|
||||
$new = clone $this;
|
||||
$new->query = $query;
|
||||
return $new;
|
||||
}
|
||||
public function withFragment(string $fragment) : UriInterface
|
||||
{
|
||||
if ($this->fragment === ($fragment = $this->filterQueryAndFragment($fragment))) {
|
||||
return $this;
|
||||
}
|
||||
$new = clone $this;
|
||||
$new->fragment = $fragment;
|
||||
return $new;
|
||||
}
|
||||
/**
|
||||
* Create a URI string from its various parts.
|
||||
*/
|
||||
private static function createUriString(string $scheme, string $authority, string $path, string $query, string $fragment) : string
|
||||
{
|
||||
$uri = '';
|
||||
if ('' !== $scheme) {
|
||||
$uri .= $scheme . ':';
|
||||
}
|
||||
if ('' !== $authority) {
|
||||
$uri .= '//' . $authority;
|
||||
}
|
||||
if ('' !== $path) {
|
||||
if ('/' !== $path[0]) {
|
||||
if ('' !== $authority) {
|
||||
// If the path is rootless and an authority is present, the path MUST be prefixed by "/"
|
||||
$path = '/' . $path;
|
||||
}
|
||||
} elseif (isset($path[1]) && '/' === $path[1]) {
|
||||
if ('' === $authority) {
|
||||
// If the path is starting with more than one "/" and no authority is present, the
|
||||
// starting slashes MUST be reduced to one.
|
||||
$path = '/' . \ltrim($path, '/');
|
||||
}
|
||||
}
|
||||
$uri .= $path;
|
||||
}
|
||||
if ('' !== $query) {
|
||||
$uri .= '?' . $query;
|
||||
}
|
||||
if ('' !== $fragment) {
|
||||
$uri .= '#' . $fragment;
|
||||
}
|
||||
return $uri;
|
||||
}
|
||||
/**
|
||||
* Is a given port non-standard for the current scheme?
|
||||
*/
|
||||
private static function isNonStandardPort(string $scheme, int $port) : bool
|
||||
{
|
||||
return !isset(self::$schemes[$scheme]) || $port !== self::$schemes[$scheme];
|
||||
}
|
||||
private function filterPort(int $port) : ?int
|
||||
{
|
||||
if (null === $port) {
|
||||
return null;
|
||||
}
|
||||
$port = (int) $port;
|
||||
if (0 > $port || 0xffff < $port) {
|
||||
throw new \InvalidArgumentException(\sprintf('Invalid port: %d. Must be between 0 and 65535', $port));
|
||||
}
|
||||
return self::isNonStandardPort($this->scheme, $port) ? $port : null;
|
||||
}
|
||||
private function filterPath($path)
|
||||
{
|
||||
if (!\is_string($path)) {
|
||||
throw new \InvalidArgumentException('Path must be a string');
|
||||
}
|
||||
return \preg_replace_callback('/(?:[^' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . '%:@\\/]++|%(?![A-Fa-f0-9]{2}))/', [__CLASS__, 'rawurlencodeMatchZero'], $path);
|
||||
}
|
||||
private function filterQueryAndFragment($str)
|
||||
{
|
||||
if (!\is_string($str)) {
|
||||
throw new \InvalidArgumentException('Query and fragment must be a string');
|
||||
}
|
||||
return \preg_replace_callback('/(?:[^' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . '%:@\\/\\?]++|%(?![A-Fa-f0-9]{2}))/', [__CLASS__, 'rawurlencodeMatchZero'], $str);
|
||||
}
|
||||
private static function rawurlencodeMatchZero(array $match)
|
||||
{
|
||||
return \rawurlencode($match[0]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user