context = $context; $this->defaults = $defaults; } public function match($pathinfo) { $allow = array(); // foo if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?Pbaz|symfony)$#x', $pathinfo, $matches)) { return array_merge($this->mergeDefaults($matches, array ( 'def' => 'test',)), array('_route' => 'foo')); } // bar if (0 === strpos($pathinfo, '/bar') && preg_match('#^/bar/(?P[^/\.]+?)$#x', $pathinfo, $matches)) { if (isset($this->context['method']) && !in_array(strtolower($this->context['method']), array('get', 'head'))) { $allow = array_merge($allow, array('get', 'head')); goto not_bar; } $matches['_route'] = 'bar'; return $matches; } not_bar: // baz if ($pathinfo === '/test/baz') { return array('_route' => 'baz'); } // baz2 if ($pathinfo === '/test/baz.html') { return array('_route' => 'baz2'); } // baz3 if (rtrim($pathinfo, '/') === '/test/baz3') { if (substr($pathinfo, -1) !== '/') { return $this->redirect($pathinfo.'/', 'baz3'); } return array('_route' => 'baz3'); } // baz4 if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/?$#x', $pathinfo, $matches)) { if (substr($pathinfo, -1) !== '/') { return $this->redirect($pathinfo.'/', 'baz4'); } $matches['_route'] = 'baz4'; return $matches; } // baz5 if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/?$#x', $pathinfo, $matches)) { if (isset($this->context['method']) && !in_array(strtolower($this->context['method']), array('post'))) { $allow = array_merge($allow, array('post')); goto not_baz5; } if (substr($pathinfo, -1) !== '/') { return $this->redirect($pathinfo.'/', 'baz5'); } $matches['_route'] = 'baz5'; return $matches; } not_baz5: // baz.baz6 if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/?$#x', $pathinfo, $matches)) { if (isset($this->context['method']) && !in_array(strtolower($this->context['method']), array('put'))) { $allow = array_merge($allow, array('put')); goto not_bazbaz6; } if (substr($pathinfo, -1) !== '/') { return $this->redirect($pathinfo.'/', 'baz.baz6'); } $matches['_route'] = 'baz.baz6'; return $matches; } not_bazbaz6: // foofoo if ($pathinfo === '/foofoo') { return array ( 'def' => 'test', '_route' => 'foofoo',); } throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new NotFoundException(); } }