Override default implementation so that pattern
is properly trimmed before being persisted.

@param $route
@return Route
500812
function update($route) {
        $route->pattern = $this->parser->trimPath($route->pattern);
        return parent::update($route);
    }
579907
public function release($route)
    {
        //argument 1 must be a string
        Argument::i()->test(1, 'string');

        if ($this->valid($route)) {
            unset($this->route[strtolower($route)]);
        }

        return $this;
    }
869907
public static function compile(Route $route)
    {
        $staticPrefix = false;
        $variables = [];
        $pos = 0;
        $extractedRegexes = [];
        $defaults = [];

        // set correct static prefix
        $prefix = $route->getHost() == '' ? '' : $route->getHost() . '/';

        // route regex
        $routePatternObject = self::str($route->getPath())->trimLeft('/');

        // if path is empty
        // e.g. the path is empty if you are matching a start page
        if($routePatternObject->val()==''){
            return new CompiledRoute(false, false, [], [], false);
        }

        $routePattern = $prefix . $routePatternObject->val() . '$';

        // we append the regex to match the string from beginning only if the path starts with http or '/'
        if($routePatternObject->startsWith('http')) {
            $routePattern = '^' . $routePattern;
        }else if(self::str($route->getRealPath())->startsWith('/') && self::str($route->getRealPath())->length()>1){
            $routePattern = '^/' . $routePattern;
        }
        // set regex delimiters
        $routePattern = '#' . $routePattern . '#';

        // extract all variables
        preg_match_all('#\{\w+\}#', $route->getPath(), $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
        foreach ($matches as $m) {
            $var = substr($m[0][0], 1, -1);

            // get all the text before the variable
            if(!$staticPrefix) {
                $prefix = substr($route->getPath(), $pos, ($m[0][1] - $pos));
                $pos = $m[0][1] + strlen($m[0][0]);
                $precedingChar = strlen($prefix) > 0 ? substr($prefix, -1) : '';
                if(strlen($precedingChar) === 1 && strpos(self::SEPARATORS, $precedingChar) !== false) {
                    $staticPrefix .= substr($prefix, 0, -1);
                } else {
                    $staticPrefix .= $prefix;
                }
            }

            $regex = '[\w-]+';
            $default = false;
            if($route->hasOption($var)) {
                // pattern
                if($route->getOptions()[$var]->hasAttribute('Pattern')) {
                    $regex = $route->getOptions()[$var]->getAttribute('Pattern');
                }

                // default
                if($route->getOptions()[$var]->hasAttribute('Default')) {
                    $default = $route->getOptions()[$var]->getAttribute('Default');
                }
            }
            $extractedRegexes[$var] = $regex;
            $defaults['{' . $var . '}'] = $default;

            $variables[] = ['name' => $var];
            $routePattern = str_replace($m[0][0], '(' . $regex . ')', $routePattern);
        }

        // build the default route
        $defaultRoute = false;
        if(count($defaults) > 0) {
            $defaultRoute = str_replace(array_keys($defaults), array_values($defaults), $route->getPath());
        }

        return new CompiledRoute($staticPrefix, $routePattern, $variables, $extractedRegexes, $defaultRoute);
    }
150672
public function route($route, $prefix = null)
    {
        $this->route = substr($route, strlen($prefix));
        $parameters = [];

        // Go through predefined routes till a match is found
        foreach ($this->routeOrder as $routeName) {
            $routeDescription = $this->routes[$routeName];
            $parameters = $this->match($this->route, $routeDescription);
            if ($parameters !== false) {
                return [
                    'route' => $this->route,
                    'parameters' => $this->fillInDefaultParameters($routeDescription, $parameters),
                    'description' => $routeDescription
                ];
            }
        }
        return [
            'route' => $this->route,
            'parameters' => $parameters,
            'description' => $this->routes['default']
        ];
    }
390651
protected function addWhereClausesToRoute($route)
    {
        $route->where(array_merge(
            $this->patterns, $route->getAction()['where'] ?? []
        ));

        return $route;
    }
1307951
public static function factory($routes = array())
    {
        $router = new self();
        if (count($routes)) {
            $router->addRoutes($routes);
        }
        return $router;
    }
1016944
public function add(Route $route)
    {
        $this->routes[] = $route;

        $this->addLookups($route);

        return $route;
    }
246509
public function map(Route $route)
    {
        $this->routes[$route->init()->getRule()] = $route;

        return $this;
    }
1050404
public static function delete(Route $route)
    {
        $routeWithoutSlash = $route;
        $routeWithSlash = $route->getWithSlash();

        // exception_if(! check(self::$register[$routeWithoutSlash->getName()]), RouteNotFoundInRoutesRegisterException::class , $routeWithoutSlash);
        // exception_if(! check(self::$register[$routeWithSlash->getName()]), RouteNotFoundInRoutesRegisterException::class , $routeWithSlash);

        if (check(self::$register[$routeWithoutSlash->getName()])) {
            unset(self::$register[$routeWithoutSlash->getName()]);
        }

        if (check(self::$register[$routeWithSlash->getName()])) {
            unset(self::$register[$routeWithSlash->getName()]);
        }
    }
813851
public function route($route, $params = [])
    {
        $this->url(
            $this->container->make('url')->route($route, $params)
        );

        return $this;
    }
1163833
protected function substituteImplicitBindings(Route $route)
    {
        $parameters = $route->parameters();

        foreach ($this->signatureParameters($route) as $parameter) {
            $id    = $parameters[$parameter->name];
            $class = $parameter->getClass()->getName();

            if ($repository = $this->registry->getRepository($class)) {
                if ($parameter->getClass()->implementsInterface(UrlRoutable::class)) {
                    $name = call_user_func([$class, 'getRouteKeyName']);

                    $entity = $repository->findOneBy([
                        $name => $id
                    ]);
                } else {
                    $entity = $repository->find($id);
                }

                if (is_null($entity) && !$parameter->isDefaultValueAvailable()) {
                    throw EntityNotFoundException::fromClassNameAndIdentifier($class, ['id' => $id]);
                }

                $route->setParameter($parameter->name, $entity);
            }
        }
    }
95874
protected function dispatchBodyClass(Route $route)
    {
        return function ($classes) use ($route) {
            if ($route->hasCondition()) {
                return $classes;
            }

            $tokens = array_filter(array_map(function ($token) use ($route) {
                switch ($type = $token[0]) {
                    case 'variable':
                        if (isset($token[3]) && $route->hasParameter($paramKey = $token[3])) {
                            $param = $route->parameter($paramKey);

                            return is_string($param) ? sprintf('%s-%s', $paramKey, sanitize_title($param)) : false;
                        }

                        return false;
                        break;
                    case 'text':
                        return sanitize_title($token[1]);
                        break;
                    default:
                        return false;
                }
            }, array_reverse($route->getCompiled()->getTokens())));

            if (! empty($tokens)) {
                return array_filter(array_merge($tokens, $classes), function ($class) {
                    return 'error404' !== $class;
                });
            }

            return $classes;
        };
    }
1230709
public function activateOnRoute(string $route)
    {
        $this->activeWhen = function () use ($route) {
            return str_contains(Route::currentRouteName(), $route);
        };

        return $this;
    }
789389
private function getReflectionMethodForRoute(Route $route)
    {
        $class = $this->extractClassFromRoute($route);
        $method = $this->extractFunctionFromRoute($route);

        if ($class !== null && $method !== null) {
            return new \ReflectionMethod($class, $method);
        }
        return null;
    }
1247296
protected function compile(&$route)
    {
        if ($route['regex']) {
            return $route;
        }

        $regex = preg_replace('#[.\+*?[^\]${}=!|:-]#', '\\\\$0', $route['pattern']);

        $regex = str_replace(array('(', ')'), array('(?:', ')?'), $regex);

        $regex = str_replace(array('<', '>'), array('(?P<', '>.+?)'), $regex);

        if ($route['rules']) {
            $search = $replace = array();
            foreach ($route['rules'] as $key => $rule) {
                $search[] = '<' . $key . '>.+?';
                $replace[] = '<' . $key . '>' . $rule;
            }
            $regex = str_replace($search, $replace, $regex);
        }

        $route['regex'] = '#^' . $regex . '$#uUD';

        return $route;
    }
884441
public function parse($route)
    {
        // reset param names
        $this->paramNames = [];

        // replace shortcuts
        $regex = strtr($route, $this->shortcuts);

        // replace param names that doesn't include shortcuts or regex
        $regex = preg_replace_callback('/{([a-zA-Z0-9]+)}/', [$this, 'replaceWithoutRegex'], $regex);

        // replace param names that includes shortcuts or regex
        $regex = preg_replace_callback('/{([a-zA-Z0-9]+):/', [$this, 'replaceWithRegex'], $regex);

        // replace ending grouping
        $regex = str_replace('}', ')', $regex);

        // fix slashes when optional params are present
        $regex = $this->fixOptionalSlashes($regex);

        // fix for handling trailing slashes
        $regex .= '(/)?';

        // return regex and param names
        return ['#^'. $regex .'$#', $this->paramNames];
    }
749322
public function dispatch(Route $route)
    {
        $callback = $route->getCallback();
        $params = array_values($route->getData());

        if ($callback instanceof Closure) {
            return $this->container->resolveClosure($callback, $params);
        }

        $class = $this->container->make($callback[0]);
        return $this->container->resolveMethod($class, $callback[1], $params);
    }