Normalize imports for global namespace
This commit is contained in:
parent
ff28f3c6eb
commit
e6d1398bb1
|
|
@ -14,5 +14,10 @@ return PhpCsFixer\Config::create()
|
||||||
'blank_line_after_opening_tag' => true,
|
'blank_line_after_opening_tag' => true,
|
||||||
'cast_spaces' => true,
|
'cast_spaces' => true,
|
||||||
'class_attributes_separation' => ['elements' => ['method']],
|
'class_attributes_separation' => ['elements' => ['method']],
|
||||||
|
'global_namespace_import' => [
|
||||||
|
'import_classes' => true,
|
||||||
|
'import_constants' => true,
|
||||||
|
'import_functions' => true,
|
||||||
|
],
|
||||||
'single_quote' => true
|
'single_quote' => true
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace WellRESTed\Dispatching;
|
namespace WellRESTed\Dispatching;
|
||||||
|
|
||||||
class DispatchException extends \InvalidArgumentException
|
use InvalidArgumentException;
|
||||||
|
|
||||||
|
class DispatchException extends InvalidArgumentException
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace WellRESTed\Message;
|
||||||
|
|
||||||
use Psr\Http\Message\MessageInterface;
|
use Psr\Http\Message\MessageInterface;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message defines core functionality for classes that represent HTTP messages.
|
* Message defines core functionality for classes that represent HTTP messages.
|
||||||
|
|
@ -189,7 +190,7 @@ abstract class Message implements MessageInterface
|
||||||
* @param string $name Case-insensitive header field name.
|
* @param string $name Case-insensitive header field name.
|
||||||
* @param string|string[] $value Header value(s).
|
* @param string|string[] $value Header value(s).
|
||||||
* @return static
|
* @return static
|
||||||
* @throws \InvalidArgumentException for invalid header names or values.
|
* @throws InvalidArgumentException for invalid header names or values.
|
||||||
*/
|
*/
|
||||||
public function withHeader($name, $value)
|
public function withHeader($name, $value)
|
||||||
{
|
{
|
||||||
|
|
@ -213,7 +214,7 @@ abstract class Message implements MessageInterface
|
||||||
* @param string $name Case-insensitive header field name to add.
|
* @param string $name Case-insensitive header field name to add.
|
||||||
* @param string|string[] $value Header value(s).
|
* @param string|string[] $value Header value(s).
|
||||||
* @return static
|
* @return static
|
||||||
* @throws \InvalidArgumentException for invalid header names or values.
|
* @throws InvalidArgumentException for invalid header names or values.
|
||||||
*/
|
*/
|
||||||
public function withAddedHeader($name, $value)
|
public function withAddedHeader($name, $value)
|
||||||
{
|
{
|
||||||
|
|
@ -256,7 +257,7 @@ abstract class Message implements MessageInterface
|
||||||
*
|
*
|
||||||
* @param StreamInterface $body Body.
|
* @param StreamInterface $body Body.
|
||||||
* @return static
|
* @return static
|
||||||
* @throws \InvalidArgumentException When the body is not valid.
|
* @throws InvalidArgumentException When the body is not valid.
|
||||||
*/
|
*/
|
||||||
public function withBody(StreamInterface $body)
|
public function withBody(StreamInterface $body)
|
||||||
{
|
{
|
||||||
|
|
@ -271,13 +272,13 @@ abstract class Message implements MessageInterface
|
||||||
* @param mixed $name
|
* @param mixed $name
|
||||||
* @param mixed|mixed[] $values
|
* @param mixed|mixed[] $values
|
||||||
* @return string[]
|
* @return string[]
|
||||||
* @throws \InvalidArgumentException Name is not a string or value is not
|
* @throws InvalidArgumentException Name is not a string or value is not
|
||||||
* a string or array of strings
|
* a string or array of strings
|
||||||
*/
|
*/
|
||||||
private function getValidatedHeaders($name, $values)
|
private function getValidatedHeaders($name, $values)
|
||||||
{
|
{
|
||||||
if (!is_string($name)) {
|
if (!is_string($name)) {
|
||||||
throw new \InvalidArgumentException('Header name must be a string');
|
throw new InvalidArgumentException('Header name must be a string');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($values)) {
|
if (!is_array($values)) {
|
||||||
|
|
@ -290,7 +291,7 @@ abstract class Message implements MessageInterface
|
||||||
|
|
||||||
$invalid = array_filter($values, $isNotStringOrNumber);
|
$invalid = array_filter($values, $isNotStringOrNumber);
|
||||||
if ($invalid) {
|
if ($invalid) {
|
||||||
throw new \InvalidArgumentException('Header values must be a string or string[]');
|
throw new InvalidArgumentException('Header values must be a string or string[]');
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_map('strval', $values);
|
return array_map('strval', $values);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace WellRESTed\Message;
|
namespace WellRESTed\Message;
|
||||||
|
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NullStream is a minimal, always-empty, non-writable stream.
|
* NullStream is a minimal, always-empty, non-writable stream.
|
||||||
|
|
@ -54,7 +55,7 @@ class NullStream implements StreamInterface
|
||||||
* Returns the current position of the file read/write pointer
|
* Returns the current position of the file read/write pointer
|
||||||
*
|
*
|
||||||
* @return int Position of the file pointer
|
* @return int Position of the file pointer
|
||||||
* @throws \RuntimeException on error.
|
* @throws RuntimeException on error.
|
||||||
*/
|
*/
|
||||||
public function tell()
|
public function tell()
|
||||||
{
|
{
|
||||||
|
|
@ -92,11 +93,11 @@ class NullStream implements StreamInterface
|
||||||
* offset bytes SEEK_CUR: Set position to current location plus offset
|
* offset bytes SEEK_CUR: Set position to current location plus offset
|
||||||
* SEEK_END: Set position to end-of-stream plus offset.
|
* SEEK_END: Set position to end-of-stream plus offset.
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \RuntimeException on failure.
|
* @throws RuntimeException on failure.
|
||||||
*/
|
*/
|
||||||
public function seek($offset, $whence = SEEK_SET)
|
public function seek($offset, $whence = SEEK_SET)
|
||||||
{
|
{
|
||||||
throw new \RuntimeException('Unable to seek to position.');
|
throw new RuntimeException('Unable to seek to position.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -105,11 +106,11 @@ class NullStream implements StreamInterface
|
||||||
* @see seek()
|
* @see seek()
|
||||||
* @link http://www.php.net/manual/en/function.fseek.php
|
* @link http://www.php.net/manual/en/function.fseek.php
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \RuntimeException on failure.
|
* @throws RuntimeException on failure.
|
||||||
*/
|
*/
|
||||||
public function rewind()
|
public function rewind()
|
||||||
{
|
{
|
||||||
throw new \RuntimeException('Unable to rewind stream.');
|
throw new RuntimeException('Unable to rewind stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -127,11 +128,11 @@ class NullStream implements StreamInterface
|
||||||
*
|
*
|
||||||
* @param string $string The string that is to be written.
|
* @param string $string The string that is to be written.
|
||||||
* @return int Returns the number of bytes written to the stream.
|
* @return int Returns the number of bytes written to the stream.
|
||||||
* @throws \RuntimeException on failure.
|
* @throws RuntimeException on failure.
|
||||||
*/
|
*/
|
||||||
public function write($string)
|
public function write($string)
|
||||||
{
|
{
|
||||||
throw new \RuntimeException('Unable to write to stream.');
|
throw new RuntimeException('Unable to write to stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -152,7 +153,7 @@ class NullStream implements StreamInterface
|
||||||
* call returns fewer bytes.
|
* call returns fewer bytes.
|
||||||
* @return string Returns the data read from the stream, or an empty string
|
* @return string Returns the data read from the stream, or an empty string
|
||||||
* if no bytes are available.
|
* if no bytes are available.
|
||||||
* @throws \RuntimeException if an error occurs.
|
* @throws RuntimeException if an error occurs.
|
||||||
*/
|
*/
|
||||||
public function read($length)
|
public function read($length)
|
||||||
{
|
{
|
||||||
|
|
@ -163,7 +164,7 @@ class NullStream implements StreamInterface
|
||||||
* Returns the remaining contents in a string
|
* Returns the remaining contents in a string
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \RuntimeException if unable to read or an error occurs while
|
* @throws RuntimeException if unable to read or an error occurs while
|
||||||
* reading.
|
* reading.
|
||||||
*/
|
*/
|
||||||
public function getContents()
|
public function getContents()
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace WellRESTed\Message;
|
||||||
use Psr\Http\Message\RequestInterface;
|
use Psr\Http\Message\RequestInterface;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
use Psr\Http\Message\UriInterface;
|
use Psr\Http\Message\UriInterface;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Representation of an outgoing, client-side request.
|
* Representation of an outgoing, client-side request.
|
||||||
|
|
@ -135,7 +136,7 @@ class Request extends Message implements RequestInterface
|
||||||
*
|
*
|
||||||
* @param string $method Case-insensitive method.
|
* @param string $method Case-insensitive method.
|
||||||
* @return static
|
* @return static
|
||||||
* @throws \InvalidArgumentException for invalid HTTP methods.
|
* @throws InvalidArgumentException for invalid HTTP methods.
|
||||||
*/
|
*/
|
||||||
public function withMethod($method)
|
public function withMethod($method)
|
||||||
{
|
{
|
||||||
|
|
@ -211,16 +212,16 @@ class Request extends Message implements RequestInterface
|
||||||
/**
|
/**
|
||||||
* @param mixed $method
|
* @param mixed $method
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
private function getValidatedMethod($method)
|
private function getValidatedMethod($method)
|
||||||
{
|
{
|
||||||
if (!is_string($method)) {
|
if (!is_string($method)) {
|
||||||
throw new \InvalidArgumentException('Method must be a string.');
|
throw new InvalidArgumentException('Method must be a string.');
|
||||||
}
|
}
|
||||||
$method = trim($method);
|
$method = trim($method);
|
||||||
if (strpos($method, ' ') !== false) {
|
if (strpos($method, ' ') !== false) {
|
||||||
throw new \InvalidArgumentException('Method cannot contain spaces.');
|
throw new InvalidArgumentException('Method cannot contain spaces.');
|
||||||
}
|
}
|
||||||
return $method;
|
return $method;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace WellRESTed\Message;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Representation of an outgoing, server-side response.
|
* Representation of an outgoing, server-side response.
|
||||||
|
|
@ -77,7 +78,7 @@ class Response extends Message implements ResponseInterface
|
||||||
* provided status code; if none is provided, implementations MAY
|
* provided status code; if none is provided, implementations MAY
|
||||||
* use the defaults as suggested in the HTTP specification.
|
* use the defaults as suggested in the HTTP specification.
|
||||||
* @return static
|
* @return static
|
||||||
* @throws \InvalidArgumentException For invalid status code arguments.
|
* @throws InvalidArgumentException For invalid status code arguments.
|
||||||
*/
|
*/
|
||||||
public function withStatus($code, $reasonPhrase = '')
|
public function withStatus($code, $reasonPhrase = '')
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
use Psr\Http\Message\UploadedFileInterface;
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
use Psr\Http\Message\UriInterface;
|
use Psr\Http\Message\UriInterface;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Representation of an incoming, server-side HTTP request.
|
* Representation of an incoming, server-side HTTP request.
|
||||||
|
|
@ -189,12 +190,12 @@ class ServerRequest extends Request implements ServerRequestInterface
|
||||||
*
|
*
|
||||||
* @param array $uploadedFiles An array tree of UploadedFileInterface instances.
|
* @param array $uploadedFiles An array tree of UploadedFileInterface instances.
|
||||||
* @return static
|
* @return static
|
||||||
* @throws \InvalidArgumentException if an invalid structure is provided.
|
* @throws InvalidArgumentException if an invalid structure is provided.
|
||||||
*/
|
*/
|
||||||
public function withUploadedFiles(array $uploadedFiles)
|
public function withUploadedFiles(array $uploadedFiles)
|
||||||
{
|
{
|
||||||
if (!$this->isValidUploadedFilesTree($uploadedFiles)) {
|
if (!$this->isValidUploadedFilesTree($uploadedFiles)) {
|
||||||
throw new \InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
'withUploadedFiles expects an array tree with UploadedFileInterface leaves.'
|
'withUploadedFiles expects an array tree with UploadedFileInterface leaves.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -249,7 +250,7 @@ class ServerRequest extends Request implements ServerRequestInterface
|
||||||
public function withParsedBody($data)
|
public function withParsedBody($data)
|
||||||
{
|
{
|
||||||
if (!(is_null($data) || is_array($data) || is_object($data))) {
|
if (!(is_null($data) || is_array($data) || is_object($data))) {
|
||||||
throw new \InvalidArgumentException('Parsed body must be null, array, or object.');
|
throw new InvalidArgumentException('Parsed body must be null, array, or object.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$request = clone $this;
|
$request = clone $this;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@
|
||||||
namespace WellRESTed\Message;
|
namespace WellRESTed\Message;
|
||||||
|
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use Exception;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
class Stream implements StreamInterface
|
class Stream implements StreamInterface
|
||||||
{
|
{
|
||||||
|
|
@ -32,7 +35,7 @@ class Stream implements StreamInterface
|
||||||
$this->write($resource);
|
$this->write($resource);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException('Expected a resource handler.');
|
throw new InvalidArgumentException('Expected a resource handler.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,7 +57,7 @@ class Stream implements StreamInterface
|
||||||
$this->rewind();
|
$this->rewind();
|
||||||
}
|
}
|
||||||
return $this->getContents();
|
return $this->getContents();
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
// Silence exceptions in order to conform with PHP's string casting
|
// Silence exceptions in order to conform with PHP's string casting
|
||||||
// operations.
|
// operations.
|
||||||
return '';
|
return '';
|
||||||
|
|
@ -113,17 +116,17 @@ class Stream implements StreamInterface
|
||||||
* Returns the current position of the file read/write pointer
|
* Returns the current position of the file read/write pointer
|
||||||
*
|
*
|
||||||
* @return int Position of the file pointer
|
* @return int Position of the file pointer
|
||||||
* @throws \RuntimeException on error.
|
* @throws RuntimeException on error.
|
||||||
*/
|
*/
|
||||||
public function tell()
|
public function tell()
|
||||||
{
|
{
|
||||||
if ($this->resource === null) {
|
if ($this->resource === null) {
|
||||||
throw new \RuntimeException('Unable to retrieve current position of detached stream.');
|
throw new RuntimeException('Unable to retrieve current position of detached stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$position = ftell($this->resource);
|
$position = ftell($this->resource);
|
||||||
if ($position === false) {
|
if ($position === false) {
|
||||||
throw new \RuntimeException('Unable to retrieve current position of file pointer.');
|
throw new RuntimeException('Unable to retrieve current position of file pointer.');
|
||||||
}
|
}
|
||||||
return $position;
|
return $position;
|
||||||
}
|
}
|
||||||
|
|
@ -167,12 +170,12 @@ class Stream implements StreamInterface
|
||||||
* offset bytes SEEK_CUR: Set position to current location plus offset
|
* offset bytes SEEK_CUR: Set position to current location plus offset
|
||||||
* SEEK_END: Set position to end-of-stream plus offset.
|
* SEEK_END: Set position to end-of-stream plus offset.
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \RuntimeException on failure.
|
* @throws RuntimeException on failure.
|
||||||
*/
|
*/
|
||||||
public function seek($offset, $whence = SEEK_SET)
|
public function seek($offset, $whence = SEEK_SET)
|
||||||
{
|
{
|
||||||
if ($this->resource === null) {
|
if ($this->resource === null) {
|
||||||
throw new \RuntimeException('Unable to seek detached stream.');
|
throw new RuntimeException('Unable to seek detached stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = -1;
|
$result = -1;
|
||||||
|
|
@ -180,7 +183,7 @@ class Stream implements StreamInterface
|
||||||
$result = fseek($this->resource, $offset, $whence);
|
$result = fseek($this->resource, $offset, $whence);
|
||||||
}
|
}
|
||||||
if ($result === -1) {
|
if ($result === -1) {
|
||||||
throw new \RuntimeException('Unable to seek to position.');
|
throw new RuntimeException('Unable to seek to position.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,12 +196,12 @@ class Stream implements StreamInterface
|
||||||
* @see seek()
|
* @see seek()
|
||||||
* @link http://www.php.net/manual/en/function.fseek.php
|
* @link http://www.php.net/manual/en/function.fseek.php
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \RuntimeException on failure.
|
* @throws RuntimeException on failure.
|
||||||
*/
|
*/
|
||||||
public function rewind()
|
public function rewind()
|
||||||
{
|
{
|
||||||
if ($this->resource === null) {
|
if ($this->resource === null) {
|
||||||
throw new \RuntimeException('Unable to seek detached stream.');
|
throw new RuntimeException('Unable to seek detached stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
@ -206,7 +209,7 @@ class Stream implements StreamInterface
|
||||||
$result = rewind($this->resource);
|
$result = rewind($this->resource);
|
||||||
}
|
}
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
throw new \RuntimeException('Unable to rewind.');
|
throw new RuntimeException('Unable to rewind.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -230,12 +233,12 @@ class Stream implements StreamInterface
|
||||||
*
|
*
|
||||||
* @param string $string The string that is to be written.
|
* @param string $string The string that is to be written.
|
||||||
* @return int Returns the number of bytes written to the stream.
|
* @return int Returns the number of bytes written to the stream.
|
||||||
* @throws \RuntimeException on failure.
|
* @throws RuntimeException on failure.
|
||||||
*/
|
*/
|
||||||
public function write($string)
|
public function write($string)
|
||||||
{
|
{
|
||||||
if ($this->resource === null) {
|
if ($this->resource === null) {
|
||||||
throw new \RuntimeException('Unable to write to detached stream.');
|
throw new RuntimeException('Unable to write to detached stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
@ -243,7 +246,7 @@ class Stream implements StreamInterface
|
||||||
$result = fwrite($this->resource, $string);
|
$result = fwrite($this->resource, $string);
|
||||||
}
|
}
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
throw new \RuntimeException('Unable to write to stream.');
|
throw new RuntimeException('Unable to write to stream.');
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
@ -271,12 +274,12 @@ class Stream implements StreamInterface
|
||||||
* call returns fewer bytes.
|
* call returns fewer bytes.
|
||||||
* @return string Returns the data read from the stream, or an empty string
|
* @return string Returns the data read from the stream, or an empty string
|
||||||
* if no bytes are available.
|
* if no bytes are available.
|
||||||
* @throws \RuntimeException if an error occurs.
|
* @throws RuntimeException if an error occurs.
|
||||||
*/
|
*/
|
||||||
public function read($length)
|
public function read($length)
|
||||||
{
|
{
|
||||||
if ($this->resource === null) {
|
if ($this->resource === null) {
|
||||||
throw new \RuntimeException('Unable to read to detached stream.');
|
throw new RuntimeException('Unable to read to detached stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
@ -284,7 +287,7 @@ class Stream implements StreamInterface
|
||||||
$result = fread($this->resource, $length);
|
$result = fread($this->resource, $length);
|
||||||
}
|
}
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
throw new \RuntimeException('Unable to read from stream.');
|
throw new RuntimeException('Unable to read from stream.');
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
@ -293,13 +296,13 @@ class Stream implements StreamInterface
|
||||||
* Returns the remaining contents in a string
|
* Returns the remaining contents in a string
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \RuntimeException if unable to read or an error occurs while
|
* @throws RuntimeException if unable to read or an error occurs while
|
||||||
* reading.
|
* reading.
|
||||||
*/
|
*/
|
||||||
public function getContents()
|
public function getContents()
|
||||||
{
|
{
|
||||||
if ($this->resource === null) {
|
if ($this->resource === null) {
|
||||||
throw new \RuntimeException('Unable to read to detached stream.');
|
throw new RuntimeException('Unable to read to detached stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
@ -307,7 +310,7 @@ class Stream implements StreamInterface
|
||||||
$result = stream_get_contents($this->resource);
|
$result = stream_get_contents($this->resource);
|
||||||
}
|
}
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
throw new \RuntimeException('Unable to read from stream.');
|
throw new RuntimeException('Unable to read from stream.');
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ namespace WellRESTed\Message;
|
||||||
|
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
use Psr\Http\Message\UploadedFileInterface;
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Value object representing a file uploaded through an HTTP request.
|
* Value object representing a file uploaded through an HTTP request.
|
||||||
|
|
@ -85,19 +87,19 @@ class UploadedFile implements UploadedFileInterface
|
||||||
* raise an exception.
|
* raise an exception.
|
||||||
*
|
*
|
||||||
* @return StreamInterface Stream representation of the uploaded file.
|
* @return StreamInterface Stream representation of the uploaded file.
|
||||||
* @throws \RuntimeException in cases when no stream is available or can
|
* @throws RuntimeException in cases when no stream is available or can
|
||||||
* be created.
|
* be created.
|
||||||
*/
|
*/
|
||||||
public function getStream()
|
public function getStream()
|
||||||
{
|
{
|
||||||
if ($this->tmpName === null) {
|
if ($this->tmpName === null) {
|
||||||
throw new \RuntimeException('Unable to read uploaded file.');
|
throw new RuntimeException('Unable to read uploaded file.');
|
||||||
}
|
}
|
||||||
if ($this->moved) {
|
if ($this->moved) {
|
||||||
throw new \RuntimeException('File has already been moved.');
|
throw new RuntimeException('File has already been moved.');
|
||||||
}
|
}
|
||||||
if (php_sapi_name() !== 'cli' && !is_uploaded_file($this->tmpName)) {
|
if (php_sapi_name() !== 'cli' && !is_uploaded_file($this->tmpName)) {
|
||||||
throw new \RuntimeException('File is not an uploaded file.');
|
throw new RuntimeException('File is not an uploaded file.');
|
||||||
}
|
}
|
||||||
return $this->stream;
|
return $this->stream;
|
||||||
}
|
}
|
||||||
|
|
@ -117,14 +119,14 @@ class UploadedFile implements UploadedFileInterface
|
||||||
* @see http://php.net/move_uploaded_file
|
* @see http://php.net/move_uploaded_file
|
||||||
* @param string $path Path to which to move the uploaded file.
|
* @param string $path Path to which to move the uploaded file.
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \InvalidArgumentException if the $path specified is invalid.
|
* @throws InvalidArgumentException if the $path specified is invalid.
|
||||||
* @throws \RuntimeException on any error during the move operation, or on
|
* @throws RuntimeException on any error during the move operation, or on
|
||||||
* the second or subsequent call to the method.
|
* the second or subsequent call to the method.
|
||||||
*/
|
*/
|
||||||
public function moveTo($path)
|
public function moveTo($path)
|
||||||
{
|
{
|
||||||
if ($this->tmpName === null || !file_exists($this->tmpName)) {
|
if ($this->tmpName === null || !file_exists($this->tmpName)) {
|
||||||
throw new \RuntimeException('File ' . $this->tmpName . ' does not exist.');
|
throw new RuntimeException('File ' . $this->tmpName . ' does not exist.');
|
||||||
}
|
}
|
||||||
if (php_sapi_name() === 'cli') {
|
if (php_sapi_name() === 'cli') {
|
||||||
rename($this->tmpName, $path);
|
rename($this->tmpName, $path);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace WellRESTed\Message;
|
namespace WellRESTed\Message;
|
||||||
|
|
||||||
use Psr\Http\Message\UriInterface;
|
use Psr\Http\Message\UriInterface;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Value object representing a URI.
|
* Value object representing a URI.
|
||||||
|
|
@ -301,13 +302,13 @@ class Uri implements UriInterface
|
||||||
*
|
*
|
||||||
* @param string $scheme The scheme to use with the new instance.
|
* @param string $scheme The scheme to use with the new instance.
|
||||||
* @return static A new instance with the specified scheme.
|
* @return static A new instance with the specified scheme.
|
||||||
* @throws \InvalidArgumentException for invalid or unsupported schemes.
|
* @throws InvalidArgumentException for invalid or unsupported schemes.
|
||||||
*/
|
*/
|
||||||
public function withScheme($scheme)
|
public function withScheme($scheme)
|
||||||
{
|
{
|
||||||
$scheme = $scheme ? strtolower($scheme) : '';
|
$scheme = $scheme ? strtolower($scheme) : '';
|
||||||
if (!in_array($scheme, ['', 'http', 'https'])) {
|
if (!in_array($scheme, ['', 'http', 'https'])) {
|
||||||
throw new \InvalidArgumentException('Scheme must be http, https, or empty.');
|
throw new InvalidArgumentException('Scheme must be http, https, or empty.');
|
||||||
}
|
}
|
||||||
$uri = clone $this;
|
$uri = clone $this;
|
||||||
$uri->scheme = $scheme;
|
$uri->scheme = $scheme;
|
||||||
|
|
@ -346,12 +347,12 @@ class Uri implements UriInterface
|
||||||
*
|
*
|
||||||
* @param string $host The hostname to use with the new instance.
|
* @param string $host The hostname to use with the new instance.
|
||||||
* @return static A new instance with the specified host.
|
* @return static A new instance with the specified host.
|
||||||
* @throws \InvalidArgumentException for invalid hostnames.
|
* @throws InvalidArgumentException for invalid hostnames.
|
||||||
*/
|
*/
|
||||||
public function withHost($host)
|
public function withHost($host)
|
||||||
{
|
{
|
||||||
if (!is_string($host)) {
|
if (!is_string($host)) {
|
||||||
throw new \InvalidArgumentException('Host must be a string.');
|
throw new InvalidArgumentException('Host must be a string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$uri = clone $this;
|
$uri = clone $this;
|
||||||
|
|
@ -374,18 +375,18 @@ class Uri implements UriInterface
|
||||||
* @param null|int $port The port to use with the new instance; a null value
|
* @param null|int $port The port to use with the new instance; a null value
|
||||||
* removes the port information.
|
* removes the port information.
|
||||||
* @return static A new instance with the specified port.
|
* @return static A new instance with the specified port.
|
||||||
* @throws \InvalidArgumentException for invalid ports.
|
* @throws InvalidArgumentException for invalid ports.
|
||||||
*/
|
*/
|
||||||
public function withPort($port)
|
public function withPort($port)
|
||||||
{
|
{
|
||||||
if (is_numeric($port)) {
|
if (is_numeric($port)) {
|
||||||
if ($port < self::MIN_PORT || $port > self::MAX_PORT) {
|
if ($port < self::MIN_PORT || $port > self::MAX_PORT) {
|
||||||
$message = sprintf('Port must be between %s and %s.', self::MIN_PORT, self::MAX_PORT);
|
$message = sprintf('Port must be between %s and %s.', self::MIN_PORT, self::MAX_PORT);
|
||||||
throw new \InvalidArgumentException($message);
|
throw new InvalidArgumentException($message);
|
||||||
}
|
}
|
||||||
$port = (int) $port;
|
$port = (int) $port;
|
||||||
} elseif ($port !== null) {
|
} elseif ($port !== null) {
|
||||||
throw new \InvalidArgumentException('Port must be an int or null.');
|
throw new InvalidArgumentException('Port must be an int or null.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$uri = clone $this;
|
$uri = clone $this;
|
||||||
|
|
@ -408,12 +409,12 @@ class Uri implements UriInterface
|
||||||
*
|
*
|
||||||
* @param string $path The path to use with the new instance.
|
* @param string $path The path to use with the new instance.
|
||||||
* @return static A new instance with the specified path.
|
* @return static A new instance with the specified path.
|
||||||
* @throws \InvalidArgumentException for invalid paths.
|
* @throws InvalidArgumentException for invalid paths.
|
||||||
*/
|
*/
|
||||||
public function withPath($path)
|
public function withPath($path)
|
||||||
{
|
{
|
||||||
if (!is_string($path)) {
|
if (!is_string($path)) {
|
||||||
throw new \InvalidArgumentException('Path must be a string');
|
throw new InvalidArgumentException('Path must be a string');
|
||||||
}
|
}
|
||||||
$uri = clone $this;
|
$uri = clone $this;
|
||||||
$uri->path = $path;
|
$uri->path = $path;
|
||||||
|
|
@ -433,7 +434,7 @@ class Uri implements UriInterface
|
||||||
*
|
*
|
||||||
* @param string $query The query string to use with the new instance.
|
* @param string $query The query string to use with the new instance.
|
||||||
* @return static A new instance with the specified query string.
|
* @return static A new instance with the specified query string.
|
||||||
* @throws \InvalidArgumentException for invalid query strings.
|
* @throws InvalidArgumentException for invalid query strings.
|
||||||
*/
|
*/
|
||||||
public function withQuery($query)
|
public function withQuery($query)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace WellRESTed\Routing\Route;
|
namespace WellRESTed\Routing\Route;
|
||||||
|
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
class RegexRoute extends Route
|
class RegexRoute extends Route
|
||||||
{
|
{
|
||||||
/** @var array */
|
/** @var array */
|
||||||
|
|
@ -26,7 +28,7 @@ class RegexRoute extends Route
|
||||||
$this->captures = $captures;
|
$this->captures = $captures;
|
||||||
return true;
|
return true;
|
||||||
} elseif ($matched === false) {
|
} elseif ($matched === false) {
|
||||||
throw new \RuntimeException('Invalid regular expression: ' . $this->getTarget());
|
throw new RuntimeException('Invalid regular expression: ' . $this->getTarget());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use WellRESTed\Message\ServerRequest;
|
||||||
use WellRESTed\Test\TestCase;
|
use WellRESTed\Test\TestCase;
|
||||||
use WellRESTed\Transmission\HeaderStack;
|
use WellRESTed\Transmission\HeaderStack;
|
||||||
use WellRESTed\Transmission\Transmitter;
|
use WellRESTed\Transmission\Transmitter;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/HeaderStack.php';
|
require_once __DIR__ . '/../../../src/HeaderStack.php';
|
||||||
|
|
||||||
|
|
@ -135,7 +136,7 @@ class TransmitterTest extends TestCase
|
||||||
|
|
||||||
$this->body->isSeekable()->willReturn(false);
|
$this->body->isSeekable()->willReturn(false);
|
||||||
$this->body->isReadable()->willReturn(true);
|
$this->body->isReadable()->willReturn(true);
|
||||||
$this->body->rewind()->willThrow(new \RuntimeException());
|
$this->body->rewind()->willThrow(new RuntimeException());
|
||||||
$this->body->eof()->willReturn(false);
|
$this->body->eof()->willReturn(false);
|
||||||
$this->body->read(Argument::any())->will(
|
$this->body->read(Argument::any())->will(
|
||||||
function ($args) use ($content, &$position) {
|
function ($args) use ($content, &$position) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue