private static function optimizeMatcher(SegmentMatcherContract $matcher): SegmentMatcherContract
    {
        if ($matcher instanceof RegexMatcher && $matcher->getGroupCount() === 1) {
            $parameterKeys = $matcher->getParameterKeys();

            switch ($matcher->getRegex()) {
                case '/^(' . Pattern::ANY . ')$/':
                    return new AnyMatcher($parameterKeys);
                case '/^(' . Pattern::DIGITS . ')$/':
                    return new ExpressionMatcher('ctype_digit({segment})', $parameterKeys);
                case '/^(' . Pattern::ALPHA . ')$/':
                    return new ExpressionMatcher('ctype_alpha({segment})', $parameterKeys);
                case '/^(' . Pattern::ALPHA_LOWER . ')$/':
                    return new ExpressionMatcher('ctype_lower({segment})', $parameterKeys);
                case '/^(' . Pattern::ALPHA_UPPER . ')$/':
                    return new ExpressionMatcher('ctype_upper({segment})', $parameterKeys);
                case '/^(' . Pattern::ALPHA_NUM . ')$/':
                    return new ExpressionMatcher('ctype_alnum({segment})', $parameterKeys);
                case '/^(' . Pattern::ALPHA_NUM_DASH . ')$/':
                    return new ExpressionMatcher('ctype_alnum(str_replace(\'-\', \'\', {segment}))', $parameterKeys);

                default:
                    return $matcher;
            }
        }

        return $matcher;
    }
private static function optimizeMatcher(SegmentMatcherContract $matcher): SegmentMatcherContract
    {
        if ($matcher instanceof RegexMatcher && $matcher->getGroupCount() === 1) {
            $parameterKeys = $matcher->getParameterKeys();

            switch ($matcher->getRegex()) {
                case '/^(' . Pattern::ANY . ')$/':
                    return new AnyMatcher($parameterKeys);
                case '/^(' . Pattern::DIGITS . ')$/':
                    return new ExpressionMatcher('ctype_digit({segment})', $parameterKeys);
                case '/^(' . Pattern::ALPHA . ')$/':
                    return new ExpressionMatcher('ctype_alpha({segment})', $parameterKeys);
                case '/^(' . Pattern::ALPHA_LOWER . ')$/':
                    return new ExpressionMatcher('ctype_lower({segment})', $parameterKeys);
                case '/^(' . Pattern::ALPHA_UPPER . ')$/':
                    return new ExpressionMatcher('ctype_upper({segment})', $parameterKeys);
                case '/^(' . Pattern::ALPHA_NUM . ')$/':
                    return new ExpressionMatcher('ctype_alnum({segment})', $parameterKeys);
                case '/^(' . Pattern::ALPHA_NUM_DASH . ')$/':
                    return new ExpressionMatcher('ctype_alnum(str_replace(\'-\', \'\', {segment}))', $parameterKeys);

                default:
                    return $matcher;
            }
        }

        return $matcher;
    }
private static function optimizeMatcher ( SegmentMatcherContract $ matcher ) : SegmentMatcherContract { if ( $ matcher instanceof RegexMatcher && $ matcher -> getGroupCount ( ) === 1 ) { $ parameterKeys = $ matcher -> getParameterKeys ( ) ; switch ( $ matcher -> getRegex ( ) ) { case '/^(' . Pattern :: ANY . ')$/' : return new AnyMatcher ( $ parameterKeys ) ; case '/^(' . Pattern :: DIGITS . ')$/' : return new ExpressionMatcher ( 'ctype_digit({segment})' , $ parameterKeys ) ; case '/^(' . Pattern :: ALPHA . ')$/' : return new ExpressionMatcher ( 'ctype_alpha({segment})' , $ parameterKeys ) ; case '/^(' . Pattern :: ALPHA_LOWER . ')$/' : return new ExpressionMatcher ( 'ctype_lower({segment})' , $ parameterKeys ) ; case '/^(' . Pattern :: ALPHA_UPPER . ')$/' : return new ExpressionMatcher ( 'ctype_upper({segment})' , $ parameterKeys ) ; case '/^(' . Pattern :: ALPHA_NUM . ')$/' : return new ExpressionMatcher ( 'ctype_alnum({segment})' , $ parameterKeys ) ; case '/^(' . Pattern :: ALPHA_NUM_DASH . ')$/' : return new ExpressionMatcher ( 'ctype_alnum(str_replace(\'-\', \'\', {segment}))' , $ parameterKeys ) ; default : return $ matcher ; } } return $ matcher ; }
Change matcher for a faster one, if available.

@param \Viserio\Component\Contract\Routing\SegmentMatcher $matcher

@return \Viserio\Component\Contract\Routing\SegmentMatcher
Change matcher for a faster one if available .