You are here

class ApacheUrlMatcher 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

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

@author Fabien Potencier <fabien@symfony.com> @author Arnaud Le Blanc <arnaud.lb@gmail.com>

Hierarchy

Expanded class hierarchy of ApacheUrlMatcher

Deprecated

since version 2.5, to be removed in 3.0. The performance gains are minimal and it's very hard to replicate the behavior of PHP implementation.

1 file declares its use of ApacheUrlMatcher
LegacyApacheUrlMatcherTest.php in vendor/symfony/routing/Tests/Matcher/LegacyApacheUrlMatcherTest.php

File

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

Namespace

Symfony\Component\Routing\Matcher
View source
class ApacheUrlMatcher extends UrlMatcher {

  /**
   * Tries to match a URL based on Apache mod_rewrite matching.
   *
   * Returns false if no route matches the URL.
   *
   * @param string $pathinfo The pathinfo to be parsed
   *
   * @return array An array of parameters
   *
   * @throws MethodNotAllowedException If the current method is not allowed
   */
  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);
    }
  }

  /**
   * Denormalizes an array of values.
   *
   * @param string[] $values
   *
   * @return array
   */
  private function denormalizeValues(array $values) {
    $normalizedValues = array();
    foreach ($values as $key => $value) {
      if (preg_match('~^(.*)\\[(\\d+)\\]$~', $key, $matches)) {
        if (!isset($normalizedValues[$matches[1]])) {
          $normalizedValues[$matches[1]] = array();
        }
        $normalizedValues[$matches[1]][(int) $matches[2]] = $value;
      }
      else {
        $normalizedValues[$key] = $value;
      }
    }
    return $normalizedValues;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ApacheUrlMatcher::denormalizeValues private function Denormalizes an array of values.
ApacheUrlMatcher::match public function Tries to match a URL based on Apache mod_rewrite matching. Overrides UrlMatcher::match
UrlMatcher::$allow protected property
UrlMatcher::$context protected property
UrlMatcher::$expressionLanguage protected property
UrlMatcher::$expressionLanguageProviders protected property
UrlMatcher::$request protected property
UrlMatcher::$routes protected property
UrlMatcher::addExpressionLanguageProvider public function
UrlMatcher::getAttributes protected function Returns an array of values to use as request attributes. 1
UrlMatcher::getContext public function Gets the request context. Overrides RequestContextAwareInterface::getContext
UrlMatcher::getExpressionLanguage protected function
UrlMatcher::handleRouteRequirements protected function Handles specific route requirements. 1
UrlMatcher::matchCollection protected function Tries to match a URL with a set of routes. 1
UrlMatcher::matchRequest public function Tries to match a request with a set of routes. Overrides RequestMatcherInterface::matchRequest
UrlMatcher::mergeDefaults protected function Get merged default parameters.
UrlMatcher::REQUIREMENT_MATCH constant
UrlMatcher::REQUIREMENT_MISMATCH constant
UrlMatcher::ROUTE_MATCH constant
UrlMatcher::setContext public function Sets the request context. Overrides RequestContextAwareInterface::setContext
UrlMatcher::__construct public function Constructor. 4