Maps a GET request to a callable.

@param string $pattern
@param callable $callback
@param array $requirements
@return $this
350998
public function get(string $pattern, $callback, array $requirements = [])
    {
        return $this->match($pattern, $callback, $requirements, [Request::METHOD_GET, Request::METHOD_HEAD]);
    }
1145178
public function options(string $pattern, $callback, array $requirements = [])
    {
        return $this->match($pattern, $callback, $requirements, [Request::METHOD_OPTIONS]);
    }
107529
public static function transpilePattern($pattern, $host = false, array $requirements = [], array $defaults = [])
    {
        $tokens = self::tokenizePattern($pattern, $host, $requirements, $defaults);

        $staticPath = !$tokens[0] instanceof Variable ? $tokens[0]->value : '/';

        $regex = self::transpileMatchRegex($tokens);

        return self::getCompact($staticPath, $regex, $tokens);
    }
508011
private function mapRoute(string $pattern, callable $callback)
    {
        $word = self::getPattern($pattern);

        $pattern = '/^' . str_replace('/', '\/', $word) . '$/';
        $this->routes[$pattern] = $callback;
    }
719234
protected function regexValidator($regex, $requirement)
    {
        $validator = $this->app->make(RegexValidator::class, [$regex]);
        $validator->setRequirementString(RegexValidator::E_DOES_NOT_MATCH, $requirement);
        $validator->setErrorString(RegexValidator::E_DOES_NOT_MATCH, $requirement);

        return $validator;
    }
808950
public function addPattern($name, $pattern)
    {
        if (!$this->hasPattern($name)) {
            $this->setPattern($name, $pattern);
        }

        return $this;
    }
470401
public function uriMatch($pattern, callable $handler)
    {
        if (preg_match($pattern, $this->getCleanUri(), $matches)) {
            return $handler($this->getCleanUri(), $matches);
        }
    }
1070740
public function addRoute($methods, $pattern, $handler, array $requirements = [], array $defaults = [])
    {
        list ($name, $host, $schemes, $constraints) = $this->parseRequirements(
            $this->extendRequirements($requirements),
            $methods
        );

        $route = new Route(
            $this->prefixPattern($pattern),
            $handler,
            is_array($methods) ? $methods : explode('|', $methods),
            $host,
            $defaults,
            $constraints,
            is_array($schemes) ? $schemes : explode('|', $schemes)
        );

        $this->routes->add($name, $route);
    }
810424
public function get($pattern, $handler, array $requirements = [], array $defaults = [])
    {
        $this->addRoute('GET', $pattern, $handler, $requirements, $defaults);
    }
915837
public static function tokenizePattern($pattern, $isHost = false, array $requirements = [], array $defaults = [])
    {
        // left pad pattern with separator
        if (!$isHost && false === self::isSeparator(substr($pattern, 0, 1))) {
            $pattern = '/'.$pattern;
        }

        list ($path, ) = $splt = array_pad(preg_split('#\{\w+\??\}#', $pattern), 1, '/');

        if (2 > count($splt)) {
            return [new Text($path)];
        }

        $separator = $isHost ? '.' : '/';
        $matchDel = join('|', array_map('preg_quote', str_split(Ps::SEPARATORS), str_split(
            str_repeat(Ps::EXP_DELIM, strlen(Ps::SEPARATORS))
        )));

        $expr = Ps::EXP_DELIM.sprintf(
            self::VAR_REGEXP,
            $matchDel,
            preg_quote(self::L_DELIM, Ps::EXP_DELIM),
            preg_quote(self::R_DELIM, Ps::EXP_DELIM)
        ).Ps::EXP_DELIM.'x';

        preg_match_all($expr, $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);

        $pos    = 0;
        $plen   = strlen($pattern);
        $nlen   = count($matches) - 1;
        $tokens = [];

        foreach ($matches as $i => $match) {
            // right hand delimiter, not always present
            $rdel = (!isset($match['rdel']) || -1 === $match['rdel'][1]) ? null : $match['rdel'];
            $ldel = -1 === $match['ldel'][1] ? null : $match['ldel'];
            $var  = -1 === $match['var'][1] ? null : $match['var'];
            $opt  = 0 === strcmp('?', substr($match[0][0], -2, 1));

            $default    = isset($defaults[$var[0]]) ? $defaults[$var[0]] : null;
            $constraint = isset($requirements[$var[0]]) ? $requirements[$var[0]] : null;

            $offset     = $match[0][1];

            // add preceeding text
            if (0 !== strlen($str = substr($pattern, $pos, $offset - $pos))) {
                $text = new Text($str, $lt = self::lastToken($tokens));
                self::pushTokens($text, $lt, $tokens);
            }

            // add left hand delimiter
            if (null !== $ldel) {
                $delim = new Delimiter($ldel[0], $lt = self::lastToken($tokens));
                self::pushTokens($delim, $lt, $tokens);
            }

            $opt = null === $default ? $opt : true;

            // add variable
            $tVar = new Variable($var[0], !$opt, $constraint, $lt = self::lastToken($tokens), null, $separator);
            self::pushTokens($tVar, $lt, $tokens);

            // add right hand delimiter
            if (null !== $rdel) {
                $delim = new Delimiter($rdel[0], $lt = self::lastToken($tokens));
                self::pushTokens($delim, $lt, $tokens);
            }

            // update current position
            $pos = $offset + strlen($match[0][0]);

            // add trailing text.
            if ($nlen === $i && $plen !== $pos) {
                $tail = substr($pattern, -($plen - $pos));

                if (0 !== strlen($tail)) {
                    $t = new Text($tail, $lt = self::lastToken($tokens));
                    self::pushTokens($t, $lt, $tokens);
                }
            }
        }

        return $tokens;
    }
879033
public function delete(string $pattern, callable $callback)
    {
        if ($this->requestMethod === "DELETE") {
            $this->mapRoute($pattern, $callback);
        }
    }
914804
public function group(string $pattern, $callable) : RouteGroupInterface
    {
        $router = $this->getRouter();
        $group  = $router->pushGroup($pattern, $callable);
        if (method_exists($group, 'setCallbackResolver')) {
            $callbackResolver = $this->getCallbackResolver();
            if ($callbackResolver instanceof CallbackResolverInterface) {
                $group->setCallbackResolver($callbackResolver);
            }
        }

        $group($this);
        $router->popGroup();
        return $group;
    }
468512
protected function write($pattern = null, ...$args)
    {
        if (!$this->hasOutput()) {
            return $this;
        }

        $this->getOutput()->write(vsprintf($pattern, $args));

        return $this;
    }
931204
public function uriNotMatch($pattern, callable $handler)
    {
        if (!preg_match($pattern, $this->getCleanUri(), $matches)) {
            return $handler($this->getCleanUri(), $matches);
        }
    }
317525
private function parseAnnotations($docBlock, $pattern, callable $callback)
    {
        $annotations = [];
        // Strip away the docblock header and footer to ease parsing of one line annotations
        $docBlock = substr($docBlock, 3, -2);

        if (preg_match_all($pattern, $docBlock, $matches) && is_callable($callback)) {
            return call_user_func($callback, $matches);
        }

        return $annotations;
    }
375336
public function setRequirements(array $requirements)
    {
        foreach ($requirements as $requirement => $type) {
            $this->addRequirement($requirement, $type);
        }

        return $this;
    }
112123
public function validate(string $name, string $pattern)
  {
    $this->currentContext->addPattern($name, $pattern);
    return $this;
  }