Skip to content

Commit

Permalink
Merge branch 'JoeBengalen-patch-cleanup' into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
akrabat committed Jul 16, 2015
2 parents bf90e65 + b36da7c commit b54203c
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 78 deletions.
1 change: 0 additions & 1 deletion Slim/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Slim\Http\Body;
use Slim\Http\Request;
use Slim\Interfaces\Http\EnvironmentInterface;
use Slim\Interfaces\InvocationStrategyInterface;
use Slim\Interfaces\RouteGroupInterface;
use Slim\Interfaces\RouteInterface;
use Slim\Interfaces\RouterInterface;
Expand Down
3 changes: 1 addition & 2 deletions Slim/CallableResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public function __construct(ContainerInterface $container, $toResolve = null)
* Receive a string that is to be resolved to a callable
*
* @param string $toResolve
*
* @return void
*/
public function setToResolve($toResolve)
{
Expand All @@ -64,6 +62,7 @@ public function setToResolve($toResolve)
* from the container otherwise instantiate it and then dispatch 'method'.
*
* @return \Closure
*
* @throws RuntimeException if the callable does not exist
* @throws RuntimeException if the callable is not resolvable
*/
Expand Down
5 changes: 3 additions & 2 deletions Slim/CallableResolverAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ trait CallableResolverAwareTrait
* Resolve a string of the format 'class:method' into a closure that the
* router can dispatch.
*
* @param string $callable
* @param string $callable
*
* @return \Closure
* @throws RuntimeException if the string cannot be resolved as a callable
*
* @throws RuntimeException If the string cannot be resolved as a callable
*/
protected function resolveCallable($callable)
{
Expand Down
5 changes: 0 additions & 5 deletions Slim/Exception/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

use Exception as BaseException;
use Psr\Http\Message\ResponseInterface;
use FastRoute\Dispatcher;
use Slim\Http\Uri;
use Slim\Http\Headers;
use Slim\Http\Body;
use Slim\Http\Request;

/**
* Stop Exception
Expand Down
13 changes: 10 additions & 3 deletions Slim/Handlers/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Error
/**
* Invoke error handler
*
* @param ServerRequestInterface $request The most recent Request object
* @param ResponseInterface $response The most recent Response object
* @param \Exception $exception The caught Exception object
* @param ServerRequestInterface $request The most recent Request object
* @param ResponseInterface $response The most recent Response object
* @param Exception $exception The caught Exception object
*
* @return ResponseInterface
*/
Expand Down Expand Up @@ -59,6 +59,13 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
->write($output);
}

/**
* Render exception as html.
*
* @param Exception $exception
*
* @return string
*/
private function renderException(Exception $exception)
{
$code = $exception->getCode();
Expand Down
6 changes: 3 additions & 3 deletions Slim/Handlers/NotAllowed.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class NotAllowed
/**
* Invoke error handler
*
* @param ServerRequestInterface $request The most recent Request object
* @param ResponseInterface $response The most recent Response object
* @param string[] $methods Allowed HTTP methods
* @param ServerRequestInterface $request The most recent Request object
* @param ResponseInterface $response The most recent Response object
* @param string[] $methods Allowed HTTP methods
*
* @return ResponseInterface
*/
Expand Down
4 changes: 2 additions & 2 deletions Slim/Handlers/NotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class NotFound
/**
* Invoke not found handler
*
* @param ServerRequestInterface $request The most recent Request object
* @param ResponseInterface $response The most recent Response object
* @param ServerRequestInterface $request The most recent Request object
* @param ResponseInterface $response The most recent Response object
*
* @return ResponseInterface
*/
Expand Down
1 change: 0 additions & 1 deletion Slim/Handlers/Strategies/RequestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
class RequestResponse implements InvocationStrategyInterface
{

/**
* Invoke a route callable with request, response, and all route parameters
* as an array of arguments.
Expand Down
6 changes: 4 additions & 2 deletions Slim/Http/Cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function setDefaults(array $settings)
* @param string $name Cookie name
* @param mixed $default Cookie default value
*
* @return mixed Cookie value if present, else default
* @return mixed Cookie value if present, else default
*/
public function get($name, $default = null)
{
Expand Down Expand Up @@ -153,7 +153,9 @@ protected function toHeader($name, array $properties)
* into a PHP associative array.
*
* @param string $header The raw HTTP request `Cookie:` header
* @return array Associative array of cookie names and values
*
* @return array Associative array of cookie names and values
*
* @throws InvalidArgumentException if the cookie data cannot be parsed
*/
public static function parseHeader($header)
Expand Down
1 change: 1 addition & 0 deletions Slim/Http/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Environment extends Collection implements EnvironmentInterface
* Create mock environment
*
* @param array $userData Array of custom environment keys and values
*
* @return self
*/
public static function mock(array $userData = [])
Expand Down
7 changes: 5 additions & 2 deletions Slim/Http/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class Headers extends Collection implements HeadersInterface
* Create new headers collection with data extracted from
* the application Environment object
*
* @param Environment $environment The Slim application Environment
* @param Environment $environment The Slim application Environment
*
* @return self
*/
public static function createFromEnvironment(Environment $environment)
Expand Down Expand Up @@ -156,6 +157,7 @@ public function add($key, $value)
* Does this collection have a given header?
*
* @param string $key The case-insensitive header name
*
* @return bool
*/
public function has($key)
Expand All @@ -181,7 +183,8 @@ public function remove($key)
* header names in the other methods in this class.
*
* @param string $key The case-insensitive header name
* @return string Normalized header name
*
* @return string Normalized header name
*/
public function normalizeKey($key)
{
Expand Down
1 change: 1 addition & 0 deletions Slim/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Request implements ServerRequestInterface
* Environment object
*
* @param Environment $environment The Slim application Environment
*
* @return self
*/
public static function createFromEnvironment(Environment $environment)
Expand Down
6 changes: 3 additions & 3 deletions Slim/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ class Response implements ResponseInterface
/**
* Create new HTTP response.
*
* @param int $status The response status code.
* @param HeadersInterface|null $headers The response headers.
* @param StreamInterface|null $body The response body.
* @param int $status The response status code.
* @param HeadersInterface|null $headers The response headers.
* @param StreamInterface|null $body The response body.
*/
public function __construct($status = 200, HeadersInterface $headers = null, StreamInterface $body = null)
{
Expand Down
10 changes: 7 additions & 3 deletions Slim/Http/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected function isAttached()
*
* Note: This method is not part of the PSR-7 standard.
*
* @param resource $newStream A PHP resource handle.
* @param resource $newStream A PHP resource handle.
*
* @throws InvalidArgumentException If argument is not a valid PHP resource.
*/
Expand Down Expand Up @@ -183,8 +183,6 @@ public function __toString()

/**
* Closes the stream and any underlying resources.
*
* @return void
*/
public function close()
{
Expand Down Expand Up @@ -214,6 +212,7 @@ public function getSize()
* Returns the current position of the file read/write pointer
*
* @return int Position of the file pointer
*
* @throws RuntimeException on error.
*/
public function tell()
Expand Down Expand Up @@ -325,7 +324,9 @@ public function seek($offset, $whence = SEEK_SET)
* otherwise, it will perform a seek(0).
*
* @see seek()
*
* @link http://www.php.net/manual/en/function.fseek.php
*
* @throws RuntimeException on failure.
*/
public function rewind()
Expand All @@ -344,6 +345,7 @@ public function rewind()
*
* @return string Returns the data read from the stream, or an empty string
* if no bytes are available.
*
* @throws RuntimeException if an error occurs.
*/
public function read($length)
Expand All @@ -361,6 +363,7 @@ public function read($length)
* @param string $string The string that is to be written.
*
* @return int Returns the number of bytes written to the stream.
*
* @throws RuntimeException on failure.
*/
public function write($string)
Expand All @@ -376,6 +379,7 @@ public function write($string)
* Returns the remaining contents in a string
*
* @return string
*
* @throws RuntimeException if unable to read or an error occurs while
* reading.
*/
Expand Down
21 changes: 12 additions & 9 deletions Slim/Http/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
namespace Slim\Http;

use RuntimeException;
use InvalidArgumentException;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;

Expand Down Expand Up @@ -204,41 +206,41 @@ public function getStream()
*
* @param string $targetPath Path to which to move the uploaded file.
*
* @throws \InvalidArgumentException if the $path specified is invalid.
* @throws \RuntimeException on any error during the move operation, or on
* @throws InvalidArgumentException if the $path specified is invalid.
* @throws RuntimeException on any error during the move operation, or on
* the second or subsequent call to the method.
*/
public function moveTo($targetPath)
{
if ($this->moved) {
throw new \RuntimeException('Uploaded file already moved');
throw new RuntimeException('Uploaded file already moved');
}

if (!is_writable($targetPath)) {
throw new \InvalidArgumentException('Upload target path is not writable');
throw new InvalidArgumentException('Upload target path is not writable');
}

$targetIsStream = strpos($targetPath, '://') > 0;
if ($targetIsStream) {
$target = rtrim($targetPath, '/') . '/' . $this->name;
if (!copy($this->file, $target)) {
throw new \RuntimeException(sprintf('Error moving uploaded file %1s to %2s', $this->name, $target));
throw new RuntimeException(sprintf('Error moving uploaded file %1s to %2s', $this->name, $target));
}
if (!unlink($this->file)) {
throw new \RuntimeException(sprintf('Error removing uploaded file %1s', $this->name));
throw new RuntimeException(sprintf('Error removing uploaded file %1s', $this->name));
}
} elseif ($this->sapi) {
if (!is_uploaded_file($this->file)) {
throw new \RuntimeException(sprintf('%1s is not a valid uploaded file', $this->file));
throw new RuntimeException(sprintf('%1s is not a valid uploaded file', $this->file));
}

if (!move_uploaded_file($this->file, $targetPath)) {
throw new \RuntimeException(sprintf('Error moving uploaded file %1s to %2s', $this->name, $targetPath));
throw new RuntimeException(sprintf('Error moving uploaded file %1s to %2s', $this->name, $targetPath));
}
} else {
$target = rtrim($targetPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $this->name;
if (!rename($this->file, $target)) {
throw new \RuntimeException(sprintf('Error moving uploaded file %1s to %2s', $this->name, $target));
throw new RuntimeException(sprintf('Error moving uploaded file %1s to %2s', $this->name, $target));
}
}

Expand All @@ -257,6 +259,7 @@ public function moveTo($targetPath)
* the file in the $_FILES array.
*
* @see http://php.net/manual/en/features.file-upload.errors.php
*
* @return int One of PHP's UPLOAD_ERR_XXX constants.
*/
public function getError()
Expand Down
20 changes: 11 additions & 9 deletions Slim/Http/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,13 @@ public function __construct($scheme, $host, $port = null, $path = '/', $query =
*
* @param string $uri Complete Uri string
* (i.e., https://user:pass@host:443/path?query).
*
* @return self
*/
public static function createFromString($uri)
{
if (!is_string($uri) && !method_exists($uri, '__toString')) {
throw new \InvalidArgumentException('Uri must be a string');
throw new InvalidArgumentException('Uri must be a string');
}

$parts = parse_url($uri);
Expand All @@ -149,7 +150,8 @@ public static function createFromString($uri)
/**
* Create new Uri from environment.
*
* @param Environment $env
* @param Environment $env
*
* @return self
*/
public static function createFromEnvironment(Environment $env)
Expand Down Expand Up @@ -263,8 +265,9 @@ public function withScheme($scheme)
*
* @param string $scheme Raw Uri scheme.
* @return string
* @throws InvalidArgumentException if the Uri scheme is not a string.
* @throws \InvalidArgumentException If Uri scheme is not "", "https", or "http".
*
* @throws InvalidArgumentException If the Uri scheme is not a string.
* @throws InvalidArgumentException If Uri scheme is not "", "https", or "http".
*/
protected function filterScheme($scheme)
{
Expand All @@ -275,12 +278,12 @@ protected function filterScheme($scheme)
];

if (!is_string($scheme) && !method_exists($scheme, '__toString')) {
throw new \InvalidArgumentException('Uri scheme must be a string');
throw new InvalidArgumentException('Uri scheme must be a string');
}

$scheme = str_replace('://', '', strtolower((string)$scheme));
if (!isset($valid[$scheme])) {
throw new \InvalidArgumentException('Uri scheme must be one of: "", "https", "http"');
throw new InvalidArgumentException('Uri scheme must be one of: "", "https", "http"');
}

return $scheme;
Expand Down Expand Up @@ -457,7 +460,8 @@ protected function hasStandardPort()
*
* @param null|int $port The Uri port number.
* @return null|int
* @throws \InvalidArgumentException If the port is invalid.
*
* @throws InvalidArgumentException If the port is invalid.
*/
protected function filterPort($port)
{
Expand Down Expand Up @@ -784,8 +788,6 @@ public function getBaseUrl()
$scheme = $this->getScheme();
$authority = $this->getAuthority();
$basePath = $this->getBasePath();
$query = $this->getQuery();
$fragment = $this->getFragment();

if ($authority && substr($basePath, 0, 1) !== '/') {
$basePath = $basePath . '/' . $basePath;
Expand Down

0 comments on commit b54203c

Please sign in to comment.