You are here

public function ApacheUrlMatcher::match in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/routing/Matcher/ApacheUrlMatcher.php \Symfony\Component\Routing\Matcher\ApacheUrlMatcher::match()

Tries to match a URL based on Apache mod_rewrite matching.

Returns false if no route matches the URL.

Parameters

string $pathinfo The pathinfo to be parsed:

Return value

array An array of parameters

Throws

MethodNotAllowedException If the current method is not allowed

Overrides UrlMatcher::match

File

vendor/symfony/routing/Matcher/ApacheUrlMatcher.php, line 41

Class

ApacheUrlMatcher
ApacheUrlMatcher matches URL based on Apache mod_rewrite matching (see ApacheMatcherDumper).

Namespace

Symfony\Component\Routing\Matcher

Code

public function match($pathinfo) {
  $parameters = array();
  $defaults = array();
  $allow = array();
  $route = null;
  foreach ($this
    ->denormalizeValues($_SERVER) as $key => $value) {
    $name = $key;

    // skip non-routing variables
    // this improves performance when $_SERVER contains many usual
    // variables like HTTP_*, DOCUMENT_ROOT, REQUEST_URI, ...
    if (false === strpos($name, '_ROUTING_')) {
      continue;
    }
    while (0 === strpos($name, 'REDIRECT_')) {
      $name = substr($name, 9);
    }

    // expect _ROUTING_<type>_<name>
    // or _ROUTING_<type>
    if (0 !== strpos($name, '_ROUTING_')) {
      continue;
    }
    if (false !== ($pos = strpos($name, '_', 9))) {
      $type = substr($name, 9, $pos - 9);
      $name = substr($name, $pos + 1);
    }
    else {
      $type = substr($name, 9);
    }
    if ('param' === $type) {
      if ('' !== $value) {
        $parameters[$name] = $value;
      }
    }
    elseif ('default' === $type) {
      $defaults[$name] = $value;
    }
    elseif ('route' === $type) {
      $route = $value;
    }
    elseif ('allow' === $type) {
      $allow[] = $name;
    }
    unset($_SERVER[$key]);
  }
  if (null !== $route) {
    $parameters['_route'] = $route;
    return $this
      ->mergeDefaults($parameters, $defaults);
  }
  elseif (0 < count($allow)) {
    throw new MethodNotAllowedException($allow);
  }
  else {
    return parent::match($pathinfo);
  }
}