[map description]

@param [type] $uri    [description]
@param [type] $method [description]

@return [type] [description]
164363
public function map($uri, $method)
    {
        if ($uri === '/') {
            $uri = '';
        }

        $controller = $this;

        return $this->app->map(
            $this->baseUri.$uri,
            function () use ($controller, $method) {
                $params = func_get_args();
                $i = 0;
                $a = preg_replace_callback('/:(\w+)/', function($matches) use ($controller, $params, &$i) {
                    $value = @$params[$i++];
                    $controller->routeData($matches[1], $value);
                    return $value;
                }, $controller->baseUri);
                $controller->delegate($method, array_slice($params, $i));
            }
        );
    }
987905
public function dispatch($method, $uri)
    {
        $uri = $uri[0] !== '/' ? '/' . $uri : $uri;

        if (($result = $this->match($method, $uri)) !== null)
        {
            list($matches, $route) = (array) $result;

            $filtered = array_filter(array_keys($matches), 'is_string');

            $flipped = (array) array_flip($filtered);

            $values = array_intersect_key($matches, $flipped);

            $factory = new RouteFactory($route);

            return $factory->parameters($values)->make();
        }

        $error = sprintf('Route "%s %s" not found', $method, $uri);

        throw new \UnexpectedValueException($error);
    }
884176
public function createRequest($method, $uri)
    {
        if (is_string($uri)) {
            $uri = (new UriFactory())->createUri($uri);
        }
        return new Request($method, $uri);
    }
381374
private function checkMatches(string $uri, string $method): array
    {
        return array_map(
            function($regexp, $route) use ($uri, $method) {
                $match = preg_match_all($regexp, $uri, $matches);

                // If something found and method is correct
                if ($match && $route->checkMethod($method)) {
                    // Set array of variables
                    $route->setVariables($matches);
                    return $route;
                }
                return null;
            },
            // Array with keys
            $this->getRoutes(true),
            // Array with values
            $this->getRoutes()
        );
    }
534429
public function match($methods, $uri, $action = null)
    {
        return $this->router->match($methods, $uri, $this->compileAction($action));
    }
144034
private function jsonCall($method, $uri, $body = null)
    {
        $jsonBody = null;

        if (null !== $body) {
            $jsonBody = json_encode($body);
        }

        $request = new Request($method, $uri, ['Content-Type' => 'application/json'], $jsonBody);
        $response = $this->guzzle->send($request);
        $this->lastResponse = $response;

        self::checkResponse($response);

        return json_decode($response->getBody());
    }
1008075
public function map($method, $path, $handler)
    {
        $path = sprintf('/%s', ltrim($path, '/'));

        $route = (new Route)->setMethods((array) $method)
        ->setPath($path)->setCallable($handler);

        $this->routes[$path] = $route;

        return $route;
    }
624470
protected function query($uri, array $params = [], $method = self::METHOD_POST)
    {
        $request = new Request($method, $uri, [
            'Content-Type'  => 'application/json',
            'Authorization' => 'Token ' . $this->token,
            'X-Secret'      => $this->secret,
        ], 0 < count($params) ? json_encode($params) : null);

        $response = $this->httpClient->send($request, $this->httpOptions);

        $result = json_decode($response->getBody(), true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new RuntimeException('Error parsing response: ' . json_last_error_msg());
        }

        if (empty($result)) {
            throw new RuntimeException('Empty result');
        }

        return array_shift($result);
    }
1115360
public function addRoute($method, $uri, $action)
    {
        $uri = strtolower($uri);
        $action = $this->parseAction($action);

        if (isset($this->groupAttributes)) {
            if (isset($this->groupAttributes['prefix'])) {
                $uri = trim($this->groupAttributes['prefix'], '/').'/'.trim($uri, '/');
            }

            $action = $this->mergeGroupAttributes($action);
        }

        $uri = '/'.trim($uri, '/');

        if (isset($action['as'])) {
            $this->namedRoutes[$action['as']] = $uri;
        }

        $this->routes[$this->identifier] = ['method' => $method, 'uri' => $uri, 'action' => $action];
        $this->identifier++;

        return $this;
    }
207447
public function any($methods, $uri, $action = null)
    {
        return $this->addRoute(array_map('strtoupper', (array)$methods), $uri, $action);
    }
