/**
  * {@inheritdoc}
  */
 public function mergeParameterKeys(SegmentMatcherContract $matcher)
 {
     if ($matcher->getHash() !== $this->getHash()) {
         throw new RuntimeException(sprintf('Cannot merge parameters: matchers must be equivalent, \'%s\' expected, \'%s\' given.', $matcher->getHash(), $this->getHash()));
     }
     $this->parameterKeys = array_unique(array_merge($this->parameterKeys, $matcher->getParameterKeys()), SORT_NUMERIC);
 }
 /**
  * Change matcher for a faster one, if available.
  *
  * @param \Viserio\Contracts\Routing\SegmentMatcher $matcher
  *
  * @return \Viserio\Contracts\Routing\SegmentMatcher
  */
 protected 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);
         }
     }
     return $matcher;
 }
 /**
  * @param \Viserio\Contracts\Routing\SegmentMatcher $matcher
  *
  * @return \Viserio\Routing\Generator\RouteTreeNode|null
  */
 public function getChild(SegmentMatcherContract $matcher)
 {
     return $this->children[$matcher->getHash()] ?? null;
 }