Server IP : 213.176.29.180  /  Your IP : 18.118.208.127
Web Server : Apache
System : Linux 213.176.29.180.hostiran.name 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
User : webtaragh ( 1001)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0750) :  /home/webtaragh/public_html/wp-includes/../

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/webtaragh/public_html/wp-includes/../middlewares.tar
utils/CONTRIBUTING.md000064400000006407147361032760010155 0ustar00# Contributing Guide

This project adheres to [The Code Manifesto](http://codemanifesto.com) as its guidelines for contributor interactions.

## The Code Manifesto

We want to work in an ecosystem that empowers developers to reach their potential--one that encourages growth and effective collaboration. A space that is safe for all.

A space such as this benefits everyone that participates in it. It encourages new developers to enter our field. It is through discussion and collaboration that we grow, and through growth that we improve.

In the effort to create such a place, we hold to these values:

1. **Discrimination limits us.** This includes discrimination on the basis of race, gender, sexual orientation, gender identity, age, nationality, technology and any other arbitrary exclusion of a group of people.
2. **Boundaries honor us.** Your comfort levels are not everyone’s comfort levels. Remember that, and if brought to your attention, heed it.
3. **We are our biggest assets.** None of us were born masters of our trade. Each of us has been helped along the way. Return that favor, when and where you can.
4. **We are resources for the future.** As an extension of #3, share what you know. Make yourself a resource to help those that come after you.
5. **Respect defines us.** Treat others as you wish to be treated. Make your discussions, criticisms and debates from a position of respectfulness. Ask yourself, is it true? Is it necessary? Is it constructive? Anything less is unacceptable.
6. **Reactions require grace.** Angry responses are valid, but abusive language and vindictive actions are toxic. When something happens that offends you, handle it assertively, but be respectful. Escalate reasonably, and try to allow the offender an opportunity to explain themselves, and possibly correct the issue.
7. **Opinions are just that: opinions.** Each and every one of us, due to our background and upbringing, have varying opinions. That is perfectly acceptable. Remember this: if you respect your own opinions, you should respect the opinions of others.
8. **To err is human.** You might not intend it, but mistakes do happen and contribute to build experience. Tolerate honest mistakes, and don't hesitate to apologize if you make one yourself.

## How to contribute

This is a collaborative effort. We welcome all contributions submitted as pull requests.

(Contributions on wording & style are also welcome.)

### Bugs

A bug is a demonstrable problem that is caused by the code in the repository. Good bug reports are extremely helpful – thank you!

Please try to be as detailed as possible in your report. Include specific information about the environment – version of PHP, etc, and steps required to reproduce the issue.

### Pull Requests

Good pull requests – patches, improvements, new features – are a fantastic help. Before create a pull request, please follow these instructions:

* The code must follow the [PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md). Run `composer cs-fix` to fix your code before commit.
* Write tests
* Document any change in `README.md` and `CHANGELOG.md`
* One pull request per feature. If you want to do more than one thing, send multiple pull request

### Runing tests

```sh
composer test
```
utils/phpcs.xml000064400000000524147361032760007555 0ustar00<?xml version="1.0"?>
<ruleset name="Middlewares coding standard">
    <description>Middlewares coding standard</description>

    <!-- display progress -->
    <arg value="p"/>
    <arg name="colors"/>

    <!-- coding standard -->
    <rule ref="PSR2"/>

    <!-- Paths to check -->
    <file>src</file>
    <file>tests</file>
</ruleset>
utils/src/CallableMiddleware.php000064400000001626147361032760012717 0ustar00<?php

namespace Middlewares\Utils;

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Interop\Http\ServerMiddleware\DelegateInterface;

class CallableMiddleware implements MiddlewareInterface
{
    /**
     * @var callable
     */
    private $handler;

    /**
     * Constructor.
     *
     * @param callable $handler
     */
    public function __construct(callable $handler)
    {
        $this->handler = $handler;
    }

    /**
     * Process a server request and return a response.
     *
     * @param ServerRequestInterface $request
     * @param DelegateInterface      $delegate
     *
     * @return ResponseInterface
     */
    public function process(ServerRequestInterface $request, DelegateInterface $delegate)
    {
        return CallableHandler::execute($this->handler, [$request, $delegate]);
    }
}
utils/src/UriFactory.php000064400000001324147361032760011304 0ustar00<?php

namespace Middlewares\Utils;

use Interop\Http\Factory\UriFactoryInterface;

/**
 * Simple class to create instances of PSR-7 uri.
 */
class UriFactory implements UriFactoryInterface
{
    /**
     * {@inheritdoc}
     */
    public function createUri($uri = '')
    {
        if (class_exists('Zend\\Diactoros\\Uri')) {
            return new \Zend\Diactoros\Uri($uri);
        }

        if (class_exists('GuzzleHttp\\Psr7\\Uri')) {
            return new \GuzzleHttp\Psr7\Uri($uri);
        }

        if (class_exists('Slim\\Http\\Uri')) {
            return \Slim\Http\Uri::createFromString($uri);
        }

        throw new \RuntimeException('Unable to create an uri. No PSR-7 uri library detected');
    }
}
utils/src/CallableResolver/ContainerResolver.php000064400000001700147361032760016100 0ustar00<?php

namespace Middlewares\Utils\CallableResolver;

use Interop\Container\ContainerInterface;
use RuntimeException;

/**
 * Resolve a callable using a container.
 */
final class ContainerResolver extends Resolver
{
    /**
     * @var ContainerInterface
     */
    private $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function resolve($callable, array $args = [])
    {
        if (is_string($callable)) {
            $callable = $this->resolveString($callable);
        }

        if (is_string($callable)) {
            $callable = $this->container->get($callable);
        } elseif (is_array($callable) && is_string($callable[0])) {
            $callable[0] = $this->container->get($callable[0]);
        }

        if (is_callable($callable)) {
            return $callable;
        }

        throw new RuntimeException('Invalid callable provided');
    }
}
utils/src/CallableResolver/ReflectionResolver.php000064400000003157147361032760016260 0ustar00<?php

namespace Middlewares\Utils\CallableResolver;

use ReflectionClass;
use ReflectionMethod;
use RuntimeException;

/**
 * Resolve a callable using reflection.
 */
final class ReflectionResolver extends Resolver
{
    public function resolve($callable, array $args = [])
    {
        if (is_string($callable)) {
            $callable = $this->resolveString($callable);
        }

        if (is_string($callable)) {
            if (!function_exists($callable)) {
                $callable = $this->createClass($callable, $args);
            }
        } elseif (is_array($callable) && is_string($callable[0])) {
            list($class, $method) = $callable;

            $refMethod = new ReflectionMethod($class, $method);

            if (!$refMethod->isStatic()) {
                $class = $this->createClass($class, $args);

                $callable = [$class, $method];
            }
        }

        if (is_callable($callable)) {
            return $callable;
        }

        throw new RuntimeException('Invalid callable provided');
    }

    /**
     * Create a new class.
     *
     * @param string $class
     * @param array  $args
     *
     * @return object
     */
    private function createClass($class, $args = [])
    {
        if (!class_exists($class)) {
            throw new RuntimeException("The class {$class} does not exists");
        }

        $refClass = new ReflectionClass($class);

        if ($refClass->hasMethod('__construct')) {
            $instance = $refClass->newInstanceArgs($args);
        } else {
            $instance = $refClass->newInstance();
        }

        return $instance;
    }
}
utils/src/CallableResolver/CallableResolverInterface.php000064400000000660147361032760017502 0ustar00<?php

namespace Middlewares\Utils\CallableResolver;

use RuntimeException;

/**
 * Simple interface to resolve callableish values.
 */
interface CallableResolverInterface
{
    /**
     * Resolves a callable.
     *
     * @param mixed $callable
     * @param array $args
     *
     * @throws RuntimeException If it's not callable
     *
     * @return callable
     */
    public function resolve($callable, array $args = []);
}
utils/src/CallableResolver/Resolver.php000064400000001102147361032760014231 0ustar00<?php

namespace Middlewares\Utils\CallableResolver;

/**
 * Common logic for callable resolvers.
 */
abstract class Resolver implements CallableResolverInterface
{
    /**
     * Resolves a callable from a string.
     *
     * @param string $callable
     *
     * @return array|string
     */
    protected function resolveString($callable)
    {
        //ClassName/Service::method
        if (strpos($callable, '::') !== false) {
            list($id, $method) = explode('::', $callable, 2);

            return [$id, $method];
        }

        return $callable;
    }
}
utils/src/Delegate.php000064400000001326147361032760010731 0ustar00<?php

namespace Middlewares\Utils;

use Interop\Http\ServerMiddleware\DelegateInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

class Delegate implements DelegateInterface
{
    /**
     * @var callable
     */
    private $callback;

    /**
     * @param callable $callback function (RequestInterface $request) : ResponseInterface
     */
    public function __construct(callable $callback)
    {
        $this->callback = $callback;
    }

    /**
     * @param ServerRequestInterface $request
     *
     * @return ResponseInterface
     */
    public function process(ServerRequestInterface $request)
    {
        return call_user_func($this->callback, $request);
    }
}
utils/src/CallableHandler.php000064400000002333147361032760012213 0ustar00<?php

namespace Middlewares\Utils;

use Psr\Http\Message\ResponseInterface;

/**
 * Simple class to execute callables and returns responses.
 */
abstract class CallableHandler
{
    /**
     * Execute the callable.
     *
     * @param callable $callable
     * @param array    $arguments
     *
     * @return ResponseInterface
     */
    public static function execute($callable, array $arguments = [])
    {
        ob_start();
        $level = ob_get_level();

        try {
            $return = call_user_func_array($callable, $arguments);

            if ($return instanceof ResponseInterface) {
                $response = $return;
                $return = '';
            } else {
                $response = Factory::createResponse();
            }

            while (ob_get_level() >= $level) {
                $return = ob_get_clean().$return;
            }

            $body = $response->getBody();

            if ($return !== '' && $body->isWritable()) {
                $body->write($return);
            }

            return $response;
        } catch (\Exception $exception) {
            while (ob_get_level() >= $level) {
                ob_end_clean();
            }

            throw $exception;
        }
    }
}
utils/src/Factory.php000064400000007032147361032760010626 0ustar00<?php

namespace Middlewares\Utils;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
use Interop\Http\Factory\ResponseFactoryInterface;
use Interop\Http\Factory\StreamFactoryInterface;
use Interop\Http\Factory\UriFactoryInterface;
use Interop\Http\Factory\ServerRequestFactoryInterface;

/**
 * Simple class to create instances of PSR-7 classes.
 */
abstract class Factory
{
    /**
     * @var ResponseFactoryInterface
     */
    private static $responseFactory;

    /**
     * @var StreamFactoryInterface
     */
    private static $streamFactory;

    /**
     * @var UriFactoryInterface
     */
    private static $uriFactory;

    /**
     * @var ServerRequestFactoryInterface
     */
    private static $serverRequestFactory;

    /**
     * Set a custom ResponseFactory.
     *
     * @param ResponseFactoryInterface $responseFactory
     */
    public static function setResponseFactory(ResponseFactoryInterface $responseFactory)
    {
        self::$responseFactory = $responseFactory;
    }

    /**
     * Set a custom StreamFactory.
     *
     * @param StreamFactoryInterface $streamFactory
     */
    public static function setStreamFactory(StreamFactoryInterface $streamFactory)
    {
        self::$streamFactory = $streamFactory;
    }

    /**
     * Set a custom UriFactory.
     *
     * @param UriFactoryInterface $uriFactory
     */
    public static function setUriFactory(UriFactoryInterface $uriFactory)
    {
        self::$uriFactory = $uriFactory;
    }

    /**
     * Set a custom ServerRequestFactory.
     *
     * @param ServerRequestFactoryInterface $serverRequestFactory
     */
    public static function setServerRequestFactory(ServerRequestFactoryInterface $serverRequestFactory)
    {
        self::$serverRequestFactory = $serverRequestFactory;
    }

    /**
     * Creates a Response instance.
     *
     * @param int $code The status code
     *
     * @return ResponseInterface
     */
    public static function createResponse($code = 200)
    {
        if (self::$responseFactory === null) {
            self::$responseFactory = new ResponseFactory();
        }

        return self::$responseFactory->createResponse($code);
    }

    /**
     * Creates a Stream instance.
     *
     * @param resource $resource A resource returned by fopen
     *
     * @return StreamInterface
     */
    public static function createStream($resource = null)
    {
        if (self::$streamFactory === null) {
            self::$streamFactory = new StreamFactory();
        }

        if ($resource === null) {
            return self::$streamFactory->createStream();
        }

        return self::$streamFactory->createStreamFromResource($resource);
    }

    /**
     * Creates an Uri instance.
     *
     * @param string $uri
     *
     * @return UriInterface
     */
    public static function createUri($uri = '')
    {
        if (self::$uriFactory === null) {
            self::$uriFactory = new UriFactory();
        }

        return self::$uriFactory->createUri($uri);
    }

    /**
     * Creates a ServerRequest instance.
     *
     * @param array  $server
     * @param string $method
     * @param string $uri
     *
     * @return ServerRequest
     */
    public static function createServerRequest(array $server = [], $method = 'GET', $uri = '/')
    {
        if (self::$serverRequestFactory === null) {
            self::$serverRequestFactory = new ServerRequestFactory();
        }

        return self::$serverRequestFactory->createServerRequest($server, $method, $uri);
    }
}
utils/src/ServerRequestFactory.php000064400000002502147361032760013363 0ustar00<?php

namespace Middlewares\Utils;

use Interop\Http\Factory\ServerRequestFactoryInterface;

/**
 * Simple class to create server request instances of PSR-7 classes.
 */
class ServerRequestFactory implements ServerRequestFactoryInterface
{
    /**
     * {@inheritdoc}
     */
    public function createServerRequest(array $server, $method = null, $uri = null)
    {
        if (class_exists('Zend\\Diactoros\\ServerRequest')) {
            return new \Zend\Diactoros\ServerRequest(
                $server,
                [],
                (string) $uri,
                $method,
                new \Zend\Diactoros\Stream(fopen('php://temp', 'r+'))
            );
        }

        if (class_exists('GuzzleHttp\\Psr7\\ServerRequest')) {
            return new \GuzzleHttp\Psr7\ServerRequest($method, (string) $uri, [], null, '1.1', $server);
        }

        if (class_exists('Slim\\Http\\Request')) {
            return new \Slim\Http\Request(
                $method,
                \Slim\Http\Uri::createFromString((string) $uri),
                new \Slim\Http\Headers(),
                [],
                $server,
                new \Slim\Http\Stream(fopen('php://temp', 'r+'))
            );
        }

        throw new \RuntimeException('Unable to create a server request. No PSR-7 server request library detected');
    }
}
utils/src/StreamFactory.php000064400000002234147361032760012001 0ustar00<?php

namespace Middlewares\Utils;

use Interop\Http\Factory\StreamFactoryInterface;

/**
 * Simple class to create instances of PSR-7 streams.
 */
class StreamFactory implements StreamFactoryInterface
{
    /**
     * {@inheritdoc}
     */
    public function createStream($content = '')
    {
        $stream = $this->createStreamFromFile('php://temp', 'r+');
        $stream->write($content);

        return $stream;
    }

    /**
     * {@inheritdoc}
     */
    public function createStreamFromFile($file, $mode = 'r')
    {
        return $this->createStreamFromResource(fopen($file, $mode));
    }

    /**
     * {@inheritdoc}
     */
    public function createStreamFromResource($resource)
    {
        if (class_exists('Zend\\Diactoros\\Stream')) {
            return new \Zend\Diactoros\Stream($resource);
        }

        if (class_exists('GuzzleHttp\\Psr7\\Stream')) {
            return new \GuzzleHttp\Psr7\Stream($resource);
        }

        if (class_exists('Slim\\Http\\Stream')) {
            return new \Slim\Http\Stream($resource);
        }

        throw new \RuntimeException('Unable to create a stream. No PSR-7 stream library detected');
    }
}
utils/src/ResponseFactory.php000064400000001441147361032760012343 0ustar00<?php

namespace Middlewares\Utils;

use Interop\Http\Factory\ResponseFactoryInterface;

/**
 * Simple class to create response instances of PSR-7 classes.
 */
class ResponseFactory implements ResponseFactoryInterface
{
    /**
     * {@inheritdoc}
     */
    public function createResponse($code = 200)
    {
        if (class_exists('Zend\\Diactoros\\Response')) {
            return new \Zend\Diactoros\Response('php://memory', $code);
        }

        if (class_exists('GuzzleHttp\\Psr7\\Response')) {
            return new \GuzzleHttp\Psr7\Response($code);
        }

        if (class_exists('Slim\\Http\\Response')) {
            return new \Slim\Http\Response($code);
        }

        throw new \RuntimeException('Unable to create a response. No PSR-7 stream library detected');
    }
}
utils/src/Dispatcher.php000064400000004140147361032760011302 0ustar00<?php

namespace Middlewares\Utils;

use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Closure;

class Dispatcher
{
    /**
     * @var MiddlewareInterface[]
     */
    private $stack;

    /**
     * Static helper to create and dispatch a request.
     *
     * @param MiddlewareInterface[]
     * @param ServerRequestInterface|null $request
     *
     * @return ResponseInterface
     */
    public static function run(array $stack, ServerRequestInterface $request = null)
    {
        if ($request === null) {
            $request = Factory::createServerRequest();
        }

        return (new static($stack))->dispatch($request);
    }

    /**
     * @param MiddlewareInterface[] $stack middleware stack (with at least one middleware component)
     */
    public function __construct(array $stack)
    {
        assert(count($stack) > 0);

        $this->stack = $stack;
    }

    /**
     * Dispatches the middleware stack and returns the resulting `ResponseInterface`.
     *
     * @param ServerRequestInterface $request
     *
     * @return ResponseInterface
     */
    public function dispatch(ServerRequestInterface $request)
    {
        $resolved = $this->resolve(0);

        return $resolved->process($request);
    }

    /**
     * @param int $index middleware stack index
     *
     * @return DelegateInterface
     */
    private function resolve($index)
    {
        return new Delegate(function (ServerRequestInterface $request) use ($index) {
            $middleware = isset($this->stack[$index]) ? $this->stack[$index] : new CallableMiddleware(function () {
            });

            if ($middleware instanceof Closure) {
                $middleware = new CallableMiddleware($middleware);
            }

            assert($middleware instanceof MiddlewareInterface);

            $result = $middleware->process($request, $this->resolve($index + 1));

            assert($result instanceof ResponseInterface);

            return $result;
        });
    }
}
utils/README.md000064400000007614147361032760007204 0ustar00# middlewares/utils

[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE)
[![Build Status][ico-travis]][link-travis]
[![Quality Score][ico-scrutinizer]][link-scrutinizer]
[![Total Downloads][ico-downloads]][link-downloads]
[![SensioLabs Insight][ico-sensiolabs]][link-sensiolabs]

Common utilities used by the middlewares' packages:

## Factory

Used to create psr-7 instances of `ServerRequestInterface`, `ResponseInterface`, `StreamInterface` and `UriInterface`. Detects automatically [Diactoros](https://github.com/zendframework/zend-diactoros), [Guzzle](https://github.com/guzzle/psr7) and [Slim](https://github.com/slimphp/Slim) but you can register a different factory using the [http-interop/http-factory](https://github.com/http-interop/http-factory) interface.

```php
use Middlewares\Utils\Factory;

$request = Factory::createServerRequest();
$response = Factory::createResponse();
$stream = Factory::createStream();
$uri = Factory::createUri('http://example.com');

//Register other factory
Factory::setResponseFactory(new FooResponseFactory());

$fooResponse = Factory::createResponse();
```

## CallableHandler

To execute a callable and return a response with the output. Useful to handle routes, etc:

```php
use Middlewares\Utils\CallableHandler;

$response = CallableHandler::execute(function () {
    echo 'Hello world';
});

echo $response->getBody(); //Hello world
```

## Dispatcher

Minimalist PSR-15 compatible dispatcher. Used for testing purposes.

```php
use Middlewares\Utils\Factory;
use Middlewares\Utils\Dispatcher;

$dispatcher = new Dispatcher([
    new Middleware1(),
    new Middleware2(),
    new Middleware3(),
    function ($request, $next) {
        $response = $next->process($request);
        return $response->withHeader('X-Foo', 'Bar');
    }
]);

$response = $dispatcher->dispatch(Factory::createServerRequest());
```

## CallableMiddleware

A simple way to create middlewares using callables. Internally uses [CallableHandler](#callablehandler) so you can use `echo` or return `string` in the callables (the response is created automatically if it's not returned).
**Note:** You may not need use this directly in the `Dispatcher`, because is used automatically with instances of `Closure`.

```php
use Middlewares\Utils\Dispatcher;
use Middlewares\Utils\CallableMiddleware;

$dispatcher = new Dispatcher([
    new CallableMiddleware(function ($request, $delegate) {
        $response = $delegate->process($request);

        return $response->withHeader('Content-Type', 'text/html');
    }),
    //Providing a Closure directly, the dispatcher will convert to a CallableMiddleware automatically
    function ($request, $delegate) {
        echo '<h1>Hello world</h1>';
    }
]);

$response = $dispatcher->dispatch(new Request());
```
---

Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.

The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

[ico-version]: https://img.shields.io/packagist/v/middlewares/utils.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/middlewares/utils/master.svg?style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/g/middlewares/utils.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/middlewares/utils.svg?style=flat-square
[ico-sensiolabs]: https://img.shields.io/sensiolabs/i/3dcb2b7c-8564-48ef-9af4-d1e974762c3a.svg?style=flat-square

[link-packagist]: https://packagist.org/packages/middlewares/utils
[link-travis]: https://travis-ci.org/middlewares/utils
[link-scrutinizer]: https://scrutinizer-ci.com/g/middlewares/utils
[link-downloads]: https://packagist.org/packages/middlewares/utils
[link-sensiolabs]: https://insight.sensiolabs.com/projects/3dcb2b7c-8564-48ef-9af4-d1e974762c3a
utils/CHANGELOG.md000064400000003225147361032760007530 0ustar00# Change Log

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) 
and this project adheres to [Semantic Versioning](http://semver.org/).

## 0.9.0 - 2017-02-05

### Added

* Callable resolves to create callables from various representations

### Removed

* `Middlewares\Utils\CallableHandler::resolve`

## 0.8.0 - 2016-12-22

### Changed

* Updated `http-interop/http-middleware` to `0.4`
* Updated `friendsofphp/php-cs-fixer` to `2.0`

## 0.7.0 - 2016-12-06

### Added

* New static helper `Middlewares\Utils\Dispatcher::run` to create and dispatch a request easily

## 0.6.1 - 2016-12-06

### Fixed

* Ensure that the body of the serverRequest is writable and seekable. 

## 0.6.0 - 2016-12-06

### Added

* ServerRequest factory
* `Middlewares\Utils\Dispatcher` accepts `Closure` as middleware components

### Changed

* `Middlewares\Utils\Dispatcher` creates automatically a response if the stack is exhausted

## 0.5.0 - 2016-11-22

### Added

* `Middlewares\Utils\CallableMiddleware` class, to create middlewares from callables
* `Middlewares\Utils\Dispatcher` class, to execute the middleware stack and return a response.

## 0.4.0 - 2016-11-13

### Changed

* Updated `http-interop/http-factory` to `0.2`

## 0.3.1 - 2016-10-03

### Fixed

* Bug in CallableHandler that resolve to the declaring class of a method instead the final class.

## 0.3.0 - 2016-10-03

### Added

* `Middlewares\Utils\CallableHandler` class, allowing to resolve and execute callables safely.

## 0.2.0 - 2016-10-01

### Added

* Uri factory

## 0.1.0 - 2016-09-30

### Added

* Response factory
* Stream factory
utils/LICENSE000064400000002052147361032760006721 0ustar00The MIT License (MIT)

Copyright (c) 2016

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.
fast-route/CONTRIBUTING.md000064400000006407147361032760011106 0ustar00# Contributing Guide

This project adheres to [The Code Manifesto](http://codemanifesto.com) as its guidelines for contributor interactions.

## The Code Manifesto

We want to work in an ecosystem that empowers developers to reach their potential--one that encourages growth and effective collaboration. A space that is safe for all.

A space such as this benefits everyone that participates in it. It encourages new developers to enter our field. It is through discussion and collaboration that we grow, and through growth that we improve.

In the effort to create such a place, we hold to these values:

1. **Discrimination limits us.** This includes discrimination on the basis of race, gender, sexual orientation, gender identity, age, nationality, technology and any other arbitrary exclusion of a group of people.
2. **Boundaries honor us.** Your comfort levels are not everyone’s comfort levels. Remember that, and if brought to your attention, heed it.
3. **We are our biggest assets.** None of us were born masters of our trade. Each of us has been helped along the way. Return that favor, when and where you can.
4. **We are resources for the future.** As an extension of #3, share what you know. Make yourself a resource to help those that come after you.
5. **Respect defines us.** Treat others as you wish to be treated. Make your discussions, criticisms and debates from a position of respectfulness. Ask yourself, is it true? Is it necessary? Is it constructive? Anything less is unacceptable.
6. **Reactions require grace.** Angry responses are valid, but abusive language and vindictive actions are toxic. When something happens that offends you, handle it assertively, but be respectful. Escalate reasonably, and try to allow the offender an opportunity to explain themselves, and possibly correct the issue.
7. **Opinions are just that: opinions.** Each and every one of us, due to our background and upbringing, have varying opinions. That is perfectly acceptable. Remember this: if you respect your own opinions, you should respect the opinions of others.
8. **To err is human.** You might not intend it, but mistakes do happen and contribute to build experience. Tolerate honest mistakes, and don't hesitate to apologize if you make one yourself.

## How to contribute

This is a collaborative effort. We welcome all contributions submitted as pull requests.

(Contributions on wording & style are also welcome.)

### Bugs

A bug is a demonstrable problem that is caused by the code in the repository. Good bug reports are extremely helpful – thank you!

Please try to be as detailed as possible in your report. Include specific information about the environment – version of PHP, etc, and steps required to reproduce the issue.

### Pull Requests

Good pull requests – patches, improvements, new features – are a fantastic help. Before create a pull request, please follow these instructions:

* The code must follow the [PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md). Run `composer cs-fix` to fix your code before commit.
* Write tests
* Document any change in `README.md` and `CHANGELOG.md`
* One pull request per feature. If you want to do more than one thing, send multiple pull request

### Runing tests

```sh
composer test
```
fast-route/phpcs.xml000064400000000524147361032760010506 0ustar00<?xml version="1.0"?>
<ruleset name="Middlewares coding standard">
    <description>Middlewares coding standard</description>

    <!-- display progress -->
    <arg value="p"/>
    <arg name="colors"/>

    <!-- coding standard -->
    <rule ref="PSR2"/>

    <!-- Paths to check -->
    <file>src</file>
    <file>tests</file>
</ruleset>
fast-route/src/FastRoute.php000064400000005373147361032760012072 0ustar00<?php

namespace Middlewares;

use Middlewares\Utils\CallableResolver\CallableResolverInterface;
use Middlewares\Utils\CallableResolver\ContainerResolver;
use Middlewares\Utils\CallableResolver\ReflectionResolver;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Interop\Container\ContainerInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Interop\Http\ServerMiddleware\DelegateInterface;
use FastRoute\Dispatcher;

class FastRoute implements MiddlewareInterface
{
    /**
     * @var Dispatcher FastRoute dispatcher
     */
    private $router;

    /**
     * @var array Extra arguments passed to the controller
     */
    private $arguments = [];

    /**
     * @var CallableResolverInterface Used to resolve the controllers
     */
    private $resolver;

    /**
     * Set the Dispatcher instance.
     *
     * @param Dispatcher $router
     */
    public function __construct(Dispatcher $router)
    {
        $this->router = $router;
    }

    /**
     * Set the resolver used to create the controllers.
     *
     * @param ContainerInterface $container
     *
     * @return self
     */
    public function resolver(ContainerInterface $container)
    {
        $this->resolver = new ContainerResolver($container);

        return $this;
    }

    /**
     * Extra arguments passed to the callable.
     *
     * @return self
     */
    public function arguments()
    {
        $this->arguments = func_get_args();

        return $this;
    }

    /**
     * Process a server request and return a response.
     *
     * @param ServerRequestInterface $request
     * @param DelegateInterface      $delegate
     *
     * @return ResponseInterface
     */
    public function process(ServerRequestInterface $request, DelegateInterface $delegate)
    {
        $route = $this->router->dispatch($request->getMethod(), $request->getUri()->getPath());

        if ($route[0] === Dispatcher::NOT_FOUND) {
            return Utils\Factory::createResponse(404);
        }

        if ($route[0] === Dispatcher::METHOD_NOT_ALLOWED) {
            return Utils\Factory::createResponse(405);
        }

        foreach ($route[2] as $name => $value) {
            $request = $request->withAttribute($name, $value);
        }

        $arguments = array_merge([$request], $this->arguments);

        $callable = $this->getResolver()->resolve($route[1], $arguments);

        return Utils\CallableHandler::execute($callable, $arguments);
    }

    /**
     * Return the resolver used for the controllers
     *
     * @return CallableResolverInterface
     */
    private function getResolver()
    {
        if (!isset($this->resolver)) {
            $this->resolver = new ReflectionResolver();
        }

        return $this->resolver;
    }
}
fast-route/README.md000064400000010614147361032760010127 0ustar00# middlewares/fast-route

[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE)
[![Build Status][ico-travis]][link-travis]
[![Quality Score][ico-scrutinizer]][link-scrutinizer]
[![Total Downloads][ico-downloads]][link-downloads]
[![SensioLabs Insight][ico-sensiolabs]][link-sensiolabs]

Middleware to use [FastRoute](https://github.com/nikic/FastRoute).

## Requirements

* PHP >= 5.6
* A [PSR-7](https://packagist.org/providers/psr/http-message-implementation) http mesage implementation ([Diactoros](https://github.com/zendframework/zend-diactoros), [Guzzle](https://github.com/guzzle/psr7), [Slim](https://github.com/slimphp/Slim), etc...)
* A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)

## Installation

This package is installable and autoloadable via Composer as [middlewares/fast-route](https://packagist.org/packages/middlewares/fast-route).

```sh
composer require middlewares/fast-route
```

## Example

```php
//Create the router dispatcher
$dispatcher = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
    $r->addRoute('GET', '/hello/{name}', function ($request) {
        //The route parameters are stored as attributes
        $name = $request->getAttribute('name');

        //You can echo the output (it will be captured and writted into the body)
        echo sprintf('Hello %s', $name);

        //Or return a string
        return sprintf('Hello %s', $name);

        //Or return a response
        return new Response();
    });
});

$dispatcher = new Dispatcher([
    new Middlewares\FastRoute($dispatcher)
]);

$response = $dispatcher->dispatch(new ServerRequest('/hello/world'));
```

**fastRoute** allows to define anything as the router handler (a closure, callback, action object, controller class, etc). By default, it's interpreted in the following way:

* If it's a string similar to `Namespace\Class::method`, and the method is not static, create a instance of `Namespace\Class` and call the method.
* If the string is the name of a existing class (like: `Namespace\Class`) and contains the method `__invoke`, create a instance and execute that method.
* Otherwise, treat it as a callable.

If you want to change this behaviour, use a container implementing the [container-interop](https://github.com/container-interop/container-interop) to return the route callable.


## Options

#### `__construct(FastRoute\Dispatcher $dispatcher)`

The dispatcher instance to use.

#### `resolver(Interop\Container\ContainerInterface $resolver)`

To use a container implementing [container-interop](https://github.com/container-interop/container-interop) to resolve the route handlers.

#### `arguments(...$args)`

Extra arguments to pass to the controller. This is useful to inject, for example a service container:

```php
$dispatcher = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
    $r->addRoute('GET', '/posts/{id}', function ($request, $app) {
        $id = $request->getAttribute('id');
        $post = $app->get('database')->select($id);
        
        return $app->get('templates')->render($post);
    });
});

$dispatcher = new Dispatcher([
    (new Middlewares\FastRoute($dispatcher))
        ->arguments($app)
]);
```

---

Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.

The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

[ico-version]: https://img.shields.io/packagist/v/middlewares/fast-route.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/middlewares/fast-route/master.svg?style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/g/middlewares/fast-route.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/middlewares/fast-route.svg?style=flat-square
[ico-sensiolabs]: https://img.shields.io/sensiolabs/i/bb44398f-43ee-4a09-a60e-d5c9735fa0be.svg?style=flat-square

[link-packagist]: https://packagist.org/packages/middlewares/fast-route
[link-travis]: https://travis-ci.org/middlewares/fast-route
[link-scrutinizer]: https://scrutinizer-ci.com/g/middlewares/fast-route
[link-downloads]: https://packagist.org/packages/middlewares/fast-route
[link-sensiolabs]: https://insight.sensiolabs.com/projects/bb44398f-43ee-4a09-a60e-d5c9735fa0be
fast-route/CHANGELOG.md000064400000001130147361032760010452 0ustar00# Change Log
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) 
and this project adheres to [Semantic Versioning](http://semver.org/).

## 0.4.0 - 2017-02-05

## Changed

* Updated to `middlewares/utils#~0.9`
* Improved route target resolution

## 0.3.0 - 2016-12-26

### Changed

* Updated tests
* Updated to `http-interop/http-middleware#0.4`
* Updated `friendsofphp/php-cs-fixer#2.0`

## 0.2.0 - 2016-11-27

### Changed

* Updated to `http-interop/http-middleware#0.3`

## 0.1.0 - 2016-10-09

First version
fast-route/LICENSE000064400000002052147361032760007652 0ustar00The MIT License (MIT)

Copyright (c) 2017

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.