218825
private function request($method, $uri, $data = [])
    {
        $uri = $this->getUri($uri);

        $headers = [];

        // Basic Auth
        $credentials = $this->key.':'.$this->password;

        // User Agent
        $agent = sprintf("%s %s", Client::NAME, Client::VERSION);

        $ch = curl_init();

        if (strtoupper($method) === 'GET' && !empty($data)) {
            $queryString = http_build_query($data);
            $uri .= '?'.$queryString;
        }

        $options = [
            CURLOPT_URL => $uri,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HEADER => true,
            CURLOPT_USERAGENT => $agent,
            CURLOPT_USERPWD => $credentials,
            CURLOPT_TIMEOUT => 60,
        ];

        if (strtoupper($method) === 'POST') {
            $jsonData = json_encode($data);

            $headers[] = 'Content-Type: application/json';
            $headers[] = 'Content-Length: '.strlen($jsonData);

            $options[CURLOPT_CUSTOMREQUEST] = 'POST';
            $options[CURLOPT_POSTFIELDS] = $jsonData;
        }

        if (isset($this->version) && is_numeric($this->version)) {
            $headers[] = 'X-EWAY-APIVERSION: '.$this->version;
        }

        $options[CURLOPT_HTTPHEADER] = $headers;

        curl_setopt_array($ch, $options);

        $rawResponse = curl_exec($ch);

        $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);

        if (curl_errno($ch)) {
            $responseError = curl_error($ch);
            $responseBody = '';
        } else {
            $responseError = '';
            $responseBody = $this->parseResponse($rawResponse, $headerSize);
        }

        $response = new Response($statusCode, $responseBody, $responseError);

        curl_close($ch);

        return $response;
    }
893732
private function generateCacheKey($method, $uri, array $options = [])
    {
        return sha1(sprintf('%s.%s.%s.%s', get_class($this), $method, $uri, json_encode($options)));
    }
1101253
public function forward($uri, $method = Request::METHOD_GET)
    {
        if ('cli' === PHP_SAPI) {
            throw new BaseException('You can not call forward method in cli mode.');
        }

        $request = $this->getRequest()->withMethod($method);

        $this->getContainer()->setShared('request', $request);

        $oldRouter = $this->getRouter();

        $oldRequestUri = $_SERVER['REQUEST_URI'];
        $oldGetUrl = $_GET['_url'];
        $_GET['_url'] = $_SERVER['REQUEST_URI'] = $uri;
        $this->getContainer()->setShared('router', new Router());
        $this->getRouter()->setPrefix($oldRouter->getPrefix());
        $this->getRouter()->handle($uri);

        $dispatcher = new Dispatcher();
        $response = $dispatcher->setAction($this->getRouter()->getAction())
            ->setActionNamespace($this->getRouter()->getActionNamespace())
            ->setBundle($this->getRouter()->getBundle())
            ->setParams($this->getRouter()->getParams())
            ->setResponderNamespace($this->getRouter()->getResponderNamespace())
            ->setRouteMatched($this->getRouter()->isMatched())
            ->dispatch($request);

        // restore latest state
        $this->getContainer()->setShared('router', $oldRouter);
        $_SERVER['REQUEST_URI'] = $oldRequestUri;
        $_GET['_url'] = $oldGetUrl;

        return $response;
    }
712661
public function route($method, $uri)
    {
        // Remove subfolder from URI if needed
        $baseDir = $this->get('___.baseDir');
        if ("/" !== $baseDir && 0 === strpos($uri, $baseDir)) {
            $uri = substr($uri, strlen($baseDir));
        }

        // Check which route is being used.
        $routings = $this->routings;
        $this->dispatcher = $this->dispatcher ?: \FastRoute\simpleDispatcher(function(\FastRoute\RouteCollector $r) use ($routings) {
            foreach ($routings as $name => $routing) {
                // 'GET', '/user/{id:\d+}', $routeName
                $r->addRoute($routing[0], $routing[1], $name);
            }
        });

        $routeInfo = $this->dispatcher->dispatch($method, $uri);

        if (\FastRoute\Dispatcher::FOUND === $routeInfo[0]) {
            return array_slice($routeInfo, 1);
        }

        return null;
    }
277892
public function requestAsync($method, $uri = null, array $options = [])
    {
        $options = $this->setRequestOptions($options);

        $query = parse_url($uri, PHP_URL_QUERY);
        if (!empty($query)) {
            $uri = substr($uri, 0, (strlen($query)+1) * -1);
            parse_str($query, $options['query']);
        }

        return parent::requestAsync($method, $uri, $options);
    }
913464
public static function createRequest(string $method, $uri): RequestInterface
    {
        if (\is_string($uri)) {
            $uri = Uri::createFromString($uri);
        }

        return new Request($method, $uri);
    }
1320552
protected function filterRequest($uri, $method)
    {
        if (!empty($filtersPattern = $this->filter[$uri][$method])) {

            $filters = explode('|', $filtersPattern);

            foreach ($filters as $filter) {

                list($className, $params) = $this->getClassNameWithParams($filter);

                $name = app()->getNamespace() . 'Filters\\' . $className;

                $instance = $this->container->make($name);

                $filterResponse = call_user_func_array([$instance, 'handle'], $params);

                if(!$filterResponse instanceof Request) {
                    return $filterResponse;
                }
            }
        }
    }