123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace Symfony\Component\Routing\Matcher;
- @trigger_error('The '.__NAMESPACE__.'\ApacheUrlMatcher class is deprecated since Symfony 2.5 and will be removed in 3.0. It\'s hard to replicate the behaviour of the PHP implementation and the performance gains are minimal.', E_USER_DEPRECATED);
- use Symfony\Component\Routing\Exception\MethodNotAllowedException;
- class ApacheUrlMatcher extends UrlMatcher
- {
-
- public function match($pathinfo)
- {
- $parameters = array();
- $defaults = array();
- $allow = array();
- $route = null;
- foreach ($this->denormalizeValues($_SERVER) as $key => $value) {
- $name = $key;
-
-
-
- if (false === strpos($name, '_ROUTING_')) {
- continue;
- }
- while (0 === strpos($name, 'REDIRECT_')) {
- $name = substr($name, 9);
- }
-
-
- 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);
- }
- }
-
- 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;
- }
- }
|