add composer's vendor directory

This commit is contained in:
Marcel Kapfer (mmk2410) 2016-05-07 12:59:40 +02:00
parent 01a3860d73
commit 60b094d5fa
745 changed files with 56017 additions and 1 deletions

20
vendor/slim/slim/CONTRIBUTING.md vendored Normal file
View file

@ -0,0 +1,20 @@
# How to Contribute
## Pull Requests
1. Fork the Slim Framework repository
2. Create a new branch for each feature or improvement
3. Send a pull request from each feature branch to the **develop** branch
It is very important to separate new features or improvements into separate feature branches, and to send a
pull request for each branch. This allows me to review and pull in new features or improvements individually.
## Style Guide
All pull requests must adhere to the [PSR-2 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md).
## Unit Testing
All pull requests must be accompanied by passing unit tests and complete code coverage. The Slim Framework uses phpunit for testing.
[Learn about PHPUnit](https://github.com/sebastianbergmann/phpunit/)

19
vendor/slim/slim/LICENSE.md vendored Normal file
View file

@ -0,0 +1,19 @@
Copyright (c) 2011-2016 Josh Lockhart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

84
vendor/slim/slim/README.md vendored Normal file
View file

@ -0,0 +1,84 @@
# Slim Framework
[![Build Status](https://travis-ci.org/slimphp/Slim.svg?branch=develop)](https://travis-ci.org/slimphp/Slim)
[![Coverage Status](https://coveralls.io/repos/slimphp/Slim/badge.svg?branch=develop)](https://coveralls.io/r/slimphp/Slim?branch=develop)
[![Total Downloads](https://poser.pugx.org/slim/slim/downloads)](https://packagist.org/packages/slim/slim)
[![License](https://poser.pugx.org/slim/slim/license)](https://packagist.org/packages/slim/slim)
Slim is a PHP micro-framework that helps you quickly write simple yet powerful web applications and APIs.
## Installation
It's recommended that you use [Composer](https://getcomposer.org/) to install Slim.
```bash
$ composer require slim/slim "^3.0"
```
This will install Slim and all required dependencies. Slim requires PHP 5.5.0 or newer.
## Usage
Create an index.php file with the following contents:
```php
<?php
require 'vendor/autoload.php';
$app = new Slim\App();
$app->get('/hello/{name}', function ($request, $response, $args) {
$response->write("Hello, " . $args['name']);
return $response;
});
$app->run();
```
You may quickly test this using the built-in PHP server:
```bash
$ php -S localhost:8000
```
Going to http://localhost:8000/hello/world will now display "Hello, world".
For more information on how to configure your web server, see the [Documentation](http://www.slimframework.com/docs/start/web-servers.html).
## Tests
To execute the test suite, you'll need phpunit.
```bash
$ phpunit
```
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Learn More
Learn more at these links:
- [Website](http://www.slimframework.com)
- [Documentation](http://www.slimframework.com/docs/start/installation.html)
- [Support Forum](http://help.slimframework.com)
- [Twitter](https://twitter.com/slimphp)
- [Resources](https://github.com/xssc/awesome-slim)
## Security
If you discover security related issues, please email security@slimframework.com instead of using the issue tracker.
## Credits
- [Josh Lockhart](https://github.com/codeguy)
- [Andrew Smith](https://github.com/silentworks)
- [Rob Allen](https://github.com/akrabat)
- [Gabriel Manricks](https://github.com/gmanricks)
- [All Contributors](../../contributors)
## License
The Slim Framework is licensed under the MIT license. See [License File](LICENSE.md) for more information.

635
vendor/slim/slim/Slim/App.php vendored Normal file
View file

@ -0,0 +1,635 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim;
use Exception;
use Throwable;
use Closure;
use InvalidArgumentException;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Interop\Container\ContainerInterface;
use FastRoute\Dispatcher;
use Slim\Exception\SlimException;
use Slim\Exception\MethodNotAllowedException;
use Slim\Exception\NotFoundException;
use Slim\Http\Uri;
use Slim\Http\Headers;
use Slim\Http\Body;
use Slim\Http\Request;
use Slim\Interfaces\Http\EnvironmentInterface;
use Slim\Interfaces\RouteGroupInterface;
use Slim\Interfaces\RouteInterface;
use Slim\Interfaces\RouterInterface;
/**
* App
*
* This is the primary class with which you instantiate,
* configure, and run a Slim Framework application.
* The \Slim\App class also accepts Slim Framework middleware.
*
* @property-read array $settings App settings
* @property-read EnvironmentInterface $environment
* @property-read RequestInterface $request
* @property-read ResponseInterface $response
* @property-read RouterInterface $router
* @property-read callable $errorHandler
* @property-read callable $phpErrorHandler
* @property-read callable $notFoundHandler function($request, $response)
* @property-read callable $notAllowedHandler function($request, $response, $allowedHttpMethods)
*/
class App
{
use MiddlewareAwareTrait;
/**
* Current version
*
* @var string
*/
const VERSION = '3.0.0';
/**
* Container
*
* @var ContainerInterface
*/
private $container;
/********************************************************************************
* Constructor
*******************************************************************************/
/**
* Create new application
*
* @param ContainerInterface|array $container Either a ContainerInterface or an associative array of app settings
* @throws InvalidArgumentException when no container is provided that implements ContainerInterface
*/
public function __construct($container = [])
{
if (is_array($container)) {
$container = new Container($container);
}
if (!$container instanceof ContainerInterface) {
throw new InvalidArgumentException('Expected a ContainerInterface');
}
$this->container = $container;
}
/**
* Enable access to the DI container by consumers of $app
*
* @return ContainerInterface
*/
public function getContainer()
{
return $this->container;
}
/**
* Add middleware
*
* This method prepends new middleware to the app's middleware stack.
*
* @param callable|string $callable The callback routine
*
* @return static
*/
public function add($callable)
{
return $this->addMiddleware(new DeferredCallable($callable, $this->container));
}
/**
* Calling a non-existant method on App checks to see if there's an item
* in the container than is callable and if so, calls it.
*
* @param string $method
* @param array $args
* @return mixed
*/
public function __call($method, $args)
{
if ($this->container->has($method)) {
$obj = $this->container->get($method);
if (is_callable($obj)) {
return call_user_func_array($obj, $args);
}
}
throw new \BadMethodCallException("Method $method is not a valid method");
}
/********************************************************************************
* Router proxy methods
*******************************************************************************/
/**
* Add GET route
*
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return \Slim\Interfaces\RouteInterface
*/
public function get($pattern, $callable)
{
return $this->map(['GET'], $pattern, $callable);
}
/**
* Add POST route
*
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return \Slim\Interfaces\RouteInterface
*/
public function post($pattern, $callable)
{
return $this->map(['POST'], $pattern, $callable);
}
/**
* Add PUT route
*
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return \Slim\Interfaces\RouteInterface
*/
public function put($pattern, $callable)
{
return $this->map(['PUT'], $pattern, $callable);
}
/**
* Add PATCH route
*
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return \Slim\Interfaces\RouteInterface
*/
public function patch($pattern, $callable)
{
return $this->map(['PATCH'], $pattern, $callable);
}
/**
* Add DELETE route
*
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return \Slim\Interfaces\RouteInterface
*/
public function delete($pattern, $callable)
{
return $this->map(['DELETE'], $pattern, $callable);
}
/**
* Add OPTIONS route
*
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return \Slim\Interfaces\RouteInterface
*/
public function options($pattern, $callable)
{
return $this->map(['OPTIONS'], $pattern, $callable);
}
/**
* Add route for any HTTP method
*
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return \Slim\Interfaces\RouteInterface
*/
public function any($pattern, $callable)
{
return $this->map(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], $pattern, $callable);
}
/**
* Add route with multiple methods
*
* @param string[] $methods Numeric array of HTTP method names
* @param string $pattern The route URI pattern
* @param callable|string $callable The route callback routine
*
* @return RouteInterface
*/
public function map(array $methods, $pattern, $callable)
{
if ($callable instanceof Closure) {
$callable = $callable->bindTo($this->container);
}
$route = $this->container->get('router')->map($methods, $pattern, $callable);
if (is_callable([$route, 'setContainer'])) {
$route->setContainer($this->container);
}
if (is_callable([$route, 'setOutputBuffering'])) {
$route->setOutputBuffering($this->container->get('settings')['outputBuffering']);
}
return $route;
}
/**
* Route Groups
*
* This method accepts a route pattern and a callback. All route
* declarations in the callback will be prepended by the group(s)
* that it is in.
*
* @param string $pattern
* @param callable $callable
*
* @return RouteGroupInterface
*/
public function group($pattern, $callable)
{
/** @var RouteGroup $group */
$group = $this->container->get('router')->pushGroup($pattern, $callable);
$group->setContainer($this->container);
$group($this);
$this->container->get('router')->popGroup();
return $group;
}
/********************************************************************************
* Runner
*******************************************************************************/
/**
* Run application
*
* This method traverses the application middleware stack and then sends the
* resultant Response object to the HTTP client.
*
* @param bool|false $silent
* @return ResponseInterface
*
* @throws Exception
* @throws MethodNotAllowedException
* @throws NotFoundException
*/
public function run($silent = false)
{
$request = $this->container->get('request');
$response = $this->container->get('response');
$response = $this->process($request, $response);
if (!$silent) {
$this->respond($response);
}
return $response;
}
/**
* Process a request
*
* This method traverses the application middleware stack and then returns the
* resultant Response object.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*
* @throws Exception
* @throws MethodNotAllowedException
* @throws NotFoundException
*/
public function process(ServerRequestInterface $request, ResponseInterface $response)
{
// Ensure basePath is set
$router = $this->container->get('router');
if (is_callable([$request->getUri(), 'getBasePath']) && is_callable([$router, 'setBasePath'])) {
$router->setBasePath($request->getUri()->getBasePath());
}
// Dispatch the Router first if the setting for this is on
if ($this->container->get('settings')['determineRouteBeforeAppMiddleware'] === true) {
// Dispatch router (note: you won't be able to alter routes after this)
$request = $this->dispatchRouterAndPrepareRoute($request, $router);
}
// Traverse middleware stack
try {
$response = $this->callMiddlewareStack($request, $response);
} catch (Exception $e) {
$response = $this->handleException($e, $request, $response);
} catch (Throwable $e) {
$response = $this->handlePhpError($e, $request, $response);
}
$response = $this->finalize($response);
return $response;
}
/**
* Send the response the client
*
* @param ResponseInterface $response
*/
public function respond(ResponseInterface $response)
{
// Send response
if (!headers_sent()) {
// Status
header(sprintf(
'HTTP/%s %s %s',
$response->getProtocolVersion(),
$response->getStatusCode(),
$response->getReasonPhrase()
));
// Headers
foreach ($response->getHeaders() as $name => $values) {
foreach ($values as $value) {
header(sprintf('%s: %s', $name, $value), false);
}
}
}
// Body
if (!$this->isEmptyResponse($response)) {
$body = $response->getBody();
if ($body->isSeekable()) {
$body->rewind();
}
$settings = $this->container->get('settings');
$chunkSize = $settings['responseChunkSize'];
$contentLength = $response->getHeaderLine('Content-Length');
if (!$contentLength) {
$contentLength = $body->getSize();
}
if (isset($contentLength)) {
$totalChunks = ceil($contentLength / $chunkSize);
$lastChunkSize = $contentLength % $chunkSize;
$currentChunk = 0;
while (!$body->eof() && $currentChunk < $totalChunks) {
if (++$currentChunk == $totalChunks && $lastChunkSize > 0) {
$chunkSize = $lastChunkSize;
}
echo $body->read($chunkSize);
if (connection_status() != CONNECTION_NORMAL) {
break;
}
}
} else {
while (!$body->eof()) {
echo $body->read($chunkSize);
if (connection_status() != CONNECTION_NORMAL) {
break;
}
}
}
}
}
/**
* Invoke application
*
* This method implements the middleware interface. It receives
* Request and Response objects, and it returns a Response object
* after compiling the routes registered in the Router and dispatching
* the Request object to the appropriate Route callback routine.
*
* @param ServerRequestInterface $request The most recent Request object
* @param ResponseInterface $response The most recent Response object
*
* @return ResponseInterface
* @throws MethodNotAllowedException
* @throws NotFoundException
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
{
// Get the route info
$routeInfo = $request->getAttribute('routeInfo');
/** @var \Slim\Interfaces\RouterInterface $router */
$router = $this->container->get('router');
// If router hasn't been dispatched or the URI changed then dispatch
if (null === $routeInfo || ($routeInfo['request'] !== [$request->getMethod(), (string) $request->getUri()])) {
$request = $this->dispatchRouterAndPrepareRoute($request, $router);
$routeInfo = $request->getAttribute('routeInfo');
}
if ($routeInfo[0] === Dispatcher::FOUND) {
$route = $router->lookupRoute($routeInfo[1]);
return $route->run($request, $response);
} elseif ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
if (!$this->container->has('notAllowedHandler')) {
throw new MethodNotAllowedException($request, $response, $routeInfo[1]);
}
/** @var callable $notAllowedHandler */
$notAllowedHandler = $this->container->get('notAllowedHandler');
return $notAllowedHandler($request, $response, $routeInfo[1]);
}
if (!$this->container->has('notFoundHandler')) {
throw new NotFoundException($request, $response);
}
/** @var callable $notFoundHandler */
$notFoundHandler = $this->container->get('notFoundHandler');
return $notFoundHandler($request, $response);
}
/**
* Perform a sub-request from within an application route
*
* This method allows you to prepare and initiate a sub-request, run within
* the context of the current request. This WILL NOT issue a remote HTTP
* request. Instead, it will route the provided URL, method, headers,
* cookies, body, and server variables against the set of registered
* application routes. The result response object is returned.
*
* @param string $method The request method (e.g., GET, POST, PUT, etc.)
* @param string $path The request URI path
* @param string $query The request URI query string
* @param array $headers The request headers (key-value array)
* @param array $cookies The request cookies (key-value array)
* @param string $bodyContent The request body
* @param ResponseInterface $response The response object (optional)
* @return ResponseInterface
*/
public function subRequest(
$method,
$path,
$query = '',
array $headers = [],
array $cookies = [],
$bodyContent = '',
ResponseInterface $response = null
) {
$env = $this->container->get('environment');
$uri = Uri::createFromEnvironment($env)->withPath($path)->withQuery($query);
$headers = new Headers($headers);
$serverParams = $env->all();
$body = new Body(fopen('php://temp', 'r+'));
$body->write($bodyContent);
$body->rewind();
$request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
if (!$response) {
$response = $this->container->get('response');
}
return $this($request, $response);
}
/**
* Dispatch the router to find the route. Prepare the route for use.
*
* @param ServerRequestInterface $request
* @param RouterInterface $router
* @return ServerRequestInterface
*/
protected function dispatchRouterAndPrepareRoute(ServerRequestInterface $request, RouterInterface $router)
{
$routeInfo = $router->dispatch($request);
if ($routeInfo[0] === Dispatcher::FOUND) {
$routeArguments = [];
foreach ($routeInfo[2] as $k => $v) {
$routeArguments[$k] = urldecode($v);
}
$route = $router->lookupRoute($routeInfo[1]);
$route->prepare($request, $routeArguments);
// add route to the request's attributes in case a middleware or handler needs access to the route
$request = $request->withAttribute('route', $route);
}
$routeInfo['request'] = [$request->getMethod(), (string) $request->getUri()];
return $request->withAttribute('routeInfo', $routeInfo);
}
/**
* Finalize response
*
* @param ResponseInterface $response
* @return ResponseInterface
*/
protected function finalize(ResponseInterface $response)
{
// stop PHP sending a Content-Type automatically
ini_set('default_mimetype', '');
if ($this->isEmptyResponse($response)) {
return $response->withoutHeader('Content-Type')->withoutHeader('Content-Length');
}
$size = $response->getBody()->getSize();
if ($size !== null && !$response->hasHeader('Content-Length')) {
$response = $response->withHeader('Content-Length', (string) $size);
}
return $response;
}
/**
* Helper method, which returns true if the provided response must not output a body and false
* if the response could have a body.
*
* @see https://tools.ietf.org/html/rfc7231
*
* @param ResponseInterface $response
* @return bool
*/
protected function isEmptyResponse(ResponseInterface $response)
{
if (method_exists($response, 'isEmpty')) {
return $response->isEmpty();
}
return in_array($response->getStatusCode(), [204, 205, 304]);
}
/**
* Call relevant handler from the Container if needed. If it doesn't exist,
* then just re-throw.
*
* @param Exception $e
* @param ServerRequestInterface $request
* @param ResponseInterface $response
*
* @return ResponseInterface
* @throws Exception if a handler is needed and not found
*/
protected function handleException(Exception $e, ServerRequestInterface $request, ResponseInterface $response)
{
if ($e instanceof MethodNotAllowedException) {
$handler = 'notAllowedHandler';
$params = [$e->getRequest(), $e->getResponse(), $e->getAllowedMethods()];
} elseif ($e instanceof NotFoundException) {
$handler = 'notFoundHandler';
$params = [$e->getRequest(), $e->getResponse()];
} elseif ($e instanceof SlimException) {
// This is a Stop exception and contains the response
return $e->getResponse();
} else {
// Other exception, use $request and $response params
$handler = 'errorHandler';
$params = [$request, $response, $e];
}
if ($this->container->has($handler)) {
$callable = $this->container->get($handler);
// Call the registered handler
return call_user_func_array($callable, $params);
}
// No handlers found, so just throw the exception
throw $e;
}
/**
* Call relevant handler from the Container if needed. If it doesn't exist,
* then just re-throw.
*
* @param Throwable $e
* @param ServerRequestInterface $request
* @param ResponseInterface $response
*
* @return ResponseInterface
* @throws Exception if a handler is needed and not found
*/
protected function handlePhpError(Throwable $e, ServerRequestInterface $request, ResponseInterface $response)
{
$handler = 'phpErrorHandler';
$params = [$request, $response, $e];
if ($this->container->has($handler)) {
$callable = $this->container->get($handler);
// Call the registered handler
return call_user_func_array($callable, $params);
}
// No handlers found, so just throw the exception
throw $e;
}
}

View file

@ -0,0 +1,87 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim;
use RuntimeException;
use Interop\Container\ContainerInterface;
use Slim\Interfaces\CallableResolverInterface;
/**
* This class resolves a string of the format 'class:method' into a closure
* that can be dispatched.
*/
final class CallableResolver implements CallableResolverInterface
{
/**
* @var ContainerInterface
*/
private $container;
/**
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* Resolve toResolve into a closure that that the router can dispatch.
*
* If toResolve is of the format 'class:method', then try to extract 'class'
* from the container otherwise instantiate it and then dispatch 'method'.
*
* @param mixed $toResolve
*
* @return callable
*
* @throws RuntimeException if the callable does not exist
* @throws RuntimeException if the callable is not resolvable
*/
public function resolve($toResolve)
{
$resolved = $toResolve;
if (!is_callable($toResolve) && is_string($toResolve)) {
// check for slim callable as "class:method"
$callablePattern = '!^([^\:]+)\:([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)$!';
if (preg_match($callablePattern, $toResolve, $matches)) {
$class = $matches[1];
$method = $matches[2];
if ($this->container->has($class)) {
$resolved = [$this->container->get($class), $method];
} else {
if (!class_exists($class)) {
throw new RuntimeException(sprintf('Callable %s does not exist', $class));
}
$resolved = [new $class($this->container), $method];
}
} else {
// check if string is something in the DIC that's callable or is a class name which
// has an __invoke() method
$class = $toResolve;
if ($this->container->has($class)) {
$resolved = $this->container->get($class);
} else {
if (!class_exists($class)) {
throw new RuntimeException(sprintf('Callable %s does not exist', $class));
}
$resolved = new $class($this->container);
}
}
}
if (!is_callable($resolved)) {
throw new RuntimeException(sprintf('%s is not resolvable', $toResolve));
}
return $resolved;
}
}

View file

@ -0,0 +1,47 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim;
use RuntimeException;
use Interop\Container\ContainerInterface;
use Slim\Interfaces\CallableResolverInterface;
/**
* ResolveCallable
*
* This is an internal class that enables resolution of 'class:method' strings
* into a closure. This class is an implementation detail and is used only inside
* of the Slim application.
*
* @property ContainerInterface $container
*/
trait CallableResolverAwareTrait
{
/**
* Resolve a string of the format 'class:method' into a closure that the
* router can dispatch.
*
* @param callable|string $callable
*
* @return \Closure
*
* @throws RuntimeException If the string cannot be resolved as a callable
*/
protected function resolveCallable($callable)
{
if (!$this->container instanceof ContainerInterface) {
return $callable;
}
/** @var CallableResolverInterface $resolver */
$resolver = $this->container->get('callableResolver');
return $resolver->resolve($callable);
}
}

204
vendor/slim/slim/Slim/Collection.php vendored Normal file
View file

@ -0,0 +1,204 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim;
use ArrayIterator;
use Slim\Interfaces\CollectionInterface;
/**
* Collection
*
* This class provides a common interface used by many other
* classes in a Slim application that manage "collections"
* of data that must be inspected and/or manipulated
*/
class Collection implements CollectionInterface
{
/**
* The source data
*
* @var array
*/
protected $data = [];
/**
* Create new collection
*
* @param array $items Pre-populate collection with this key-value array
*/
public function __construct(array $items = [])
{
foreach ($items as $key => $value) {
$this->set($key, $value);
}
}
/********************************************************************************
* Collection interface
*******************************************************************************/
/**
* Set collection item
*
* @param string $key The data key
* @param mixed $value The data value
*/
public function set($key, $value)
{
$this->data[$key] = $value;
}
/**
* Get collection item for key
*
* @param string $key The data key
* @param mixed $default The default value to return if data key does not exist
*
* @return mixed The key's value, or the default value
*/
public function get($key, $default = null)
{
return $this->has($key) ? $this->data[$key] : $default;
}
/**
* Add item to collection
*
* @param array $items Key-value array of data to append to this collection
*/
public function replace(array $items)
{
foreach ($items as $key => $value) {
$this->set($key, $value);
}
}
/**
* Get all items in collection
*
* @return array The collection's source data
*/
public function all()
{
return $this->data;
}
/**
* Get collection keys
*
* @return array The collection's source data keys
*/
public function keys()
{
return array_keys($this->data);
}
/**
* Does this collection have a given key?
*
* @param string $key The data key
*
* @return bool
*/
public function has($key)
{
return array_key_exists($key, $this->data);
}
/**
* Remove item from collection
*
* @param string $key The data key
*/
public function remove($key)
{
unset($this->data[$key]);
}
/**
* Remove all items from collection
*/
public function clear()
{
$this->data = [];
}
/********************************************************************************
* ArrayAccess interface
*******************************************************************************/
/**
* Does this collection have a given key?
*
* @param string $key The data key
*
* @return bool
*/
public function offsetExists($key)
{
return $this->has($key);
}
/**
* Get collection item for key
*
* @param string $key The data key
*
* @return mixed The key's value, or the default value
*/
public function offsetGet($key)
{
return $this->get($key);
}
/**
* Set collection item
*
* @param string $key The data key
* @param mixed $value The data value
*/
public function offsetSet($key, $value)
{
$this->set($key, $value);
}
/**
* Remove item from collection
*
* @param string $key The data key
*/
public function offsetUnset($key)
{
$this->remove($key);
}
/**
* Get number of items in collection
*
* @return int
*/
public function count()
{
return count($this->data);
}
/********************************************************************************
* IteratorAggregate interface
*******************************************************************************/
/**
* Get collection iterator
*
* @return \ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->data);
}
}

151
vendor/slim/slim/Slim/Container.php vendored Normal file
View file

@ -0,0 +1,151 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim;
use Interop\Container\ContainerInterface;
use Interop\Container\Exception\ContainerException;
use Pimple\Container as PimpleContainer;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Exception\ContainerValueNotFoundException;
/**
* Slim's default DI container is Pimple.
*
* Slim\App expects a container that implements Interop\Container\ContainerInterface
* with these service keys configured and ready for use:
*
* - settings: an array or instance of \ArrayAccess
* - environment: an instance of \Slim\Interfaces\Http\EnvironmentInterface
* - request: an instance of \Psr\Http\Message\ServerRequestInterface
* - response: an instance of \Psr\Http\Message\ResponseInterface
* - router: an instance of \Slim\Interfaces\RouterInterface
* - foundHandler: an instance of \Slim\Interfaces\InvocationStrategyInterface
* - errorHandler: a callable with the signature: function($request, $response, $exception)
* - notFoundHandler: a callable with the signature: function($request, $response)
* - notAllowedHandler: a callable with the signature: function($request, $response, $allowedHttpMethods)
* - callableResolver: an instance of callableResolver
*
* @property-read array settings
* @property-read \Slim\Interfaces\Http\EnvironmentInterface environment
* @property-read \Psr\Http\Message\ServerRequestInterface request
* @property-read \Psr\Http\Message\ResponseInterface response
* @property-read \Slim\Interfaces\RouterInterface router
* @property-read \Slim\Interfaces\InvocationStrategyInterface foundHandler
* @property-read callable errorHandler
* @property-read callable notFoundHandler
* @property-read callable notAllowedHandler
* @property-read \Slim\Interfaces\CallableResolverInterface callableResolver
*/
class Container extends PimpleContainer implements ContainerInterface
{
/**
* Default settings
*
* @var array
*/
private $defaultSettings = [
'httpVersion' => '1.1',
'responseChunkSize' => 4096,
'outputBuffering' => 'append',
'determineRouteBeforeAppMiddleware' => false,
'displayErrorDetails' => false,
];
/**
* Create new container
*
* @param array $values The parameters or objects.
*/
public function __construct(array $values = [])
{
parent::__construct($values);
$userSettings = isset($values['settings']) ? $values['settings'] : [];
$this->registerDefaultServices($userSettings);
}
/**
* This function registers the default services that Slim needs to work.
*
* All services are shared - that is, they are registered such that the
* same instance is returned on subsequent calls.
*
* @param array $userSettings Associative array of application settings
*
* @return void
*/
private function registerDefaultServices($userSettings)
{
$defaultSettings = $this->defaultSettings;
/**
* This service MUST return an array or an
* instance of \ArrayAccess.
*
* @return array|\ArrayAccess
*/
$this['settings'] = function () use ($userSettings, $defaultSettings) {
return new Collection(array_merge($defaultSettings, $userSettings));
};
$defaultProvider = new DefaultServicesProvider();
$defaultProvider->register($this);
}
/********************************************************************************
* Methods to satisfy Interop\Container\ContainerInterface
*******************************************************************************/
/**
* Finds an entry of the container by its identifier and returns it.
*
* @param string $id Identifier of the entry to look for.
*
* @throws ContainerValueNotFoundException No entry was found for this identifier.
* @throws ContainerException Error while retrieving the entry.
*
* @return mixed Entry.
*/
public function get($id)
{
if (!$this->offsetExists($id)) {
throw new ContainerValueNotFoundException(sprintf('Identifier "%s" is not defined.', $id));
}
return $this->offsetGet($id);
}
/**
* Returns true if the container can return an entry for the given identifier.
* Returns false otherwise.
*
* @param string $id Identifier of the entry to look for.
*
* @return boolean
*/
public function has($id)
{
return $this->offsetExists($id);
}
/********************************************************************************
* Magic methods for convenience
*******************************************************************************/
public function __get($name)
{
return $this->get($name);
}
public function __isset($name)
{
return $this->has($name);
}
}

View file

@ -0,0 +1,197 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Exception\ContainerValueNotFoundException;
use Slim\Handlers\PhpError;
use Slim\Handlers\Error;
use Slim\Handlers\NotFound;
use Slim\Handlers\NotAllowed;
use Slim\Handlers\Strategies\RequestResponse;
use Slim\Http\Environment;
use Slim\Http\Headers;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Interfaces\CallableResolverInterface;
use Slim\Interfaces\Http\EnvironmentInterface;
use Slim\Interfaces\InvocationStrategyInterface;
use Slim\Interfaces\RouterInterface;
/**
* Slim's default Service Provider.
*/
class DefaultServicesProvider
{
/**
* Register Slim's default services.
*
* @param Container $container A DI container implementing ArrayAccess and container-interop.
*/
public function register($container)
{
if (!isset($container['environment'])) {
/**
* This service MUST return a shared instance
* of \Slim\Interfaces\Http\EnvironmentInterface.
*
* @return EnvironmentInterface
*/
$container['environment'] = function () {
return new Environment($_SERVER);
};
}
if (!isset($container['request'])) {
/**
* PSR-7 Request object
*
* @param Container $container
*
* @return ServerRequestInterface
*/
$container['request'] = function ($container) {
return Request::createFromEnvironment($container->get('environment'));
};
}
if (!isset($container['response'])) {
/**
* PSR-7 Response object
*
* @param Container $container
*
* @return ResponseInterface
*/
$container['response'] = function ($container) {
$headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']);
$response = new Response(200, $headers);
return $response->withProtocolVersion($container->get('settings')['httpVersion']);
};
}
if (!isset($container['router'])) {
/**
* This service MUST return a SHARED instance
* of \Slim\Interfaces\RouterInterface.
*
* @return RouterInterface
*/
$container['router'] = function () {
return new Router;
};
}
if (!isset($container['foundHandler'])) {
/**
* This service MUST return a SHARED instance
* of \Slim\Interfaces\InvocationStrategyInterface.
*
* @return InvocationStrategyInterface
*/
$container['foundHandler'] = function () {
return new RequestResponse;
};
}
if (!isset($container['phpErrorHandler'])) {
/**
* This service MUST return a callable
* that accepts three arguments:
*
* 1. Instance of \Psr\Http\Message\ServerRequestInterface
* 2. Instance of \Psr\Http\Message\ResponseInterface
* 3. Instance of \Error
*
* The callable MUST return an instance of
* \Psr\Http\Message\ResponseInterface.
*
* @param Container $container
*
* @return callable
*/
$container['phpErrorHandler'] = function ($container) {
return new PhpError($container->get('settings')['displayErrorDetails']);
};
}
if (!isset($container['errorHandler'])) {
/**
* This service MUST return a callable
* that accepts three arguments:
*
* 1. Instance of \Psr\Http\Message\ServerRequestInterface
* 2. Instance of \Psr\Http\Message\ResponseInterface
* 3. Instance of \Exception
*
* The callable MUST return an instance of
* \Psr\Http\Message\ResponseInterface.
*
* @param Container $container
*
* @return callable
*/
$container['errorHandler'] = function ($container) {
return new Error($container->get('settings')['displayErrorDetails']);
};
}
if (!isset($container['notFoundHandler'])) {
/**
* This service MUST return a callable
* that accepts two arguments:
*
* 1. Instance of \Psr\Http\Message\ServerRequestInterface
* 2. Instance of \Psr\Http\Message\ResponseInterface
*
* The callable MUST return an instance of
* \Psr\Http\Message\ResponseInterface.
*
* @return callable
*/
$container['notFoundHandler'] = function () {
return new NotFound;
};
}
if (!isset($container['notAllowedHandler'])) {
/**
* This service MUST return a callable
* that accepts three arguments:
*
* 1. Instance of \Psr\Http\Message\ServerRequestInterface
* 2. Instance of \Psr\Http\Message\ResponseInterface
* 3. Array of allowed HTTP methods
*
* The callable MUST return an instance of
* \Psr\Http\Message\ResponseInterface.
*
* @return callable
*/
$container['notAllowedHandler'] = function () {
return new NotAllowed;
};
}
if (!isset($container['callableResolver'])) {
/**
* Instance of \Slim\Interfaces\CallableResolverInterface
*
* @param Container $container
*
* @return CallableResolverInterface
*/
$container['callableResolver'] = function ($container) {
return new CallableResolver($container);
};
}
}
}

View file

@ -0,0 +1,39 @@
<?php
namespace Slim;
use Closure;
use Interop\Container\ContainerInterface;
class DeferredCallable
{
use CallableResolverAwareTrait;
private $callable;
/** @var ContainerInterface */
private $container;
/**
* DeferredMiddleware constructor.
* @param callable|string $callable
* @param ContainerInterface $container
*/
public function __construct($callable, ContainerInterface $container = null)
{
$this->callable = $callable;
$this->container = $container;
}
public function __invoke()
{
$callable = $this->resolveCallable($this->callable);
if ($callable instanceof Closure) {
$callable = $callable->bindTo($this->container);
}
$args = func_get_args();
return call_user_func_array($callable, $args);
}
}

View file

@ -0,0 +1,20 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/codeguy/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/codeguy/Slim/blob/master/LICENSE (MIT License)
*/
namespace Slim\Exception;
use RuntimeException;
use Interop\Container\Exception\NotFoundException as InteropNotFoundException;
/**
* Not Found Exception
*/
class ContainerValueNotFoundException extends RuntimeException implements InteropNotFoundException
{
}

View file

@ -0,0 +1,45 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/codeguy/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/codeguy/Slim/blob/master/LICENSE (MIT License)
*/
namespace Slim\Exception;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
class MethodNotAllowedException extends SlimException
{
/**
* HTTP methods allowed
*
* @var string[]
*/
protected $allowedMethods;
/**
* Create new exception
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param string[] $allowedMethods
*/
public function __construct(ServerRequestInterface $request, ResponseInterface $response, array $allowedMethods)
{
parent::__construct($request, $response);
$this->allowedMethods = $allowedMethods;
}
/**
* Get allowed methods
*
* @return string[]
*/
public function getAllowedMethods()
{
return $this->allowedMethods;
}
}

View file

@ -0,0 +1,14 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/codeguy/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/codeguy/Slim/blob/master/LICENSE (MIT License)
*/
namespace Slim\Exception;
class NotFoundException extends SlimException
{
}

View file

@ -0,0 +1,69 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Exception;
use Exception;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
/**
* Stop Exception
*
* This Exception is thrown when the Slim application needs to abort
* processing and return control flow to the outer PHP script.
*/
class SlimException extends Exception
{
/**
* A request object
*
* @var ServerRequestInterface
*/
protected $request;
/**
* A response object to send to the HTTP client
*
* @var ResponseInterface
*/
protected $response;
/**
* Create new exception
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
*/
public function __construct(ServerRequestInterface $request, ResponseInterface $response)
{
parent::__construct();
$this->request = $request;
$this->response = $response;
}
/**
* Get request
*
* @return ServerRequestInterface
*/
public function getRequest()
{
return $this->request;
}
/**
* Get response
*
* @return ResponseInterface
*/
public function getResponse()
{
return $this->response;
}
}

300
vendor/slim/slim/Slim/Handlers/Error.php vendored Normal file
View file

@ -0,0 +1,300 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Handlers;
use Exception;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Http\Body;
/**
* Default Slim application error handler
*
* It outputs the error message and diagnostic information in either JSON, XML,
* or HTML based on the Accept header.
*/
class Error
{
protected $displayErrorDetails;
/**
* Known handled content types
*
* @var array
*/
protected $knownContentTypes = [
'application/json',
'application/xml',
'text/xml',
'text/html',
];
/**
* Constructor
*
* @param boolean $displayErrorDetails Set to true to display full details
*/
public function __construct($displayErrorDetails = false)
{
$this->displayErrorDetails = (bool)$displayErrorDetails;
}
/**
* 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
*
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Exception $exception)
{
$contentType = $this->determineContentType($request);
switch ($contentType) {
case 'application/json':
$output = $this->renderJsonErrorMessage($exception);
break;
case 'text/xml':
case 'application/xml':
$output = $this->renderXmlErrorMessage($exception);
break;
case 'text/html':
$output = $this->renderHtmlErrorMessage($exception);
break;
}
$this->writeToErrorLog($exception);
$body = new Body(fopen('php://temp', 'r+'));
$body->write($output);
return $response
->withStatus(500)
->withHeader('Content-type', $contentType)
->withBody($body);
}
/**
* Write to the error log if displayErrorDetails is false
*
* @param Exception $exception
* @return void
*/
protected function writeToErrorLog($exception)
{
if ($this->displayErrorDetails) {
return;
}
$message = 'Slim Application Error:' . PHP_EOL;
$message .= $this->renderTextException($exception);
while ($exception = $exception->getPrevious()) {
$message .= PHP_EOL . 'Previous exception:' . PHP_EOL;
$message .= $this->renderTextException($exception);
}
$message .= PHP_EOL . 'View in rendered output by enabling the "displayErrorDetails" setting.' . PHP_EOL;
error_log($message);
}
/**
* Render exception as Text.
*
* @param Exception $exception
*
* @return string
*/
protected function renderTextException(Exception $exception)
{
$text = sprintf('Type: %s' . PHP_EOL, get_class($exception));
if (($code = $exception->getCode())) {
$text .= sprintf('Code: %s' . PHP_EOL, $code);
}
if (($message = $exception->getMessage())) {
$text .= sprintf('Message: %s' . PHP_EOL, htmlentities($message));
}
if (($file = $exception->getFile())) {
$text .= sprintf('File: %s' . PHP_EOL, $file);
}
if (($line = $exception->getLine())) {
$text .= sprintf('Line: %s' . PHP_EOL, $line);
}
if (($trace = $exception->getTraceAsString())) {
$text .= sprintf('Trace: %s', $trace);
}
return $text;
}
/**
* Render HTML error page
*
* @param Exception $exception
* @return string
*/
protected function renderHtmlErrorMessage(Exception $exception)
{
$title = 'Slim Application Error';
if ($this->displayErrorDetails) {
$html = '<p>The application could not run because of the following error:</p>';
$html .= '<h2>Details</h2>';
$html .= $this->renderHtmlException($exception);
while ($exception = $exception->getPrevious()) {
$html .= '<h2>Previous exception</h2>';
$html .= $this->renderHtmlException($exception);
}
} else {
$html = '<p>A website error has occurred. Sorry for the temporary inconvenience.</p>';
}
$output = sprintf(
"<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" .
"<title>%s</title><style>body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana," .
"sans-serif;}h1{margin:0;font-size:48px;font-weight:normal;line-height:48px;}strong{" .
"display:inline-block;width:65px;}</style></head><body><h1>%s</h1>%s</body></html>",
$title,
$title,
$html
);
return $output;
}
/**
* Render exception as HTML.
*
* @param Exception $exception
*
* @return string
*/
protected function renderHtmlException(Exception $exception)
{
$html = sprintf('<div><strong>Type:</strong> %s</div>', get_class($exception));
if (($code = $exception->getCode())) {
$html .= sprintf('<div><strong>Code:</strong> %s</div>', $code);
}
if (($message = $exception->getMessage())) {
$html .= sprintf('<div><strong>Message:</strong> %s</div>', htmlentities($message));
}
if (($file = $exception->getFile())) {
$html .= sprintf('<div><strong>File:</strong> %s</div>', $file);
}
if (($line = $exception->getLine())) {
$html .= sprintf('<div><strong>Line:</strong> %s</div>', $line);
}
if (($trace = $exception->getTraceAsString())) {
$html .= '<h2>Trace</h2>';
$html .= sprintf('<pre>%s</pre>', htmlentities($trace));
}
return $html;
}
/**
* Render JSON error
*
* @param Exception $exception
* @return string
*/
protected function renderJsonErrorMessage(Exception $exception)
{
$error = [
'message' => 'Slim Application Error',
];
if ($this->displayErrorDetails) {
$error['exception'] = [];
do {
$error['exception'][] = [
'type' => get_class($exception),
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => explode("\n", $exception->getTraceAsString()),
];
} while ($exception = $exception->getPrevious());
}
return json_encode($error, JSON_PRETTY_PRINT);
}
/**
* Render XML error
*
* @param Exception $exception
* @return string
*/
protected function renderXmlErrorMessage(Exception $exception)
{
$xml = "<error>\n <message>Slim Application Error</message>\n";
if ($this->displayErrorDetails) {
do {
$xml .= " <exception>\n";
$xml .= " <type>" . get_class($exception) . "</type>\n";
$xml .= " <code>" . $exception->getCode() . "</code>\n";
$xml .= " <message>" . $this->createCdataSection($exception->getMessage()) . "</message>\n";
$xml .= " <file>" . $exception->getFile() . "</file>\n";
$xml .= " <line>" . $exception->getLine() . "</line>\n";
$xml .= " <trace>" . $this->createCdataSection($exception->getTraceAsString()) . "</trace>\n";
$xml .= " </exception>\n";
} while ($exception = $exception->getPrevious());
}
$xml .= "</error>";
return $xml;
}
/**
* Returns a CDATA section with the given content.
*
* @param string $content
* @return string
*/
private function createCdataSection($content)
{
return sprintf('<![CDATA[%s]]>', str_replace(']]>', ']]]]><![CDATA[>', $content));
}
/**
* Determine which content type we know about is wanted using Accept header
*
* @param ServerRequestInterface $request
* @return string
*/
private function determineContentType(ServerRequestInterface $request)
{
$acceptHeader = $request->getHeaderLine('Accept');
$selectedContentTypes = array_intersect(explode(',', $acceptHeader), $this->knownContentTypes);
if (count($selectedContentTypes)) {
return $selectedContentTypes[0];
}
return 'text/html';
}
}

View file

@ -0,0 +1,173 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Handlers;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Slim\Http\Body;
/**
* Default Slim application not allowed handler
*
* It outputs a simple message in either JSON, XML or HTML based on the
* Accept header.
*/
class NotAllowed
{
/**
* Known handled content types
*
* @var array
*/
protected $knownContentTypes = [
'application/json',
'application/xml',
'text/xml',
'text/html',
];
/**
* 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
*
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, array $methods)
{
if ($request->getMethod() === 'OPTIONS') {
$status = 200;
$contentType = 'text/plain';
$output = $this->renderPlainNotAllowedMessage($methods);
} else {
$status = 405;
$contentType = $this->determineContentType($request);
switch ($contentType) {
case 'application/json':
$output = $this->renderJsonNotAllowedMessage($methods);
break;
case 'text/xml':
case 'application/xml':
$output = $this->renderXmlNotAllowedMessage($methods);
break;
case 'text/html':
$output = $this->renderHtmlNotAllowedMessage($methods);
break;
}
}
$body = new Body(fopen('php://temp', 'r+'));
$body->write($output);
$allow = implode(', ', $methods);
return $response
->withStatus($status)
->withHeader('Content-type', $contentType)
->withHeader('Allow', $allow)
->withBody($body);
}
/**
* Determine which content type we know about is wanted using Accept header
*
* @param ServerRequestInterface $request
* @return string
*/
private function determineContentType(ServerRequestInterface $request)
{
$acceptHeader = $request->getHeaderLine('Accept');
$selectedContentTypes = array_intersect(explode(',', $acceptHeader), $this->knownContentTypes);
if (count($selectedContentTypes)) {
return $selectedContentTypes[0];
}
return 'text/html';
}
/**
* Render PLAIN not allowed message
*
* @param array $methods
* @return string
*/
protected function renderPlainNotAllowedMessage($methods)
{
$allow = implode(', ', $methods);
return 'Allowed methods: ' . $allow;
}
/**
* Render JSON not allowed message
*
* @param array $methods
* @return string
*/
protected function renderJsonNotAllowedMessage($methods)
{
$allow = implode(', ', $methods);
return '{"message":"Method not allowed. Must be one of: ' . $allow . '"}';
}
/**
* Render XML not allowed message
*
* @param array $methods
* @return string
*/
protected function renderXmlNotAllowedMessage($methods)
{
$allow = implode(', ', $methods);
return "<root><message>Method not allowed. Must be one of: $allow</message></root>";
}
/**
* Render HTML not allowed message
*
* @param array $methods
* @return string
*/
protected function renderHtmlNotAllowedMessage($methods)
{
$allow = implode(', ', $methods);
$output = <<<END
<html>
<head>
<title>Method not allowed</title>
<style>
body{
margin:0;
padding:30px;
font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;
}
h1{
margin:0;
font-size:48px;
font-weight:normal;
line-height:48px;
}
</style>
</head>
<body>
<h1>Method not allowed</h1>
<p>Method not allowed. Must be one of: <strong>$allow</strong></p>
</body>
</html>
END;
return $output;
}
}

View file

@ -0,0 +1,157 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Handlers;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Slim\Http\Body;
/**
* Default Slim application not found handler.
*
* It outputs a simple message in either JSON, XML or HTML based on the
* Accept header.
*/
class NotFound
{
/**
* Known handled content types
*
* @var array
*/
protected $knownContentTypes = [
'application/json',
'application/xml',
'text/xml',
'text/html',
];
/**
* Invoke not found handler
*
* @param ServerRequestInterface $request The most recent Request object
* @param ResponseInterface $response The most recent Response object
*
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
{
$contentType = $this->determineContentType($request);
switch ($contentType) {
case 'application/json':
$output = $this->renderJsonNotFoundOutput($request, $response);
break;
case 'text/xml':
case 'application/xml':
$output = $this->renderXmlNotFoundOutput($request, $response);
break;
case 'text/html':
$output = $this->renderHtmlNotFoundOutput($request, $response);
}
$body = new Body(fopen('php://temp', 'r+'));
$body->write($output);
return $response->withStatus(404)
->withHeader('Content-Type', $contentType)
->withBody($body);
}
/**
* Determine which content type we know about is wanted using Accept header
*
* @param ServerRequestInterface $request
* @return string
*/
private function determineContentType(ServerRequestInterface $request)
{
$acceptHeader = $request->getHeaderLine('Accept');
$selectedContentTypes = array_intersect(explode(',', $acceptHeader), $this->knownContentTypes);
if (count($selectedContentTypes)) {
return $selectedContentTypes[0];
}
return 'text/html';
}
/**
* Return a response for application/json content not found
*
* @param ServerRequestInterface $request The most recent Request object
* @param ResponseInterface $response The most recent Response object
*
* @return ResponseInterface
*/
protected function renderJsonNotFoundOutput(ServerRequestInterface $request, ResponseInterface $response)
{
return '{"message":"Not found"}';
}
/**
* Return a response for xml content not found
*
* @param ServerRequestInterface $request The most recent Request object
* @param ResponseInterface $response The most recent Response object
*
* @return ResponseInterface
*/
protected function renderXmlNotFoundOutput(ServerRequestInterface $request, ResponseInterface $response)
{
return '<root><message>Not found</message></root>';
}
/**
* Return a response for text/html content not found
*
* @param ServerRequestInterface $request The most recent Request object
* @param ResponseInterface $response The most recent Response object
*
* @return ResponseInterface
*/
protected function renderHtmlNotFoundOutput(ServerRequestInterface $request, ResponseInterface $response)
{
$homeUrl = (string)($request->getUri()->withPath('')->withQuery('')->withFragment(''));
return <<<END
<html>
<head>
<title>Page Not Found</title>
<style>
body{
margin:0;
padding:30px;
font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;
}
h1{
margin:0;
font-size:48px;
font-weight:normal;
line-height:48px;
}
strong{
display:inline-block;
width:65px;
}
</style>
</head>
<body>
<h1>Page Not Found</h1>
<p>
The page you are looking for could not be found. Check the address bar
to ensure your URL is spelled correctly. If all else fails, you can
visit our home page at the link below.
</p>
<a href='$homeUrl'>Visit the Home Page</a>
</body>
</html>
END;
}
}

View file

@ -0,0 +1,303 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Handlers;
use Throwable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Http\Body;
/**
* Default Slim application error handler for PHP 7+ Throwables
*
* It outputs the error message and diagnostic information in either JSON, XML,
* or HTML based on the Accept header.
*/
class PhpError
{
protected $displayErrorDetails;
/**
* Known handled content types
*
* @var array
*/
protected $knownContentTypes = [
'application/json',
'application/xml',
'text/xml',
'text/html',
];
/**
* Constructor
*
* @param boolean $displayErrorDetails Set to true to display full details
*/
public function __construct($displayErrorDetails = false)
{
$this->displayErrorDetails = (bool)$displayErrorDetails;
}
/**
* Invoke error handler
*
* @param ServerRequestInterface $request The most recent Request object
* @param ResponseInterface $response The most recent Response object
* @param Throwable $error The caught Throwable object
*
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Throwable $error)
{
$contentType = $this->determineContentType($request);
switch ($contentType) {
case 'application/json':
$output = $this->renderJsonErrorMessage($error);
break;
case 'text/xml':
case 'application/xml':
$output = $this->renderXmlErrorMessage($error);
break;
case 'text/html':
$output = $this->renderHtmlErrorMessage($error);
break;
}
$this->writeToErrorLog($error);
$body = new Body(fopen('php://temp', 'r+'));
$body->write($output);
return $response
->withStatus(500)
->withHeader('Content-type', $contentType)
->withBody($body);
}
/**
* Write to the error log if displayErrorDetails is false
*
* @param Throwable $error
*
* @return void
*/
protected function writeToErrorLog($error)
{
if ($this->displayErrorDetails) {
return;
}
$message = 'Slim Application Error:' . PHP_EOL;
$message .= $this->renderTextError($error);
while ($error = $error->getPrevious()) {
$message .= PHP_EOL . 'Previous error:' . PHP_EOL;
$message .= $this->renderTextError($error);
}
$message .= PHP_EOL . 'View in rendered output by enabling the "displayErrorDetails" setting.' . PHP_EOL;
error_log($message);
}
/**
* Render error as Text.
*
* @param Throwable $error
*
* @return string
*/
protected function renderTextError(Throwable $error)
{
$text = sprintf('Type: %s' . PHP_EOL, get_class($error));
if (($code = $error->getCode())) {
$text .= sprintf('Code: %s' . PHP_EOL, $code);
}
if (($message = $error->getMessage())) {
$text .= sprintf('Message: %s' . PHP_EOL, htmlentities($message));
}
if (($file = $error->getFile())) {
$text .= sprintf('File: %s' . PHP_EOL, $file);
}
if (($line = $error->getLine())) {
$text .= sprintf('Line: %s' . PHP_EOL, $line);
}
if (($trace = $error->getTraceAsString())) {
$text .= sprintf('Trace: %s', $trace);
}
return $text;
}
/**
* Render HTML error page
*
* @param Throwable $error
*
* @return string
*/
protected function renderHtmlErrorMessage(Throwable $error)
{
$title = 'Slim Application Error';
if ($this->displayErrorDetails) {
$html = '<p>The application could not run because of the following error:</p>';
$html .= '<h2>Details</h2>';
$html .= $this->renderHtmlError($error);
while ($error = $error->getPrevious()) {
$html .= '<h2>Previous error</h2>';
$html .= $this->renderHtmlError($error);
}
} else {
$html = '<p>A website error has occurred. Sorry for the temporary inconvenience.</p>';
}
$output = sprintf(
"<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" .
"<title>%s</title><style>body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana," .
"sans-serif;}h1{margin:0;font-size:48px;font-weight:normal;line-height:48px;}strong{" .
"display:inline-block;width:65px;}</style></head><body><h1>%s</h1>%s</body></html>",
$title,
$title,
$html
);
return $output;
}
/**
* Render error as HTML.
*
* @param Throwable $error
*
* @return string
*/
protected function renderHtmlError(Throwable $error)
{
$html = sprintf('<div><strong>Type:</strong> %s</div>', get_class($error));
if (($code = $error->getCode())) {
$html .= sprintf('<div><strong>Code:</strong> %s</div>', $code);
}
if (($message = $error->getMessage())) {
$html .= sprintf('<div><strong>Message:</strong> %s</div>', htmlentities($message));
}
if (($file = $error->getFile())) {
$html .= sprintf('<div><strong>File:</strong> %s</div>', $file);
}
if (($line = $error->getLine())) {
$html .= sprintf('<div><strong>Line:</strong> %s</div>', $line);
}
if (($trace = $error->getTraceAsString())) {
$html .= '<h2>Trace</h2>';
$html .= sprintf('<pre>%s</pre>', htmlentities($trace));
}
return $html;
}
/**
* Render JSON error
*
* @param Throwable $error
*
* @return string
*/
protected function renderJsonErrorMessage(Throwable $error)
{
$json = [
'message' => 'Slim Application Error',
];
if ($this->displayErrorDetails) {
$json['error'] = [];
do {
$json['error'][] = [
'type' => get_class($error),
'code' => $error->getCode(),
'message' => $error->getMessage(),
'file' => $error->getFile(),
'line' => $error->getLine(),
'trace' => explode("\n", $error->getTraceAsString()),
];
} while ($error = $error->getPrevious());
}
return json_encode($json, JSON_PRETTY_PRINT);
}
/**
* Render XML error
*
* @param Throwable $error
* @return string
*/
protected function renderXmlErrorMessage(Throwable $error)
{
$xml = "<error>\n <message>Slim Application Error</message>\n";
if ($this->displayErrorDetails) {
do {
$xml .= " <error>\n";
$xml .= " <type>" . get_class($error) . "</type>\n";
$xml .= " <code>" . $error->getCode() . "</code>\n";
$xml .= " <message>" . $this->createCdataSection($error->getMessage()) . "</message>\n";
$xml .= " <file>" . $error->getFile() . "</file>\n";
$xml .= " <line>" . $error->getLine() . "</line>\n";
$xml .= " <trace>" . $this->createCdataSection($error->getTraceAsString()) . "</trace>\n";
$xml .= " </error>\n";
} while ($error = $error->getPrevious());
}
$xml .= "</error>";
return $xml;
}
/**
* Returns a CDATA section with the given content.
*
* @param string $content
* @return string
*/
private function createCdataSection($content)
{
return sprintf('<![CDATA[%s]]>', str_replace(']]>', ']]]]><![CDATA[>', $content));
}
/**
* Determine which content type we know about is wanted using Accept header
*
* @param ServerRequestInterface $request
* @return string
*/
private function determineContentType(ServerRequestInterface $request)
{
$acceptHeader = $request->getHeaderLine('Accept');
$selectedContentTypes = array_intersect(explode(',', $acceptHeader), $this->knownContentTypes);
if (count($selectedContentTypes)) {
return $selectedContentTypes[0];
}
return 'text/html';
}
}

View file

@ -0,0 +1,43 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Handlers\Strategies;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Interfaces\InvocationStrategyInterface;
/**
* Default route callback strategy with route parameters as an array of arguments.
*/
class RequestResponse implements InvocationStrategyInterface
{
/**
* Invoke a route callable with request, response, and all route parameters
* as an array of arguments.
*
* @param array|callable $callable
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param array $routeArguments
*
* @return mixed
*/
public function __invoke(
callable $callable,
ServerRequestInterface $request,
ResponseInterface $response,
array $routeArguments
) {
foreach ($routeArguments as $k => $v) {
$request = $request->withAttribute($k, $v);
}
return call_user_func($callable, $request, $response, $routeArguments);
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Handlers\Strategies;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Interfaces\InvocationStrategyInterface;
/**
* Route callback strategy with route parameters as individual arguments.
*/
class RequestResponseArgs implements InvocationStrategyInterface
{
/**
* Invoke a route callable with request, response and all route parameters
* as individual arguments.
*
* @param array|callable $callable
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param array $routeArguments
*
* @return mixed
*/
public function __invoke(
callable $callable,
ServerRequestInterface $request,
ResponseInterface $response,
array $routeArguments
) {
array_unshift($routeArguments, $request, $response);
return call_user_func_array($callable, $routeArguments);
}
}

22
vendor/slim/slim/Slim/Http/Body.php vendored Normal file
View file

@ -0,0 +1,22 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Http;
/**
* Body
*
* This class represents an HTTP message body and encapsulates a
* streamable resource according to the PSR-7 standard.
*
* @link https://github.com/php-fig/http-message/blob/master/src/StreamInterface.php
*/
class Body extends Stream
{
}

195
vendor/slim/slim/Slim/Http/Cookies.php vendored Normal file
View file

@ -0,0 +1,195 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Http;
use InvalidArgumentException;
use Slim\Interfaces\Http\CookiesInterface;
/**
* Cookie helper
*/
class Cookies implements CookiesInterface
{
/**
* Cookies from HTTP request
*
* @var array
*/
protected $requestCookies = [];
/**
* Cookies for HTTP response
*
* @var array
*/
protected $responseCookies = [];
/**
* Default cookie properties
*
* @var array
*/
protected $defaults = [
'value' => '',
'domain' => null,
'hostonly' => null,
'path' => null,
'expires' => null,
'secure' => false,
'httponly' => false
];
/**
* Create new cookies helper
*
* @param array $cookies
*/
public function __construct(array $cookies = [])
{
$this->requestCookies = $cookies;
}
/**
* Set default cookie properties
*
* @param array $settings
*/
public function setDefaults(array $settings)
{
$this->defaults = array_replace($this->defaults, $settings);
}
/**
* Get request cookie
*
* @param string $name Cookie name
* @param mixed $default Cookie default value
*
* @return mixed Cookie value if present, else default
*/
public function get($name, $default = null)
{
return isset($this->requestCookies[$name]) ? $this->requestCookies[$name] : $default;
}
/**
* Set response cookie
*
* @param string $name Cookie name
* @param string|array $value Cookie value, or cookie properties
*/
public function set($name, $value)
{
if (!is_array($value)) {
$value = ['value' => (string)$value];
}
$this->responseCookies[$name] = array_replace($this->defaults, $value);
}
/**
* Convert to `Set-Cookie` headers
*
* @return string[]
*/
public function toHeaders()
{
$headers = [];
foreach ($this->responseCookies as $name => $properties) {
$headers[] = $this->toHeader($name, $properties);
}
return $headers;
}
/**
* Convert to `Set-Cookie` header
*
* @param string $name Cookie name
* @param array $properties Cookie properties
*
* @return string
*/
protected function toHeader($name, array $properties)
{
$result = urlencode($name) . '=' . urlencode($properties['value']);
if (isset($properties['domain'])) {
$result .= '; domain=' . $properties['domain'];
}
if (isset($properties['path'])) {
$result .= '; path=' . $properties['path'];
}
if (isset($properties['expires'])) {
if (is_string($properties['expires'])) {
$timestamp = strtotime($properties['expires']);
} else {
$timestamp = (int)$properties['expires'];
}
if ($timestamp !== 0) {
$result .= '; expires=' . gmdate('D, d-M-Y H:i:s e', $timestamp);
}
}
if (isset($properties['secure']) && $properties['secure']) {
$result .= '; secure';
}
if (isset($properties['hostonly']) && $properties['hostonly']) {
$result .= '; HostOnly';
}
if (isset($properties['httponly']) && $properties['httponly']) {
$result .= '; HttpOnly';
}
return $result;
}
/**
* Parse HTTP request `Cookie:` header and extract
* into a PHP associative array.
*
* @param string $header The raw HTTP request `Cookie:` header
*
* @return array Associative array of cookie names and values
*
* @throws InvalidArgumentException if the cookie data cannot be parsed
*/
public static function parseHeader($header)
{
if (is_array($header) === true) {
$header = isset($header[0]) ? $header[0] : '';
}
if (is_string($header) === false) {
throw new InvalidArgumentException('Cannot parse Cookie data. Header value must be a string.');
}
$header = rtrim($header, "\r\n");
$pieces = preg_split('@\s*[;,]\s*@', $header);
$cookies = [];
foreach ($pieces as $cookie) {
$cookie = explode('=', $cookie, 2);
if (count($cookie) === 2) {
$key = urldecode($cookie[0]);
$value = urldecode($cookie[1]);
if (!isset($cookies[$key])) {
$cookies[$key] = $value;
}
}
}
return $cookies;
}
}

View file

@ -0,0 +1,52 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Http;
use Slim\Collection;
use Slim\Interfaces\Http\EnvironmentInterface;
/**
* Environment
*
* This class decouples the Slim application from the global PHP environment.
* This is particularly useful for unit testing, but it also lets us create
* custom sub-requests.
*/
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 = [])
{
$data = array_merge([
'SERVER_PROTOCOL' => 'HTTP/1.1',
'REQUEST_METHOD' => 'GET',
'SCRIPT_NAME' => '',
'REQUEST_URI' => '',
'QUERY_STRING' => '',
'SERVER_NAME' => 'localhost',
'SERVER_PORT' => 80,
'HTTP_HOST' => 'localhost',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.8',
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'HTTP_USER_AGENT' => 'Slim Framework',
'REMOTE_ADDR' => '127.0.0.1',
'REQUEST_TIME' => time(),
'REQUEST_TIME_FLOAT' => microtime(true),
], $userData);
return new static($data);
}
}

197
vendor/slim/slim/Slim/Http/Headers.php vendored Normal file
View file

@ -0,0 +1,197 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Http;
use Slim\Collection;
use Slim\Interfaces\Http\HeadersInterface;
/**
* Headers
*
* This class represents a collection of HTTP headers
* that is used in both the HTTP request and response objects.
* It also enables header name case-insensitivity when
* getting or setting a header value.
*
* Each HTTP header can have multiple values. This class
* stores values into an array for each header name. When
* you request a header value, you receive an array of values
* for that header.
*/
class Headers extends Collection implements HeadersInterface
{
/**
* Special HTTP headers that do not have the "HTTP_" prefix
*
* @var array
*/
protected static $special = [
'CONTENT_TYPE' => 1,
'CONTENT_LENGTH' => 1,
'PHP_AUTH_USER' => 1,
'PHP_AUTH_PW' => 1,
'PHP_AUTH_DIGEST' => 1,
'AUTH_TYPE' => 1,
];
/**
* Create new headers collection with data extracted from
* the application Environment object
*
* @param Environment $environment The Slim application Environment
*
* @return self
*/
public static function createFromEnvironment(Environment $environment)
{
$data = [];
foreach ($environment as $key => $value) {
$key = strtoupper($key);
if (isset(static::$special[$key]) || strpos($key, 'HTTP_') === 0) {
if ($key !== 'HTTP_CONTENT_LENGTH') {
$data[$key] = $value;
}
}
}
return new static($data);
}
/**
* Return array of HTTP header names and values.
* This method returns the _original_ header name
* as specified by the end user.
*
* @return array
*/
public function all()
{
$all = parent::all();
$out = [];
foreach ($all as $key => $props) {
$out[$props['originalKey']] = $props['value'];
}
return $out;
}
/**
* Set HTTP header value
*
* This method sets a header value. It replaces
* any values that may already exist for the header name.
*
* @param string $key The case-insensitive header name
* @param string $value The header value
*/
public function set($key, $value)
{
if (!is_array($value)) {
$value = [$value];
}
parent::set($this->normalizeKey($key), [
'value' => $value,
'originalKey' => $key
]);
}
/**
* Get HTTP header value
*
* @param string $key The case-insensitive header name
* @param mixed $default The default value if key does not exist
*
* @return string[]
*/
public function get($key, $default = null)
{
if ($this->has($key)) {
return parent::get($this->normalizeKey($key))['value'];
}
return $default;
}
/**
* Get HTTP header key as originally specified
*
* @param string $key The case-insensitive header name
* @param mixed $default The default value if key does not exist
*
* @return string
*/
public function getOriginalKey($key, $default = null)
{
if ($this->has($key)) {
return parent::get($this->normalizeKey($key))['originalKey'];
}
return $default;
}
/**
* Add HTTP header value
*
* This method appends a header value. Unlike the set() method,
* this method _appends_ this new value to any values
* that already exist for this header name.
*
* @param string $key The case-insensitive header name
* @param array|string $value The new header value(s)
*/
public function add($key, $value)
{
$oldValues = $this->get($key, []);
$newValues = is_array($value) ? $value : [$value];
$this->set($key, array_merge($oldValues, array_values($newValues)));
}
/**
* Does this collection have a given header?
*
* @param string $key The case-insensitive header name
*
* @return bool
*/
public function has($key)
{
return parent::has($this->normalizeKey($key));
}
/**
* Remove header from collection
*
* @param string $key The case-insensitive header name
*/
public function remove($key)
{
parent::remove($this->normalizeKey($key));
}
/**
* Normalize header name
*
* This method transforms header names into a
* normalized form. This is how we enable case-insensitive
* header names in the other methods in this class.
*
* @param string $key The case-insensitive header name
*
* @return string Normalized header name
*/
public function normalizeKey($key)
{
$key = strtr(strtolower($key), '_', '-');
if (strpos($key, 'http-') === 0) {
$key = substr($key, 5);
}
return $key;
}
}

295
vendor/slim/slim/Slim/Http/Message.php vendored Normal file
View file

@ -0,0 +1,295 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Http;
use InvalidArgumentException;
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\StreamInterface;
/**
* Abstract message (base class for Request and Response)
*
* This class represents a general HTTP message. It provides common properties and methods for
* the HTTP request and response, as defined in the PSR-7 MessageInterface.
*
* @link https://github.com/php-fig/http-message/blob/master/src/MessageInterface.php
* @see Slim\Http\Request
* @see Slim\Http\Response
*/
abstract class Message implements MessageInterface
{
/**
* Protocol version
*
* @var string
*/
protected $protocolVersion = '1.1';
/**
* Headers
*
* @var \Slim\Interfaces\Http\HeadersInterface
*/
protected $headers;
/**
* Body object
*
* @var \Psr\Http\Message\StreamInterface
*/
protected $body;
/**
* Disable magic setter to ensure immutability
*/
public function __set($name, $value)
{
// Do nothing
}
/*******************************************************************************
* Protocol
******************************************************************************/
/**
* Retrieves the HTTP protocol version as a string.
*
* The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
*
* @return string HTTP protocol version.
*/
public function getProtocolVersion()
{
return $this->protocolVersion;
}
/**
* Return an instance with the specified HTTP protocol version.
*
* The version string MUST contain only the HTTP version number (e.g.,
* "1.1", "1.0").
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* new protocol version.
*
* @param string $version HTTP protocol version
* @return static
* @throws InvalidArgumentException if the http version is an invalid number
*/
public function withProtocolVersion($version)
{
static $valid = [
'1.0' => true,
'1.1' => true,
'2.0' => true,
];
if (!isset($valid[$version])) {
throw new InvalidArgumentException('Invalid HTTP version. Must be one of: 1.0, 1.1, 2.0');
}
$clone = clone $this;
$clone->protocolVersion = $version;
return $clone;
}
/*******************************************************************************
* Headers
******************************************************************************/
/**
* Retrieves all message header values.
*
* The keys represent the header name as it will be sent over the wire, and
* each value is an array of strings associated with the header.
*
* // Represent the headers as a string
* foreach ($message->getHeaders() as $name => $values) {
* echo $name . ": " . implode(", ", $values);
* }
*
* // Emit headers iteratively:
* foreach ($message->getHeaders() as $name => $values) {
* foreach ($values as $value) {
* header(sprintf('%s: %s', $name, $value), false);
* }
* }
*
* While header names are not case-sensitive, getHeaders() will preserve the
* exact case in which headers were originally specified.
*
* @return array Returns an associative array of the message's headers. Each
* key MUST be a header name, and each value MUST be an array of strings
* for that header.
*/
public function getHeaders()
{
return $this->headers->all();
}
/**
* Checks if a header exists by the given case-insensitive name.
*
* @param string $name Case-insensitive header field name.
* @return bool Returns true if any header names match the given header
* name using a case-insensitive string comparison. Returns false if
* no matching header name is found in the message.
*/
public function hasHeader($name)
{
return $this->headers->has($name);
}
/**
* Retrieves a message header value by the given case-insensitive name.
*
* This method returns an array of all the header values of the given
* case-insensitive header name.
*
* If the header does not appear in the message, this method MUST return an
* empty array.
*
* @param string $name Case-insensitive header field name.
* @return string[] An array of string values as provided for the given
* header. If the header does not appear in the message, this method MUST
* return an empty array.
*/
public function getHeader($name)
{
return $this->headers->get($name, []);
}
/**
* Retrieves a comma-separated string of the values for a single header.
*
* This method returns all of the header values of the given
* case-insensitive header name as a string concatenated together using
* a comma.
*
* NOTE: Not all header values may be appropriately represented using
* comma concatenation. For such headers, use getHeader() instead
* and supply your own delimiter when concatenating.
*
* If the header does not appear in the message, this method MUST return
* an empty string.
*
* @param string $name Case-insensitive header field name.
* @return string A string of values as provided for the given header
* concatenated together using a comma. If the header does not appear in
* the message, this method MUST return an empty string.
*/
public function getHeaderLine($name)
{
return implode(',', $this->headers->get($name, []));
}
/**
* Return an instance with the provided value replacing the specified header.
*
* While header names are case-insensitive, the casing of the header will
* be preserved by this function, and returned from getHeaders().
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* new and/or updated header and value.
*
* @param string $name Case-insensitive header field name.
* @param string|string[] $value Header value(s).
* @return static
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withHeader($name, $value)
{
$clone = clone $this;
$clone->headers->set($name, $value);
return $clone;
}
/**
* Return an instance with the specified header appended with the given value.
*
* Existing values for the specified header will be maintained. The new
* value(s) will be appended to the existing list. If the header did not
* exist previously, it will be added.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* new header and/or value.
*
* @param string $name Case-insensitive header field name to add.
* @param string|string[] $value Header value(s).
* @return static
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withAddedHeader($name, $value)
{
$clone = clone $this;
$clone->headers->add($name, $value);
return $clone;
}
/**
* Return an instance without the specified header.
*
* Header resolution MUST be done without case-sensitivity.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that removes
* the named header.
*
* @param string $name Case-insensitive header field name to remove.
* @return static
*/
public function withoutHeader($name)
{
$clone = clone $this;
$clone->headers->remove($name);
return $clone;
}
/*******************************************************************************
* Body
******************************************************************************/
/**
* Gets the body of the message.
*
* @return StreamInterface Returns the body as a stream.
*/
public function getBody()
{
return $this->body;
}
/**
* Return an instance with the specified message body.
*
* The body MUST be a StreamInterface object.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return a new instance that has the
* new body stream.
*
* @param StreamInterface $body Body.
* @return static
* @throws \InvalidArgumentException When the body is not valid.
*/
public function withBody(StreamInterface $body)
{
// TODO: Test for invalid body?
$clone = clone $this;
$clone->body = $body;
return $clone;
}
}

1150
vendor/slim/slim/Slim/Http/Request.php vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,27 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Http;
/**
* Provides a PSR-7 implementation of a reusable raw request body
*/
class RequestBody extends Body
{
/**
* Create a new RequestBody.
*/
public function __construct()
{
$stream = fopen('php://temp', 'w+');
stream_copy_to_stream(fopen('php://input', 'r'), $stream);
rewind($stream);
parent::__construct($stream);
}
}

461
vendor/slim/slim/Slim/Http/Response.php vendored Normal file
View file

@ -0,0 +1,461 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Http;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
use Slim\Interfaces\Http\HeadersInterface;
/**
* Response
*
* This class represents an HTTP response. It manages
* the response status, headers, and body
* according to the PSR-7 standard.
*
* @link https://github.com/php-fig/http-message/blob/master/src/MessageInterface.php
* @link https://github.com/php-fig/http-message/blob/master/src/ResponseInterface.php
*/
class Response extends Message implements ResponseInterface
{
/**
* Status code
*
* @var int
*/
protected $status = 200;
/**
* Reason phrase
*
* @var string
*/
protected $reasonPhrase = '';
/**
* Status codes and reason phrases
*
* @var array
*/
protected static $messages = [
//Informational 1xx
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
//Successful 2xx
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',
226 => 'IM Used',
//Redirection 3xx
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
306 => '(Unused)',
307 => 'Temporary Redirect',
308 => 'Permanent Redirect',
//Client Error 4xx
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 Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
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',
426 => 'Upgrade Required',
428 => 'Precondition Required',
429 => 'Too Many Requests',
431 => 'Request Header Fields Too Large',
451 => 'Unavailable For Legal Reasons',
//Server Error 5xx
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
506 => 'Variant Also Negotiates',
507 => 'Insufficient Storage',
508 => 'Loop Detected',
510 => 'Not Extended',
511 => 'Network Authentication Required',
];
/**
* 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.
*/
public function __construct($status = 200, HeadersInterface $headers = null, StreamInterface $body = null)
{
$this->status = $this->filterStatus($status);
$this->headers = $headers ? $headers : new Headers();
$this->body = $body ? $body : new Body(fopen('php://temp', 'r+'));
}
/**
* This method is applied to the cloned object
* after PHP performs an initial shallow-copy. This
* method completes a deep-copy by creating new objects
* for the cloned object's internal reference pointers.
*/
public function __clone()
{
$this->headers = clone $this->headers;
$this->body = clone $this->body;
}
/*******************************************************************************
* Status
******************************************************************************/
/**
* Gets the response status code.
*
* The status code is a 3-digit integer result code of the server's attempt
* to understand and satisfy the request.
*
* @return int Status code.
*/
public function getStatusCode()
{
return $this->status;
}
/**
* Return an instance with the specified status code and, optionally, reason phrase.
*
* If no reason phrase is specified, implementations MAY choose to default
* to the RFC 7231 or IANA recommended reason phrase for the response's
* status code.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* updated status and reason phrase.
*
* @link http://tools.ietf.org/html/rfc7231#section-6
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
* @param int $code The 3-digit integer result code to set.
* @param string $reasonPhrase The reason phrase to use with the
* provided status code; if none is provided, implementations MAY
* use the defaults as suggested in the HTTP specification.
* @return self
* @throws \InvalidArgumentException For invalid status code arguments.
*/
public function withStatus($code, $reasonPhrase = '')
{
$code = $this->filterStatus($code);
if (!is_string($reasonPhrase) && !method_exists($reasonPhrase, '__toString')) {
throw new InvalidArgumentException('ReasonPhrase must be a string');
}
$clone = clone $this;
$clone->status = $code;
if ($reasonPhrase === '' && isset(static::$messages[$code])) {
$reasonPhrase = static::$messages[$code];
}
if ($reasonPhrase === '') {
throw new InvalidArgumentException('ReasonPhrase must be supplied for this code');
}
$clone->reasonPhrase = $reasonPhrase;
return $clone;
}
/**
* Filter HTTP status code.
*
* @param int $status HTTP status code.
* @return int
* @throws \InvalidArgumentException If an invalid HTTP status code is provided.
*/
protected function filterStatus($status)
{
if (!is_integer($status) || $status<100 || $status>599) {
throw new InvalidArgumentException('Invalid HTTP status code');
}
return $status;
}
/**
* Gets the response reason phrase associated with the status code.
*
* Because a reason phrase is not a required element in a response
* status line, the reason phrase value MAY be null. Implementations MAY
* choose to return the default RFC 7231 recommended reason phrase (or those
* listed in the IANA HTTP Status Code Registry) for the response's
* status code.
*
* @link http://tools.ietf.org/html/rfc7231#section-6
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
* @return string Reason phrase; must return an empty string if none present.
*/
public function getReasonPhrase()
{
if ($this->reasonPhrase) {
return $this->reasonPhrase;
}
if (isset(static::$messages[$this->status])) {
return static::$messages[$this->status];
}
return '';
}
/*******************************************************************************
* Body
******************************************************************************/
/**
* Write data to the response body.
*
* Note: This method is not part of the PSR-7 standard.
*
* Proxies to the underlying stream and writes the provided data to it.
*
* @param string $data
* @return self
*/
public function write($data)
{
$this->getBody()->write($data);
return $this;
}
/*******************************************************************************
* Response Helpers
******************************************************************************/
/**
* Redirect.
*
* Note: This method is not part of the PSR-7 standard.
*
* This method prepares the response object to return an HTTP Redirect
* response to the client.
*
* @param string|UriInterface $url The redirect destination.
* @param int $status The redirect HTTP status code.
* @return self
*/
public function withRedirect($url, $status = 302)
{
return $this->withStatus($status)->withHeader('Location', (string)$url);
}
/**
* Json.
*
* Note: This method is not part of the PSR-7 standard.
*
* This method prepares the response object to return an HTTP Json
* response to the client.
*
* @param mixed $data The data
* @param int $status The HTTP status code.
* @param int $encodingOptions Json encoding options
* @throws \RuntimeException
* @return self
*/
public function withJson($data, $status = null, $encodingOptions = 0)
{
$body = $this->getBody();
$body->rewind();
$body->write($json = json_encode($data, $encodingOptions));
// Ensure that the json encoding passed successfully
if ($json === false) {
throw new \RuntimeException(json_last_error_msg(), json_last_error());
}
$responseWithJson = $this->withHeader('Content-Type', 'application/json;charset=utf-8');
if (isset($status)) {
return $responseWithJson->withStatus($status);
}
return $responseWithJson;
}
/**
* Is this response empty?
*
* Note: This method is not part of the PSR-7 standard.
*
* @return bool
*/
public function isEmpty()
{
return in_array($this->getStatusCode(), [204, 205, 304]);
}
/**
* Is this response informational?
*
* Note: This method is not part of the PSR-7 standard.
*
* @return bool
*/
public function isInformational()
{
return $this->getStatusCode() >= 100 && $this->getStatusCode() < 200;
}
/**
* Is this response OK?
*
* Note: This method is not part of the PSR-7 standard.
*
* @return bool
*/
public function isOk()
{
return $this->getStatusCode() === 200;
}
/**
* Is this response successful?
*
* Note: This method is not part of the PSR-7 standard.
*
* @return bool
*/
public function isSuccessful()
{
return $this->getStatusCode() >= 200 && $this->getStatusCode() < 300;
}
/**
* Is this response a redirect?
*
* Note: This method is not part of the PSR-7 standard.
*
* @return bool
*/
public function isRedirect()
{
return in_array($this->getStatusCode(), [301, 302, 303, 307]);
}
/**
* Is this response a redirection?
*
* Note: This method is not part of the PSR-7 standard.
*
* @return bool
*/
public function isRedirection()
{
return $this->getStatusCode() >= 300 && $this->getStatusCode() < 400;
}
/**
* Is this response forbidden?
*
* Note: This method is not part of the PSR-7 standard.
*
* @return bool
* @api
*/
public function isForbidden()
{
return $this->getStatusCode() === 403;
}
/**
* Is this response not Found?
*
* Note: This method is not part of the PSR-7 standard.
*
* @return bool
*/
public function isNotFound()
{
return $this->getStatusCode() === 404;
}
/**
* Is this response a client error?
*
* Note: This method is not part of the PSR-7 standard.
*
* @return bool
*/
public function isClientError()
{
return $this->getStatusCode() >= 400 && $this->getStatusCode() < 500;
}
/**
* Is this response a server error?
*
* Note: This method is not part of the PSR-7 standard.
*
* @return bool
*/
public function isServerError()
{
return $this->getStatusCode() >= 500 && $this->getStatusCode() < 600;
}
/**
* Convert response to string.
*
* Note: This method is not part of the PSR-7 standard.
*
* @return string
*/
public function __toString()
{
$output = sprintf(
'HTTP/%s %s %s',
$this->getProtocolVersion(),
$this->getStatusCode(),
$this->getReasonPhrase()
);
$output .= PHP_EOL;
foreach ($this->getHeaders() as $name => $values) {
$output .= sprintf('%s: %s', $name, $this->getHeaderLine($name)) . PHP_EOL;
}
$output .= PHP_EOL;
$output .= (string)$this->getBody();
return $output;
}
}

409
vendor/slim/slim/Slim/Http/Stream.php vendored Normal file
View file

@ -0,0 +1,409 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Http;
use InvalidArgumentException;
use Psr\Http\Message\StreamInterface;
use RuntimeException;
/**
* Represents a data stream as defined in PSR-7.
*
* @link https://github.com/php-fig/http-message/blob/master/src/StreamInterface.php
*/
class Stream implements StreamInterface
{
/**
* Resource modes
*
* @var array
* @link http://php.net/manual/function.fopen.php
*/
protected static $modes = [
'readable' => ['r', 'r+', 'w+', 'a+', 'x+', 'c+'],
'writable' => ['r+', 'w', 'w+', 'a', 'a+', 'x', 'x+', 'c', 'c+'],
];
/**
* The underlying stream resource
*
* @var resource
*/
protected $stream;
/**
* Stream metadata
*
* @var array
*/
protected $meta;
/**
* Is this stream readable?
*
* @var bool
*/
protected $readable;
/**
* Is this stream writable?
*
* @var bool
*/
protected $writable;
/**
* Is this stream seekable?
*
* @var bool
*/
protected $seekable;
/**
* The size of the stream if known
*
* @var null|int
*/
protected $size;
/**
* Create a new Stream.
*
* @param resource $stream A PHP resource handle.
*
* @throws InvalidArgumentException If argument is not a resource.
*/
public function __construct($stream)
{
$this->attach($stream);
}
/**
* Get stream metadata as an associative array or retrieve a specific key.
*
* The keys returned are identical to the keys returned from PHP's
* stream_get_meta_data() function.
*
* @link http://php.net/manual/en/function.stream-get-meta-data.php
*
* @param string $key Specific metadata to retrieve.
*
* @return array|mixed|null Returns an associative array if no key is
* provided. Returns a specific key value if a key is provided and the
* value is found, or null if the key is not found.
*/
public function getMetadata($key = null)
{
$this->meta = stream_get_meta_data($this->stream);
if (is_null($key) === true) {
return $this->meta;
}
return isset($this->meta[$key]) ? $this->meta[$key] : null;
}
/**
* Is a resource attached to this stream?
*
* Note: This method is not part of the PSR-7 standard.
*
* @return bool
*/
protected function isAttached()
{
return is_resource($this->stream);
}
/**
* Attach new resource to this object.
*
* Note: This method is not part of the PSR-7 standard.
*
* @param resource $newStream A PHP resource handle.
*
* @throws InvalidArgumentException If argument is not a valid PHP resource.
*/
protected function attach($newStream)
{
if (is_resource($newStream) === false) {
throw new InvalidArgumentException(__METHOD__ . ' argument must be a valid PHP resource');
}
if ($this->isAttached() === true) {
$this->detach();
}
$this->stream = $newStream;
}
/**
* Separates any underlying resources from the stream.
*
* After the stream has been detached, the stream is in an unusable state.
*
* @return resource|null Underlying PHP stream, if any
*/
public function detach()
{
$oldResource = $this->stream;
$this->stream = null;
$this->meta = null;
$this->readable = null;
$this->writable = null;
$this->seekable = null;
$this->size = null;
return $oldResource;
}
/**
* Reads all data from the stream into a string, from the beginning to end.
*
* This method MUST attempt to seek to the beginning of the stream before
* reading data and read the stream until the end is reached.
*
* Warning: This could attempt to load a large amount of data into memory.
*
* This method MUST NOT raise an exception in order to conform with PHP's
* string casting operations.
*
* @see http://php.net/manual/en/language.oop5.magic.php#object.tostring
* @return string
*/
public function __toString()
{
if (!$this->isAttached()) {
return '';
}
try {
$this->rewind();
return $this->getContents();
} catch (RuntimeException $e) {
return '';
}
}
/**
* Closes the stream and any underlying resources.
*/
public function close()
{
if ($this->isAttached() === true) {
fclose($this->stream);
}
$this->detach();
}
/**
* Get the size of the stream if known.
*
* @return int|null Returns the size in bytes if known, or null if unknown.
*/
public function getSize()
{
if (!$this->size && $this->isAttached() === true) {
$stats = fstat($this->stream);
$this->size = isset($stats['size']) ? $stats['size'] : null;
}
return $this->size;
}
/**
* Returns the current position of the file read/write pointer
*
* @return int Position of the file pointer
*
* @throws RuntimeException on error.
*/
public function tell()
{
if (!$this->isAttached() || ($position = ftell($this->stream)) === false) {
throw new RuntimeException('Could not get the position of the pointer in stream');
}
return $position;
}
/**
* Returns true if the stream is at the end of the stream.
*
* @return bool
*/
public function eof()
{
return $this->isAttached() ? feof($this->stream) : true;
}
/**
* Returns whether or not the stream is readable.
*
* @return bool
*/
public function isReadable()
{
if ($this->readable === null) {
$this->readable = false;
if ($this->isAttached()) {
$meta = $this->getMetadata();
foreach (self::$modes['readable'] as $mode) {
if (strpos($meta['mode'], $mode) === 0) {
$this->readable = true;
break;
}
}
}
}
return $this->readable;
}
/**
* Returns whether or not the stream is writable.
*
* @return bool
*/
public function isWritable()
{
if ($this->writable === null) {
$this->writable = false;
if ($this->isAttached()) {
$meta = $this->getMetadata();
foreach (self::$modes['writable'] as $mode) {
if (strpos($meta['mode'], $mode) === 0) {
$this->writable = true;
break;
}
}
}
}
return $this->writable;
}
/**
* Returns whether or not the stream is seekable.
*
* @return bool
*/
public function isSeekable()
{
if ($this->seekable === null) {
$this->seekable = false;
if ($this->isAttached()) {
$meta = $this->getMetadata();
$this->seekable = $meta['seekable'];
}
}
return $this->seekable;
}
/**
* Seek to a position in the stream.
*
* @link http://www.php.net/manual/en/function.fseek.php
*
* @param int $offset Stream offset
* @param int $whence Specifies how the cursor position will be calculated
* based on the seek offset. Valid values are identical to the built-in
* PHP $whence values for `fseek()`. SEEK_SET: Set position equal to
* offset bytes SEEK_CUR: Set position to current location plus offset
* SEEK_END: Set position to end-of-stream plus offset.
*
* @throws RuntimeException on failure.
*/
public function seek($offset, $whence = SEEK_SET)
{
// Note that fseek returns 0 on success!
if (!$this->isSeekable() || fseek($this->stream, $offset, $whence) === -1) {
throw new RuntimeException('Could not seek in stream');
}
}
/**
* Seek to the beginning of the stream.
*
* If the stream is not seekable, this method will raise an exception;
* 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()
{
if (!$this->isSeekable() || rewind($this->stream) === false) {
throw new RuntimeException('Could not rewind stream');
}
}
/**
* Read data from the stream.
*
* @param int $length Read up to $length bytes from the object and return
* them. Fewer than $length bytes may be returned if underlying stream
* call returns fewer bytes.
*
* @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)
{
if (!$this->isReadable() || ($data = fread($this->stream, $length)) === false) {
throw new RuntimeException('Could not read from stream');
}
return $data;
}
/**
* Write data to the stream.
*
* @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)
{
if (!$this->isWritable() || ($written = fwrite($this->stream, $string)) === false) {
throw new RuntimeException('Could not write to stream');
}
// reset size so that it will be recalculated on next call to getSize()
$this->size = null;
return $written;
}
/**
* Returns the remaining contents in a string
*
* @return string
*
* @throws RuntimeException if unable to read or an error occurs while
* reading.
*/
public function getContents()
{
if (!$this->isReadable() || ($contents = stream_get_contents($this->stream)) === false) {
throw new RuntimeException('Could not get contents of stream');
}
return $contents;
}
}

View file

@ -0,0 +1,327 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Http;
use RuntimeException;
use InvalidArgumentException;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;
/**
* Represents Uploaded Files.
*
* It manages and normalizes uploaded files according to the PSR-7 standard.
*
* @link https://github.com/php-fig/http-message/blob/master/src/UploadedFileInterface.php
* @link https://github.com/php-fig/http-message/blob/master/src/StreamInterface.php
*/
class UploadedFile implements UploadedFileInterface
{
/**
* The client-provided full path to the file
*
* @note this is public to maintain BC with 3.1.0 and earlier.
*
* @var string
*/
public $file;
/**
* The client-provided file name.
*
* @var string
*/
protected $name;
/**
* The client-provided media type of the file.
*
* @var string
*/
protected $type;
/**
* The size of the file in bytes.
*
* @var int
*/
protected $size;
/**
* A valid PHP UPLOAD_ERR_xxx code for the file upload.
*
* @var int
*/
protected $error = UPLOAD_ERR_OK;
/**
* Indicates if the upload is from a SAPI environment.
*
* @var bool
*/
protected $sapi = false;
/**
* An optional StreamInterface wrapping the file resource.
*
* @var StreamInterface
*/
protected $stream;
/**
* Indicates if the uploaded file has already been moved.
*
* @var bool
*/
protected $moved = false;
/**
* Create a normalized tree of UploadedFile instances from the Environment.
*
* @param Environment $env The environment
*
* @return array|null A normalized tree of UploadedFile instances or null if none are provided.
*/
public static function createFromEnvironment(Environment $env)
{
if (is_array($env['slim.files']) && $env->has('slim.files')) {
return $env['slim.files'];
} elseif (isset($_FILES)) {
return static::parseUploadedFiles($_FILES);
}
return [];
}
/**
* Parse a non-normalized, i.e. $_FILES superglobal, tree of uploaded file data.
*
* @param array $uploadedFiles The non-normalized tree of uploaded file data.
*
* @return array A normalized tree of UploadedFile instances.
*/
private static function parseUploadedFiles(array $uploadedFiles)
{
$parsed = [];
foreach ($uploadedFiles as $field => $uploadedFile) {
if (!isset($uploadedFile['error'])) {
if (is_array($uploadedFile)) {
$parsed[$field] = static::parseUploadedFiles($uploadedFile);
}
continue;
}
$parsed[$field] = [];
if (!is_array($uploadedFile['error'])) {
$parsed[$field] = new static(
$uploadedFile['tmp_name'],
isset($uploadedFile['name']) ? $uploadedFile['name'] : null,
isset($uploadedFile['type']) ? $uploadedFile['type'] : null,
isset($uploadedFile['size']) ? $uploadedFile['size'] : null,
$uploadedFile['error'],
true
);
} else {
$subArray = [];
foreach ($uploadedFile['error'] as $fileIdx => $error) {
// normalise subarray and re-parse to move the input's keyname up a level
$subArray[$fileIdx]['name'] = $uploadedFile['name'][$fileIdx];
$subArray[$fileIdx]['type'] = $uploadedFile['type'][$fileIdx];
$subArray[$fileIdx]['tmp_name'] = $uploadedFile['tmp_name'][$fileIdx];
$subArray[$fileIdx]['error'] = $uploadedFile['error'][$fileIdx];
$subArray[$fileIdx]['size'] = $uploadedFile['size'][$fileIdx];
$parsed[$field] = static::parseUploadedFiles($subArray);
}
}
}
return $parsed;
}
/**
* Construct a new UploadedFile instance.
*
* @param string $file The full path to the uploaded file provided by the client.
* @param string|null $name The file name.
* @param string|null $type The file media type.
* @param int|null $size The file size in bytes.
* @param int $error The UPLOAD_ERR_XXX code representing the status of the upload.
* @param bool $sapi Indicates if the upload is in a SAPI environment.
*/
public function __construct($file, $name = null, $type = null, $size = null, $error = UPLOAD_ERR_OK, $sapi = false)
{
$this->file = $file;
$this->name = $name;
$this->type = $type;
$this->size = $size;
$this->error = $error;
$this->sapi = $sapi;
}
/**
* Retrieve a stream representing the uploaded file.
*
* This method MUST return a StreamInterface instance, representing the
* uploaded file. The purpose of this method is to allow utilizing native PHP
* stream functionality to manipulate the file upload, such as
* stream_copy_to_stream() (though the result will need to be decorated in a
* native PHP stream wrapper to work with such functions).
*
* If the moveTo() method has been called previously, this method MUST raise
* an exception.
*
* @return StreamInterface Stream representation of the uploaded file.
* @throws \RuntimeException in cases when no stream is available or can be
* created.
*/
public function getStream()
{
if ($this->moved) {
throw new \RuntimeException(sprintf('Uploaded file %1s has already been moved', $this->name));
}
if ($this->stream === null) {
$this->stream = new Stream(fopen($this->file, 'r'));
}
return $this->stream;
}
/**
* Move the uploaded file to a new location.
*
* Use this method as an alternative to move_uploaded_file(). This method is
* guaranteed to work in both SAPI and non-SAPI environments.
* Implementations must determine which environment they are in, and use the
* appropriate method (move_uploaded_file(), rename(), or a stream
* operation) to perform the operation.
*
* $targetPath may be an absolute path, or a relative path. If it is a
* relative path, resolution should be the same as used by PHP's rename()
* function.
*
* The original file or stream MUST be removed on completion.
*
* If this method is called more than once, any subsequent calls MUST raise
* an exception.
*
* When used in an SAPI environment where $_FILES is populated, when writing
* files via moveTo(), is_uploaded_file() and move_uploaded_file() SHOULD be
* used to ensure permissions and upload status are verified correctly.
*
* If you wish to move to a stream, use getStream(), as SAPI operations
* cannot guarantee writing to stream destinations.
*
* @see http://php.net/is_uploaded_file
* @see http://php.net/move_uploaded_file
*
* @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
* the second or subsequent call to the method.
*/
public function moveTo($targetPath)
{
if ($this->moved) {
throw new RuntimeException('Uploaded file already moved');
}
if (!is_writable(dirname($targetPath))) {
throw new InvalidArgumentException('Upload target path is not writable');
}
$targetIsStream = strpos($targetPath, '://') > 0;
if ($targetIsStream) {
if (!copy($this->file, $targetPath)) {
throw new RuntimeException(sprintf('Error moving uploaded file %1s to %2s', $this->name, $targetPath));
}
if (!unlink($this->file)) {
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));
}
if (!move_uploaded_file($this->file, $targetPath)) {
throw new RuntimeException(sprintf('Error moving uploaded file %1s to %2s', $this->name, $targetPath));
}
} else {
if (!rename($this->file, $targetPath)) {
throw new RuntimeException(sprintf('Error moving uploaded file %1s to %2s', $this->name, $targetPath));
}
}
$this->moved = true;
}
/**
* Retrieve the error associated with the uploaded file.
*
* The return value MUST be one of PHP's UPLOAD_ERR_XXX constants.
*
* If the file was uploaded successfully, this method MUST return
* UPLOAD_ERR_OK.
*
* Implementations SHOULD return the value stored in the "error" key of
* 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()
{
return $this->error;
}
/**
* Retrieve the filename sent by the client.
*
* Do not trust the value returned by this method. A client could send
* a malicious filename with the intention to corrupt or hack your
* application.
*
* Implementations SHOULD return the value stored in the "name" key of
* the file in the $_FILES array.
*
* @return string|null The filename sent by the client or null if none
* was provided.
*/
public function getClientFilename()
{
return $this->name;
}
/**
* Retrieve the media type sent by the client.
*
* Do not trust the value returned by this method. A client could send
* a malicious media type with the intention to corrupt or hack your
* application.
*
* Implementations SHOULD return the value stored in the "type" key of
* the file in the $_FILES array.
*
* @return string|null The media type sent by the client or null if none
* was provided.
*/
public function getClientMediaType()
{
return $this->type;
}
/**
* Retrieve the file size.
*
* Implementations SHOULD return the value stored in the "size" key of
* the file in the $_FILES array if available, as PHP calculates this based
* on the actual size transmitted.
*
* @return int|null The file size in bytes or null if unknown.
*/
public function getSize()
{
return $this->size;
}
}

821
vendor/slim/slim/Slim/Http/Uri.php vendored Normal file
View file

@ -0,0 +1,821 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Http;
use InvalidArgumentException;
use \Psr\Http\Message\UriInterface;
use Slim\Http\Environment;
/**
* Value object representing a URI.
*
* This interface is meant to represent URIs according to RFC 3986 and to
* provide methods for most common operations. Additional functionality for
* working with URIs can be provided on top of the interface or externally.
* Its primary use is for HTTP requests, but may also be used in other
* contexts.
*
* Instances of this interface are considered immutable; all methods that
* might change state MUST be implemented such that they retain the internal
* state of the current instance and return an instance that contains the
* changed state.
*
* Typically the Host header will be also be present in the request message.
* For server-side requests, the scheme will typically be discoverable in the
* server parameters.
*
* @link http://tools.ietf.org/html/rfc3986 (the URI specification)
*/
class Uri implements UriInterface
{
/**
* Uri scheme (without "://" suffix)
*
* @var string
*/
protected $scheme = '';
/**
* Uri user
*
* @var string
*/
protected $user = '';
/**
* Uri password
*
* @var string
*/
protected $password = '';
/**
* Uri host
*
* @var string
*/
protected $host = '';
/**
* Uri port number
*
* @var null|int
*/
protected $port;
/**
* Uri base path
*
* @var string
*/
protected $basePath = '';
/**
* Uri path
*
* @var string
*/
protected $path = '';
/**
* Uri query string (without "?" prefix)
*
* @var string
*/
protected $query = '';
/**
* Uri fragment string (without "#" prefix)
*
* @var string
*/
protected $fragment = '';
/**
* Create new Uri.
*
* @param string $scheme Uri scheme.
* @param string $host Uri host.
* @param int $port Uri port number.
* @param string $path Uri path.
* @param string $query Uri query string.
* @param string $fragment Uri fragment.
* @param string $user Uri user.
* @param string $password Uri password.
*/
public function __construct(
$scheme,
$host,
$port = null,
$path = '/',
$query = '',
$fragment = '',
$user = '',
$password = ''
) {
$this->scheme = $this->filterScheme($scheme);
$this->host = $host;
$this->port = $this->filterPort($port);
$this->path = empty($path) ? '/' : $this->filterPath($path);
$this->query = $this->filterQuery($query);
$this->fragment = $this->filterQuery($fragment);
$this->user = $user;
$this->password = $password;
}
/**
* Create new Uri from string.
*
* @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');
}
$parts = parse_url($uri);
$scheme = isset($parts['scheme']) ? $parts['scheme'] : '';
$user = isset($parts['user']) ? $parts['user'] : '';
$pass = isset($parts['pass']) ? $parts['pass'] : '';
$host = isset($parts['host']) ? $parts['host'] : '';
$port = isset($parts['port']) ? $parts['port'] : null;
$path = isset($parts['path']) ? $parts['path'] : '';
$query = isset($parts['query']) ? $parts['query'] : '';
$fragment = isset($parts['fragment']) ? $parts['fragment'] : '';
return new static($scheme, $host, $port, $path, $query, $fragment, $user, $pass);
}
/**
* Create new Uri from environment.
*
* @param Environment $env
*
* @return self
*/
public static function createFromEnvironment(Environment $env)
{
// Scheme
$isSecure = $env->get('HTTPS');
$scheme = (empty($isSecure) || $isSecure === 'off') ? 'http' : 'https';
// Authority: Username and password
$username = $env->get('PHP_AUTH_USER', '');
$password = $env->get('PHP_AUTH_PW', '');
// Authority: Host
if ($env->has('HTTP_HOST')) {
$host = $env->get('HTTP_HOST');
} else {
$host = $env->get('SERVER_NAME');
}
// Authority: Port
$port = (int)$env->get('SERVER_PORT', 80);
if (preg_match('/^(\[[a-fA-F0-9:.]+\])(:\d+)?\z/', $host, $matches)) {
$host = $matches[1];
if ($matches[2]) {
$port = (int) substr($matches[2], 1);
}
} else {
$pos = strpos($host, ':');
if ($pos !== false) {
$port = (int) substr($host, $pos + 1);
$host = strstr($host, ':', true);
}
}
// Path
$requestScriptName = parse_url($env->get('SCRIPT_NAME'), PHP_URL_PATH);
$requestScriptDir = dirname($requestScriptName);
// parse_url() requires a full URL. As we don't extract the domain name or scheme,
// we use a stand-in.
$requestUri = parse_url('http://example.com' . $env->get('REQUEST_URI'), PHP_URL_PATH);
$basePath = '';
$virtualPath = $requestUri;
if (stripos($requestUri, $requestScriptName) === 0) {
$basePath = $requestScriptName;
} elseif ($requestScriptDir !== '/' && stripos($requestUri, $requestScriptDir) === 0) {
$basePath = $requestScriptDir;
}
if ($basePath) {
$virtualPath = ltrim(substr($requestUri, strlen($basePath)), '/');
}
// Query string
$queryString = $env->get('QUERY_STRING', '');
// Fragment
$fragment = '';
// Build Uri
$uri = new static($scheme, $host, $port, $virtualPath, $queryString, $fragment, $username, $password);
if ($basePath) {
$uri = $uri->withBasePath($basePath);
}
return $uri;
}
/********************************************************************************
* Scheme
*******************************************************************************/
/**
* Retrieve the scheme component of the URI.
*
* If no scheme is present, this method MUST return an empty string.
*
* The value returned MUST be normalized to lowercase, per RFC 3986
* Section 3.1.
*
* The trailing ":" character is not part of the scheme and MUST NOT be
* added.
*
* @see https://tools.ietf.org/html/rfc3986#section-3.1
* @return string The URI scheme.
*/
public function getScheme()
{
return $this->scheme;
}
/**
* Return an instance with the specified scheme.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified scheme.
*
* Implementations MUST support the schemes "http" and "https" case
* insensitively, and MAY accommodate other schemes if required.
*
* An empty scheme is equivalent to removing the scheme.
*
* @param string $scheme The scheme to use with the new instance.
* @return self A new instance with the specified scheme.
* @throws \InvalidArgumentException for invalid or unsupported schemes.
*/
public function withScheme($scheme)
{
$scheme = $this->filterScheme($scheme);
$clone = clone $this;
$clone->scheme = $scheme;
return $clone;
}
/**
* Filter Uri 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".
*/
protected function filterScheme($scheme)
{
static $valid = [
'' => true,
'https' => true,
'http' => true,
];
if (!is_string($scheme) && !method_exists($scheme, '__toString')) {
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"');
}
return $scheme;
}
/********************************************************************************
* Authority
*******************************************************************************/
/**
* Retrieve the authority component of the URI.
*
* If no authority information is present, this method MUST return an empty
* string.
*
* The authority syntax of the URI is:
*
* <pre>
* [user-info@]host[:port]
* </pre>
*
* If the port component is not set or is the standard port for the current
* scheme, it SHOULD NOT be included.
*
* @see https://tools.ietf.org/html/rfc3986#section-3.2
* @return string The URI authority, in "[user-info@]host[:port]" format.
*/
public function getAuthority()
{
$userInfo = $this->getUserInfo();
$host = $this->getHost();
$port = $this->getPort();
return ($userInfo ? $userInfo . '@' : '') . $host . ($port !== null ? ':' . $port : '');
}
/**
* Retrieve the user information component of the URI.
*
* If no user information is present, this method MUST return an empty
* string.
*
* If a user is present in the URI, this will return that value;
* additionally, if the password is also present, it will be appended to the
* user value, with a colon (":") separating the values.
*
* The trailing "@" character is not part of the user information and MUST
* NOT be added.
*
* @return string The URI user information, in "username[:password]" format.
*/
public function getUserInfo()
{
return $this->user . ($this->password ? ':' . $this->password : '');
}
/**
* Return an instance with the specified user information.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified user information.
*
* Password is optional, but the user information MUST include the
* user; an empty string for the user is equivalent to removing user
* information.
*
* @param string $user The user name to use for authority.
* @param null|string $password The password associated with $user.
* @return self A new instance with the specified user information.
*/
public function withUserInfo($user, $password = null)
{
$clone = clone $this;
$clone->user = $user;
$clone->password = $password ? $password : '';
return $clone;
}
/**
* Retrieve the host component of the URI.
*
* If no host is present, this method MUST return an empty string.
*
* The value returned MUST be normalized to lowercase, per RFC 3986
* Section 3.2.2.
*
* @see http://tools.ietf.org/html/rfc3986#section-3.2.2
* @return string The URI host.
*/
public function getHost()
{
return $this->host;
}
/**
* Return an instance with the specified host.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified host.
*
* An empty host value is equivalent to removing the host.
*
* @param string $host The hostname to use with the new instance.
* @return self A new instance with the specified host.
* @throws \InvalidArgumentException for invalid hostnames.
*/
public function withHost($host)
{
$clone = clone $this;
$clone->host = $host;
return $clone;
}
/**
* Retrieve the port component of the URI.
*
* If a port is present, and it is non-standard for the current scheme,
* this method MUST return it as an integer. If the port is the standard port
* used with the current scheme, this method SHOULD return null.
*
* If no port is present, and no scheme is present, this method MUST return
* a null value.
*
* If no port is present, but a scheme is present, this method MAY return
* the standard port for that scheme, but SHOULD return null.
*
* @return null|int The URI port.
*/
public function getPort()
{
return $this->port && !$this->hasStandardPort() ? $this->port : null;
}
/**
* Return an instance with the specified port.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified port.
*
* Implementations MUST raise an exception for ports outside the
* established TCP and UDP port ranges.
*
* A null value provided for the port is equivalent to removing the port
* information.
*
* @param null|int $port The port to use with the new instance; a null value
* removes the port information.
* @return self A new instance with the specified port.
* @throws \InvalidArgumentException for invalid ports.
*/
public function withPort($port)
{
$port = $this->filterPort($port);
$clone = clone $this;
$clone->port = $port;
return $clone;
}
/**
* Does this Uri use a standard port?
*
* @return bool
*/
protected function hasStandardPort()
{
return ($this->scheme === 'http' && $this->port === 80) || ($this->scheme === 'https' && $this->port === 443);
}
/**
* Filter Uri port.
*
* @param null|int $port The Uri port number.
* @return null|int
*
* @throws InvalidArgumentException If the port is invalid.
*/
protected function filterPort($port)
{
if (is_null($port) || (is_integer($port) && ($port >= 1 && $port <= 65535))) {
return $port;
}
throw new InvalidArgumentException('Uri port must be null or an integer between 1 and 65535 (inclusive)');
}
/********************************************************************************
* Path
*******************************************************************************/
/**
* Retrieve the path component of the URI.
*
* The path can either be empty or absolute (starting with a slash) or
* rootless (not starting with a slash). Implementations MUST support all
* three syntaxes.
*
* Normally, the empty path "" and absolute path "/" are considered equal as
* defined in RFC 7230 Section 2.7.3. But this method MUST NOT automatically
* do this normalization because in contexts with a trimmed base path, e.g.
* the front controller, this difference becomes significant. It's the task
* of the user to handle both "" and "/".
*
* The value returned MUST be percent-encoded, but MUST NOT double-encode
* any characters. To determine what characters to encode, please refer to
* RFC 3986, Sections 2 and 3.3.
*
* As an example, if the value should include a slash ("/") not intended as
* delimiter between path segments, that value MUST be passed in encoded
* form (e.g., "%2F") to the instance.
*
* @see https://tools.ietf.org/html/rfc3986#section-2
* @see https://tools.ietf.org/html/rfc3986#section-3.3
* @return string The URI path.
*/
public function getPath()
{
return $this->path;
}
/**
* Return an instance with the specified path.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified path.
*
* The path can either be empty or absolute (starting with a slash) or
* rootless (not starting with a slash). Implementations MUST support all
* three syntaxes.
*
* If the path is intended to be domain-relative rather than path relative then
* it must begin with a slash ("/"). Paths not starting with a slash ("/")
* are assumed to be relative to some base path known to the application or
* consumer.
*
* Users can provide both encoded and decoded path characters.
* Implementations ensure the correct encoding as outlined in getPath().
*
* @param string $path The path to use with the new instance.
* @return self A new instance with the specified path.
* @throws \InvalidArgumentException for invalid paths.
*/
public function withPath($path)
{
if (!is_string($path)) {
throw new InvalidArgumentException('Uri path must be a string');
}
$clone = clone $this;
$clone->path = $this->filterPath($path);
// if the path is absolute, then clear basePath
if (substr($path, 0, 1) == '/') {
$clone->basePath = '';
}
return $clone;
}
/**
* Retrieve the base path segment of the URI.
*
* Note: This method is not part of the PSR-7 standard.
*
* This method MUST return a string; if no path is present it MUST return
* an empty string.
*
* @return string The base path segment of the URI.
*/
public function getBasePath()
{
return $this->basePath;
}
/**
* Set base path.
*
* Note: This method is not part of the PSR-7 standard.
*
* @param string $basePath
* @return self
*/
public function withBasePath($basePath)
{
if (!is_string($basePath)) {
throw new InvalidArgumentException('Uri path must be a string');
}
if (!empty($basePath)) {
$basePath = '/' . trim($basePath, '/'); // <-- Trim on both sides
}
$clone = clone $this;
if ($basePath !== '/') {
$clone->basePath = $this->filterPath($basePath);
}
return $clone;
}
/**
* Filter Uri path.
*
* This method percent-encodes all reserved
* characters in the provided path string. This method
* will NOT double-encode characters that are already
* percent-encoded.
*
* @param string $path The raw uri path.
* @return string The RFC 3986 percent-encoded uri path.
* @link http://www.faqs.org/rfcs/rfc3986.html
*/
protected function filterPath($path)
{
return preg_replace_callback(
'/(?:[^a-zA-Z0-9_\-\.~:@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/',
function ($match) {
return rawurlencode($match[0]);
},
$path
);
}
/********************************************************************************
* Query
*******************************************************************************/
/**
* Retrieve the query string of the URI.
*
* If no query string is present, this method MUST return an empty string.
*
* The leading "?" character is not part of the query and MUST NOT be
* added.
*
* The value returned MUST be percent-encoded, but MUST NOT double-encode
* any characters. To determine what characters to encode, please refer to
* RFC 3986, Sections 2 and 3.4.
*
* As an example, if a value in a key/value pair of the query string should
* include an ampersand ("&") not intended as a delimiter between values,
* that value MUST be passed in encoded form (e.g., "%26") to the instance.
*
* @see https://tools.ietf.org/html/rfc3986#section-2
* @see https://tools.ietf.org/html/rfc3986#section-3.4
* @return string The URI query string.
*/
public function getQuery()
{
return $this->query;
}
/**
* Return an instance with the specified query string.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified query string.
*
* Users can provide both encoded and decoded query characters.
* Implementations ensure the correct encoding as outlined in getQuery().
*
* An empty query string value is equivalent to removing the query string.
*
* @param string $query The query string to use with the new instance.
* @return self A new instance with the specified query string.
* @throws \InvalidArgumentException for invalid query strings.
*/
public function withQuery($query)
{
if (!is_string($query) && !method_exists($query, '__toString')) {
throw new InvalidArgumentException('Uri query must be a string');
}
$query = ltrim((string)$query, '?');
$clone = clone $this;
$clone->query = $this->filterQuery($query);
return $clone;
}
/**
* Filters the query string or fragment of a URI.
*
* @param string $query The raw uri query string.
* @return string The percent-encoded query string.
*/
protected function filterQuery($query)
{
return preg_replace_callback(
'/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/',
function ($match) {
return rawurlencode($match[0]);
},
$query
);
}
/********************************************************************************
* Fragment
*******************************************************************************/
/**
* Retrieve the fragment component of the URI.
*
* If no fragment is present, this method MUST return an empty string.
*
* The leading "#" character is not part of the fragment and MUST NOT be
* added.
*
* The value returned MUST be percent-encoded, but MUST NOT double-encode
* any characters. To determine what characters to encode, please refer to
* RFC 3986, Sections 2 and 3.5.
*
* @see https://tools.ietf.org/html/rfc3986#section-2
* @see https://tools.ietf.org/html/rfc3986#section-3.5
* @return string The URI fragment.
*/
public function getFragment()
{
return $this->fragment;
}
/**
* Return an instance with the specified URI fragment.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified URI fragment.
*
* Users can provide both encoded and decoded fragment characters.
* Implementations ensure the correct encoding as outlined in getFragment().
*
* An empty fragment value is equivalent to removing the fragment.
*
* @param string $fragment The fragment to use with the new instance.
* @return self A new instance with the specified fragment.
*/
public function withFragment($fragment)
{
if (!is_string($fragment) && !method_exists($fragment, '__toString')) {
throw new InvalidArgumentException('Uri fragment must be a string');
}
$fragment = ltrim((string)$fragment, '#');
$clone = clone $this;
$clone->fragment = $this->filterQuery($fragment);
return $clone;
}
/********************************************************************************
* Helpers
*******************************************************************************/
/**
* Return the string representation as a URI reference.
*
* Depending on which components of the URI are present, the resulting
* string is either a full URI or relative reference according to RFC 3986,
* Section 4.1. The method concatenates the various components of the URI,
* using the appropriate delimiters:
*
* - If a scheme is present, it MUST be suffixed by ":".
* - If an authority is present, it MUST be prefixed by "//".
* - The path can be concatenated without delimiters. But there are two
* cases where the path has to be adjusted to make the URI reference
* valid as PHP does not allow to throw an exception in __toString():
* - If the path is rootless and an authority is present, the path MUST
* be prefixed by "/".
* - If the path is starting with more than one "/" and no authority is
* present, the starting slashes MUST be reduced to one.
* - If a query is present, it MUST be prefixed by "?".
* - If a fragment is present, it MUST be prefixed by "#".
*
* @see http://tools.ietf.org/html/rfc3986#section-4.1
* @return string
*/
public function __toString()
{
$scheme = $this->getScheme();
$authority = $this->getAuthority();
$basePath = $this->getBasePath();
$path = $this->getPath();
$query = $this->getQuery();
$fragment = $this->getFragment();
$path = $basePath . '/' . ltrim($path, '/');
return ($scheme ? $scheme . ':' : '')
. ($authority ? '//' . $authority : '')
. $path
. ($query ? '?' . $query : '')
. ($fragment ? '#' . $fragment : '');
}
/**
* Return the fully qualified base URL.
*
* Note that this method never includes a trailing /
*
* This method is not part of PSR-7.
*
* @return string
*/
public function getBaseUrl()
{
$scheme = $this->getScheme();
$authority = $this->getAuthority();
$basePath = $this->getBasePath();
if ($authority && substr($basePath, 0, 1) !== '/') {
$basePath = $basePath . '/' . $basePath;
}
return ($scheme ? $scheme . ':' : '')
. ($authority ? '//' . $authority : '')
. rtrim($basePath, '/');
}
}

View file

@ -0,0 +1,27 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Interfaces;
/**
* Resolves a callable.
*
* @package Slim
* @since 3.0.0
*/
interface CallableResolverInterface
{
/**
* Invoke the resolved callable.
*
* @param mixed $toResolve
*
* @return callable
*/
public function resolve($toResolve);
}

View file

@ -0,0 +1,32 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Interfaces;
/**
* Collection Interface
*
* @package Slim
* @since 3.0.0
*/
interface CollectionInterface extends \ArrayAccess, \Countable, \IteratorAggregate
{
public function set($key, $value);
public function get($key, $default = null);
public function replace(array $items);
public function all();
public function has($key);
public function remove($key);
public function clear();
}

View file

@ -0,0 +1,23 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Interfaces\Http;
/**
* Cookies Interface
*
* @package Slim
* @since 3.0.0
*/
interface CookiesInterface
{
public function get($name, $default = null);
public function set($name, $value);
public function toHeaders();
public static function parseHeader($header);
}

View file

@ -0,0 +1,20 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Interfaces\Http;
/**
* Environment Interface
*
* @package Slim
* @since 3.0.0
*/
interface EnvironmentInterface
{
public static function mock(array $settings = []);
}

View file

@ -0,0 +1,24 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Interfaces\Http;
use Slim\Interfaces\CollectionInterface;
/**
* Headers Interface
*
* @package Slim
* @since 3.0.0
*/
interface HeadersInterface extends CollectionInterface
{
public function add($key, $value);
public function normalizeKey($key);
}

View file

@ -0,0 +1,35 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Interfaces;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
/**
* Defines a contract for invoking a route callable.
*/
interface InvocationStrategyInterface
{
/**
* Invoke a route callable.
*
* @param callable $callable The callable to invoke using the strategy.
* @param ServerRequestInterface $request The request object.
* @param ResponseInterface $response The response object.
* @param array $routeArguments The route's placholder arguments
*
* @return ResponseInterface|string The response from the callable.
*/
public function __invoke(
callable $callable,
ServerRequestInterface $request,
ResponseInterface $response,
array $routeArguments
);
}

View file

@ -0,0 +1,46 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Interfaces;
use Slim\App;
/**
* RouteGroup Interface
*
* @package Slim
* @since 3.0.0
*/
interface RouteGroupInterface
{
/**
* Get route pattern
*
* @return string
*/
public function getPattern();
/**
* Prepend middleware to the group middleware collection
*
* @param callable|string $callable The callback routine
*
* @return RouteGroupInterface
*/
public function add($callable);
/**
* Execute route group callable in the context of the Slim App
*
* This method invokes the route group object's callable, collecting
* nested route objects
*
* @param App $app
*/
public function __invoke(App $app);
}

View file

@ -0,0 +1,129 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Interfaces;
use InvalidArgumentException;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
/**
* Route Interface
*
* @package Slim
* @since 3.0.0
*/
interface RouteInterface
{
/**
* Retrieve a specific route argument
*
* @param string $name
* @param mixed $default
*
* @return mixed
*/
public function getArgument($name, $default = null);
/**
* Get route arguments
*
* @return array
*/
public function getArguments();
/**
* Get route name
*
* @return null|string
*/
public function getName();
/**
* Get route pattern
*
* @return string
*/
public function getPattern();
/**
* Set a route argument
*
* @param string $name
* @param string $value
*
* @return static
*/
public function setArgument($name, $value);
/**
* Replace route arguments
*
* @param array $arguments
*
* @return static
*/
public function setArguments(array $arguments);
/**
* Set route name
*
* @param string $name
*
* @return static
* @throws InvalidArgumentException if the route name is not a string
*/
public function setName($name);
/**
* Add middleware
*
* This method prepends new middleware to the route's middleware stack.
*
* @param callable|string $callable The callback routine
*
* @return RouteInterface
*/
public function add($callable);
/**
* Prepare the route for use
*
* @param ServerRequestInterface $request
* @param array $arguments
*/
public function prepare(ServerRequestInterface $request, array $arguments);
/**
* Run route
*
* This method traverses the middleware stack, including the route's callable
* and captures the resultant HTTP response object. It then sends the response
* back to the Application.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function run(ServerRequestInterface $request, ResponseInterface $response);
/**
* Dispatch route callable against current Request and Response objects
*
* This method invokes the route object's callable. If middleware is
* registered for the route, each callable middleware is invoked in
* the order specified.
*
* @param ServerRequestInterface $request The current Request object
* @param ResponseInterface $response The current Response object
*
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response);
}

View file

@ -0,0 +1,107 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim\Interfaces;
use RuntimeException;
use InvalidArgumentException;
use Psr\Http\Message\ServerRequestInterface;
/**
* Router Interface
*
* @package Slim
* @since 3.0.0
*/
interface RouterInterface
{
/**
* Add route
*
* @param string[] $methods Array of HTTP methods
* @param string $pattern The route pattern
* @param callable $handler The route callable
*
* @return RouteInterface
*/
public function map($methods, $pattern, $handler);
/**
* Dispatch router for HTTP request
*
* @param ServerRequestInterface $request The current HTTP request object
*
* @return array
*
* @link https://github.com/nikic/FastRoute/blob/master/src/Dispatcher.php
*/
public function dispatch(ServerRequestInterface $request);
/**
* Add a route group to the array
*
* @param string $pattern The group pattern
* @param callable $callable A group callable
*
* @return RouteGroupInterface
*/
public function pushGroup($pattern, $callable);
/**
* Removes the last route group from the array
*
* @return bool True if successful, else False
*/
public function popGroup();
/**
* Get named route object
*
* @param string $name Route name
*
* @return \Slim\Interfaces\RouteInterface
*
* @throws RuntimeException If named route does not exist
*/
public function getNamedRoute($name);
/**
* @param $identifier
*
* @return \Slim\Interfaces\RouteInterface
*/
public function lookupRoute($identifier);
/**
* Build the path for a named route excluding the base path
*
* @param string $name Route name
* @param array $data Named argument replacement data
* @param array $queryParams Optional query string parameters
*
* @return string
*
* @throws RuntimeException If named route does not exist
* @throws InvalidArgumentException If required data not provided
*/
public function relativePathFor($name, array $data = [], array $queryParams = []);
/**
* Build the path for a named route including the base path
*
* @param string $name Route name
* @param array $data Named argument replacement data
* @param array $queryParams Optional query string parameters
*
* @return string
*
* @throws RuntimeException If named route does not exist
* @throws InvalidArgumentException If required data not provided
*/
public function pathFor($name, array $data = [], array $queryParams = []);
}

View file

@ -0,0 +1,120 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim;
use RuntimeException;
use SplStack;
use SplDoublyLinkedList;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use UnexpectedValueException;
/**
* Middleware
*
* This is an internal class that enables concentric middleware layers. This
* class is an implementation detail and is used only inside of the Slim
* application; it is not visible to—and should not be used by—end users.
*/
trait MiddlewareAwareTrait
{
/**
* Middleware call stack
*
* @var \SplStack
* @link http://php.net/manual/class.splstack.php
*/
protected $stack;
/**
* Middleware stack lock
*
* @var bool
*/
protected $middlewareLock = false;
/**
* Add middleware
*
* This method prepends new middleware to the application middleware stack.
*
* @param callable $callable Any callable that accepts three arguments:
* 1. A Request object
* 2. A Response object
* 3. A "next" middleware callable
* @return static
*
* @throws RuntimeException If middleware is added while the stack is dequeuing
* @throws UnexpectedValueException If the middleware doesn't return a Psr\Http\Message\ResponseInterface
*/
protected function addMiddleware(callable $callable)
{
if ($this->middlewareLock) {
throw new RuntimeException('Middleware cant be added once the stack is dequeuing');
}
if (is_null($this->stack)) {
$this->seedMiddlewareStack();
}
$next = $this->stack->top();
$this->stack[] = function (ServerRequestInterface $req, ResponseInterface $res) use ($callable, $next) {
$result = call_user_func($callable, $req, $res, $next);
if ($result instanceof ResponseInterface === false) {
throw new UnexpectedValueException(
'Middleware must return instance of \Psr\Http\Message\ResponseInterface'
);
}
return $result;
};
return $this;
}
/**
* Seed middleware stack with first callable
*
* @param callable $kernel The last item to run as middleware
*
* @throws RuntimeException if the stack is seeded more than once
*/
protected function seedMiddlewareStack(callable $kernel = null)
{
if (!is_null($this->stack)) {
throw new RuntimeException('MiddlewareStack can only be seeded once.');
}
if ($kernel === null) {
$kernel = $this;
}
$this->stack = new SplStack;
$this->stack->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP);
$this->stack[] = $kernel;
}
/**
* Call middleware stack
*
* @param ServerRequestInterface $req A request object
* @param ResponseInterface $res A response object
*
* @return ResponseInterface
*/
public function callMiddlewareStack(ServerRequestInterface $req, ResponseInterface $res)
{
if (is_null($this->stack)) {
$this->seedMiddlewareStack();
}
/** @var callable $start */
$start = $this->stack->top();
$this->middlewareLock = true;
$resp = $start($req, $res);
$this->middlewareLock = false;
return $resp;
}
}

96
vendor/slim/slim/Slim/Routable.php vendored Normal file
View file

@ -0,0 +1,96 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim;
use Interop\Container\ContainerInterface;
/**
* A routable, middleware-aware object
*
* @package Slim
* @since 3.0.0
*/
abstract class Routable
{
use CallableResolverAwareTrait;
/**
* Route callable
*
* @var callable
*/
protected $callable;
/**
* Container
*
* @var ContainerInterface
*/
protected $container;
/**
* Route middleware
*
* @var callable[]
*/
protected $middleware = [];
/**
* Route pattern
*
* @var string
*/
protected $pattern;
/**
* Get the middleware registered for the group
*
* @return callable[]
*/
public function getMiddleware()
{
return $this->middleware;
}
/**
* Get the route pattern
*
* @return string
*/
public function getPattern()
{
return $this->pattern;
}
/**
* Set container for use with resolveCallable
*
* @param ContainerInterface $container
*
* @return self
*/
public function setContainer(ContainerInterface $container)
{
$this->container = $container;
return $this;
}
/**
* Prepend middleware to the middleware collection
*
* @param callable|string $callable The callback routine
*
* @return static
*/
public function add($callable)
{
$this->middleware[] = new DeferredCallable($callable, $this->container);
return $this;
}
}

357
vendor/slim/slim/Slim/Route.php vendored Normal file
View file

@ -0,0 +1,357 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim;
use Exception;
use InvalidArgumentException;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Slim\Handlers\Strategies\RequestResponse;
use Slim\Interfaces\InvocationStrategyInterface;
use Slim\Interfaces\RouteInterface;
/**
* Route
*/
class Route extends Routable implements RouteInterface
{
use MiddlewareAwareTrait;
/**
* HTTP methods supported by this route
*
* @var string[]
*/
protected $methods = [];
/**
* Route identifier
*
* @var string
*/
protected $identifier;
/**
* Route name
*
* @var null|string
*/
protected $name;
/**
* Parent route groups
*
* @var RouteGroup[]
*/
protected $groups;
private $finalized = false;
/**
* Output buffering mode
*
* One of: false, 'prepend' or 'append'
*
* @var boolean|string
*/
protected $outputBuffering = 'append';
/**
* Route parameters
*
* @var array
*/
protected $arguments = [];
/**
* Create new route
*
* @param string[] $methods The route HTTP methods
* @param string $pattern The route pattern
* @param callable $callable The route callable
* @param int $identifier The route identifier
* @param RouteGroup[] $groups The parent route groups
*/
public function __construct($methods, $pattern, $callable, $groups = [], $identifier = 0)
{
$this->methods = $methods;
$this->pattern = $pattern;
$this->callable = $callable;
$this->groups = $groups;
$this->identifier = 'route' . $identifier;
}
/**
* Finalize the route in preparation for dispatching
*/
public function finalize()
{
if ($this->finalized) {
return;
}
$groupMiddleware = [];
foreach ($this->getGroups() as $group) {
$groupMiddleware = array_merge($group->getMiddleware(), $groupMiddleware);
}
$this->middleware = array_merge($this->middleware, $groupMiddleware);
foreach ($this->getMiddleware() as $middleware) {
$this->addMiddleware($middleware);
}
$this->finalized = true;
}
/**
* Get route callable
*
* @return callable
*/
public function getCallable()
{
return $this->callable;
}
/**
* Get route methods
*
* @return string[]
*/
public function getMethods()
{
return $this->methods;
}
/**
* Get parent route groups
*
* @return RouteGroup[]
*/
public function getGroups()
{
return $this->groups;
}
/**
* Get route name
*
* @return null|string
*/
public function getName()
{
return $this->name;
}
/**
* Get route identifier
*
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Get output buffering mode
*
* @return boolean|string
*/
public function getOutputBuffering()
{
return $this->outputBuffering;
}
/**
* Set output buffering mode
*
* One of: false, 'prepend' or 'append'
*
* @param boolean|string $mode
*
* @throws InvalidArgumentException If an unknown buffering mode is specified
*/
public function setOutputBuffering($mode)
{
if (!in_array($mode, [false, 'prepend', 'append'], true)) {
throw new InvalidArgumentException('Unknown output buffering mode');
}
$this->outputBuffering = $mode;
}
/**
* Set route name
*
* @param string $name
*
* @return self
*
* @throws InvalidArgumentException if the route name is not a string
*/
public function setName($name)
{
if (!is_string($name)) {
throw new InvalidArgumentException('Route name must be a string');
}
$this->name = $name;
return $this;
}
/**
* Set a route argument
*
* @param string $name
* @param string $value
*
* @return self
*/
public function setArgument($name, $value)
{
$this->arguments[$name] = $value;
return $this;
}
/**
* Replace route arguments
*
* @param array $arguments
*
* @return self
*/
public function setArguments(array $arguments)
{
$this->arguments = $arguments;
return $this;
}
/**
* Retrieve route arguments
*
* @return array
*/
public function getArguments()
{
return $this->arguments;
}
/**
* Retrieve a specific route argument
*
* @param string $name
* @param mixed $default
*
* @return mixed
*/
public function getArgument($name, $default = null)
{
if (array_key_exists($name, $this->arguments)) {
return $this->arguments[$name];
}
return $default;
}
/********************************************************************************
* Route Runner
*******************************************************************************/
/**
* Prepare the route for use
*
* @param ServerRequestInterface $request
* @param array $arguments
*/
public function prepare(ServerRequestInterface $request, array $arguments)
{
// Add the arguments
foreach ($arguments as $k => $v) {
$this->setArgument($k, $v);
}
}
/**
* Run route
*
* This method traverses the middleware stack, including the route's callable
* and captures the resultant HTTP response object. It then sends the response
* back to the Application.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
*
* @return ResponseInterface
*/
public function run(ServerRequestInterface $request, ResponseInterface $response)
{
// Finalise route now that we are about to run it
$this->finalize();
// Traverse middleware stack and fetch updated response
return $this->callMiddlewareStack($request, $response);
}
/**
* Dispatch route callable against current Request and Response objects
*
* This method invokes the route object's callable. If middleware is
* registered for the route, each callable middleware is invoked in
* the order specified.
*
* @param ServerRequestInterface $request The current Request object
* @param ResponseInterface $response The current Response object
* @return \Psr\Http\Message\ResponseInterface
* @throws \Exception if the route callable throws an exception
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
{
$this->callable = $this->resolveCallable($this->callable);
/** @var InvocationStrategyInterface $handler */
$handler = isset($this->container) ? $this->container->get('foundHandler') : new RequestResponse();
// invoke route callable
if ($this->outputBuffering === false) {
$newResponse = $handler($this->callable, $request, $response, $this->arguments);
} else {
try {
ob_start();
$newResponse = $handler($this->callable, $request, $response, $this->arguments);
$output = ob_get_clean();
} catch (Exception $e) {
ob_end_clean();
throw $e;
}
}
if ($newResponse instanceof ResponseInterface) {
// if route callback returns a ResponseInterface, then use it
$response = $newResponse;
} elseif (is_string($newResponse)) {
// if route callback returns a string, then append it to the response
if ($response->getBody()->isWritable()) {
$response->getBody()->write($newResponse);
}
}
if (!empty($output) && $response->getBody()->isWritable()) {
if ($this->outputBuffering === 'prepend') {
// prepend output buffer content
$body = new Http\Body(fopen('php://temp', 'r+'));
$body->write($output . $response->getBody());
$response = $response->withBody($body);
} elseif ($this->outputBuffering === 'append') {
// append output buffer content
$response->getBody()->write($output);
}
}
return $response;
}
}

47
vendor/slim/slim/Slim/RouteGroup.php vendored Normal file
View file

@ -0,0 +1,47 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim;
use Closure;
use Slim\Interfaces\RouteGroupInterface;
/**
* A collector for Routable objects with a common middleware stack
*
* @package Slim
*/
class RouteGroup extends Routable implements RouteGroupInterface
{
/**
* Create a new RouteGroup
*
* @param string $pattern The pattern prefix for the group
* @param callable $callable The group callable
*/
public function __construct($pattern, $callable)
{
$this->pattern = $pattern;
$this->callable = $callable;
}
/**
* Invoke the group to register any Routable objects within it.
*
* @param App $app The App to bind the callable to.
*/
public function __invoke(App $app = null)
{
$callable = $this->resolveCallable($this->callable);
if ($callable instanceof Closure && $app !== null) {
$callable = $callable->bindTo($app);
}
$callable();
}
}

361
vendor/slim/slim/Slim/Router.php vendored Normal file
View file

@ -0,0 +1,361 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2016 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
*/
namespace Slim;
use FastRoute\Dispatcher;
use InvalidArgumentException;
use RuntimeException;
use Psr\Http\Message\ServerRequestInterface;
use FastRoute\RouteCollector;
use FastRoute\RouteParser;
use FastRoute\RouteParser\Std as StdParser;
use FastRoute\DataGenerator;
use Slim\Interfaces\RouteGroupInterface;
use Slim\Interfaces\RouterInterface;
use Slim\Interfaces\RouteInterface;
/**
* Router
*
* This class organizes Slim application route objects. It is responsible
* for registering route objects, assigning names to route objects,
* finding routes that match the current HTTP request, and creating
* URLs for a named route.
*/
class Router implements RouterInterface
{
/**
* Parser
*
* @var \FastRoute\RouteParser
*/
protected $routeParser;
/**
* Base path used in pathFor()
*
* @var string
*/
protected $basePath = '';
/**
* Routes
*
* @var Route[]
*/
protected $routes = [];
/**
* Route counter incrementer
* @var int
*/
protected $routeCounter = 0;
/**
* Route groups
*
* @var RouteGroup[]
*/
protected $routeGroups = [];
/**
* @var \FastRoute\Dispatcher
*/
protected $dispatcher;
/**
* Create new router
*
* @param RouteParser $parser
*/
public function __construct(RouteParser $parser = null)
{
$this->routeParser = $parser ?: new StdParser;
}
/**
* Set the base path used in pathFor()
*
* @param string $basePath
*
* @return self
*/
public function setBasePath($basePath)
{
if (!is_string($basePath)) {
throw new InvalidArgumentException('Router basePath must be a string');
}
$this->basePath = $basePath;
return $this;
}
/**
* Add route
*
* @param string[] $methods Array of HTTP methods
* @param string $pattern The route pattern
* @param callable $handler The route callable
*
* @return RouteInterface
*
* @throws InvalidArgumentException if the route pattern isn't a string
*/
public function map($methods, $pattern, $handler)
{
if (!is_string($pattern)) {
throw new InvalidArgumentException('Route pattern must be a string');
}
// Prepend parent group pattern(s)
if ($this->routeGroups) {
$pattern = $this->processGroups() . $pattern;
}
// According to RFC methods are defined in uppercase (See RFC 7231)
$methods = array_map("strtoupper", $methods);
// Add route
$route = new Route($methods, $pattern, $handler, $this->routeGroups, $this->routeCounter);
$this->routes[$route->getIdentifier()] = $route;
$this->routeCounter++;
return $route;
}
/**
* Dispatch router for HTTP request
*
* @param ServerRequestInterface $request The current HTTP request object
*
* @return array
*
* @link https://github.com/nikic/FastRoute/blob/master/src/Dispatcher.php
*/
public function dispatch(ServerRequestInterface $request)
{
$uri = '/' . ltrim($request->getUri()->getPath(), '/');
return $this->createDispatcher()->dispatch(
$request->getMethod(),
$uri
);
}
/**
* @return \FastRoute\Dispatcher
*/
protected function createDispatcher()
{
return $this->dispatcher ?: \FastRoute\simpleDispatcher(function (RouteCollector $r) {
foreach ($this->getRoutes() as $route) {
$r->addRoute($route->getMethods(), $route->getPattern(), $route->getIdentifier());
}
}, [
'routeParser' => $this->routeParser
]);
}
/**
* @param \FastRoute\Dispatcher $dispatcher
*/
public function setDispatcher(Dispatcher $dispatcher)
{
$this->dispatcher = $dispatcher;
}
/**
* Get route objects
*
* @return Route[]
*/
public function getRoutes()
{
return $this->routes;
}
/**
* Get named route object
*
* @param string $name Route name
*
* @return Route
*
* @throws RuntimeException If named route does not exist
*/
public function getNamedRoute($name)
{
foreach ($this->routes as $route) {
if ($name == $route->getName()) {
return $route;
}
}
throw new RuntimeException('Named route does not exist for name: ' . $name);
}
/**
* Process route groups
*
* @return string A group pattern to prefix routes with
*/
protected function processGroups()
{
$pattern = "";
foreach ($this->routeGroups as $group) {
$pattern .= $group->getPattern();
}
return $pattern;
}
/**
* Add a route group to the array
*
* @param string $pattern
* @param callable $callable
*
* @return RouteGroupInterface
*/
public function pushGroup($pattern, $callable)
{
$group = new RouteGroup($pattern, $callable);
array_push($this->routeGroups, $group);
return $group;
}
/**
* Removes the last route group from the array
*
* @return RouteGroup|bool The RouteGroup if successful, else False
*/
public function popGroup()
{
$group = array_pop($this->routeGroups);
return $group instanceof RouteGroup ? $group : false;
}
/**
* @param $identifier
* @return \Slim\Interfaces\RouteInterface
*/
public function lookupRoute($identifier)
{
if (!isset($this->routes[$identifier])) {
throw new RuntimeException('Route not found, looks like your route cache is stale.');
}
return $this->routes[$identifier];
}
/**
* Build the path for a named route excluding the base path
*
* @param string $name Route name
* @param array $data Named argument replacement data
* @param array $queryParams Optional query string parameters
*
* @return string
*
* @throws RuntimeException If named route does not exist
* @throws InvalidArgumentException If required data not provided
*/
public function relativePathFor($name, array $data = [], array $queryParams = [])
{
$route = $this->getNamedRoute($name);
$pattern = $route->getPattern();
$routeDatas = $this->routeParser->parse($pattern);
// $routeDatas is an array of all possible routes that can be made. There is
// one routedata for each optional parameter plus one for no optional parameters.
//
// The most specific is last, so we look for that first.
$routeDatas = array_reverse($routeDatas);
$segments = [];
foreach ($routeDatas as $routeData) {
foreach ($routeData as $item) {
if (is_string($item)) {
// this segment is a static string
$segments[] = $item;
continue;
}
// This segment has a parameter: first element is the name
if (!array_key_exists($item[0], $data)) {
// we don't have a data element for this segment: cancel
// testing this routeData item, so that we can try a less
// specific routeData item.
$segments = [];
$segmentName = $item[0];
break;
}
$segments[] = $data[$item[0]];
}
if (!empty($segments)) {
// we found all the parameters for this route data, no need to check
// less specific ones
break;
}
}
if (empty($segments)) {
throw new InvalidArgumentException('Missing data for URL segment: ' . $segmentName);
}
$url = implode('', $segments);
if ($queryParams) {
$url .= '?' . http_build_query($queryParams);
}
return $url;
}
/**
* Build the path for a named route including the base path
*
* @param string $name Route name
* @param array $data Named argument replacement data
* @param array $queryParams Optional query string parameters
*
* @return string
*
* @throws RuntimeException If named route does not exist
* @throws InvalidArgumentException If required data not provided
*/
public function pathFor($name, array $data = [], array $queryParams = [])
{
$url = $this->relativePathFor($name, $data, $queryParams);
if ($this->basePath) {
$url = $this->basePath . $url;
}
return $url;
}
/**
* Build the path for a named route.
*
* This method is deprecated. Use pathFor() from now on.
*
* @param string $name Route name
* @param array $data Named argument replacement data
* @param array $queryParams Optional query string parameters
*
* @return string
*
* @throws RuntimeException If named route does not exist
* @throws InvalidArgumentException If required data not provided
*/
public function urlFor($name, array $data = [], array $queryParams = [])
{
trigger_error('urlFor() is deprecated. Use pathFor() instead.', E_USER_DEPRECATED);
return $this->pathFor($name, $data, $queryParams);
}
}

54
vendor/slim/slim/composer.json vendored Normal file
View file

@ -0,0 +1,54 @@
{
"name": "slim/slim",
"type": "library",
"description": "Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs",
"keywords": ["framework","micro","api","router"],
"homepage": "http://slimframework.com",
"license": "MIT",
"authors": [
{
"name": "Josh Lockhart",
"email": "hello@joshlockhart.com",
"homepage": "https://joshlockhart.com"
},
{
"name": "Andrew Smith",
"email": "a.smith@silentworks.co.uk",
"homepage": "http://silentworks.co.uk"
},
{
"name": "Rob Allen",
"email": "rob@akrabat.com",
"homepage": "http://akrabat.com"
},
{
"name": "Gabriel Manricks",
"email": "gmanricks@me.com",
"homepage": "http://gabrielmanricks.com"
}
],
"require": {
"php": ">=5.5.0",
"pimple/pimple": "^3.0",
"psr/http-message": "^1.0",
"nikic/fast-route": "^0.6",
"container-interop/container-interop": "^1.1"
},
"require-dev": {
"squizlabs/php_codesniffer": "^2.5",
"phpunit/phpunit": "^4.0"
},
"autoload": {
"psr-4": {
"Slim\\": "Slim"
}
},
"scripts": {
"test": [
"php vendor/bin/phpcs",
"php vendor/bin/phpunit"
],
"phpunit": "php vendor/bin/phpunit",
"phpcs": "php vendor/bin/phpcs"
}
}

12
vendor/slim/slim/example/.htaccess vendored Normal file
View file

@ -0,0 +1,12 @@
# Note: see https://httpd.apache.org/docs/current/howto/htaccess.html:
#
# "You should avoid using .htaccess files completely if you have access to
# httpd main server config file. Using .htaccess files slows down your Apache
# http server. Any directive that you can include in a .htaccess file is
# better set in a Directory block, as it will have the same effect with
# better performance."
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

45
vendor/slim/slim/example/index.php vendored Normal file
View file

@ -0,0 +1,45 @@
<?php
/**
* Step 1: Require the Slim Framework using Composer's autoloader
*
* If you are not using Composer, you need to load Slim Framework with your own
* PSR-4 autoloader.
*/
require 'vendor/autoload.php';
/**
* Step 2: Instantiate a Slim application
*
* This example instantiates a Slim application using
* its default settings. However, you will usually configure
* your Slim application now by passing an associative array
* of setting names and values into the application constructor.
*/
$app = new Slim\App();
/**
* Step 3: Define the Slim application routes
*
* Here we define several Slim application routes that respond
* to appropriate HTTP request methods. In this example, the second
* argument for `Slim::get`, `Slim::post`, `Slim::put`, `Slim::patch`, and `Slim::delete`
* is an anonymous function.
*/
$app->get('/', function ($request, $response, $args) {
$response->write("Welcome to Slim!");
return $response;
});
$app->get('/hello[/{name}]', function ($request, $response, $args) {
$response->write("Hello, " . $args['name']);
return $response;
})->setArgument('name', 'World!');
/**
* Step 4: Run the Slim application
*
* This method should be called last. This executes the Slim application
* and returns the HTTP response to the HTTP client.
*/
$app->run();