コード例 #1
0
ファイル: Fallbacks.php プロジェクト: Webapper/silex-xtr
 public function run()
 {
     $app = $this->xtr->getApplication();
     /** @var $matcher RedirectableUrlMatcher */
     $context = $app['request_context'];
     $matched = false;
     $path = $this->xtr->getRequest()->getPathInfo();
     $lastException = null;
     // matching fallback route groups:
     foreach ($this->xtr['routes'] as $fallback => $routes) {
         $routes = RouteCollection::FromArray($routes)->flat();
         $matcher = new RedirectableUrlMatcher($routes->toSilexCollection(), $context);
         try {
             $matcher->match($path);
             $matched = $fallback;
             break;
         } catch (ResourceNotFoundException $e) {
             // not found: silent continue
             $lastException = $e;
         }
     }
     if ($matched === false) {
         throw $lastException;
     }
     // configuring distinct service:
     $allow = [$matched];
     $fallbacks = array_flip(array_keys($this->xtr['routes']));
     unset($fallbacks[$matched]);
     $deny = array_keys($fallbacks);
     $this->xtr['@distinct.settings'] = ['allow' => $allow, 'deny' => $deny];
 }
コード例 #2
0
ファイル: UrlMatcher.php プロジェクト: gmo/common
 public function match($pathinfo)
 {
     try {
         return parent::match($pathinfo);
     } catch (ResourceNotFoundException $e) {
         if (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
             throw $e;
         }
     }
     // Try matching the route with trailing slash
     if ('/' !== substr($pathinfo, -1)) {
         try {
             return parent::match($pathinfo . '/');
         } catch (ResourceNotFoundException $e2) {
             throw $e;
         }
     }
     // Try matching the route without trailing slash
     $withoutTrailingSlash = substr($pathinfo, 0, -1);
     try {
         return parent::match($withoutTrailingSlash);
     } catch (ResourceNotFoundException $e2) {
         throw $e;
     }
 }
コード例 #3
0
 public function match($pathinfo)
 {
     try {
         return parent::match($pathinfo);
     } catch (ResourceNotFoundException $e) {
         return $this->matcher->match($pathinfo);
     }
 }
コード例 #4
0
ファイル: BoltUrlMatcher.php プロジェクト: pkdevboxy/site-v20
 public function match($pathinfo)
 {
     try {
         return parent::match($pathinfo);
     } catch (ResourceNotFoundException $e) {
         if ('/' !== substr($pathinfo, -1)) {
             throw $e;
         }
         // Try matching the route without trailing slash
         $withoutTrailingSlash = substr($pathinfo, 0, -1);
         try {
             parent::match($withoutTrailingSlash);
             return $this->redirect($withoutTrailingSlash, null);
         } catch (ResourceNotFoundException $e2) {
             throw $e;
         }
     }
 }
コード例 #5
0
ファイル: UrlMatcher.php プロジェクト: atiarda/bolt
 public function match($pathinfo)
 {
     try {
         return parent::match($pathinfo);
     } catch (ResourceNotFoundException $e) {
         if ('/' !== substr($pathinfo, -1)) {
             throw $e;
         }
         // Try matching the route without trailing slash
         $withoutTrailingSlash = substr($pathinfo, 0, -1);
         try {
             parent::match($withoutTrailingSlash);
             return $this->redirect($withoutTrailingSlash, null);
         } catch (ResourceNotFoundException $e2) {
             // We don't care about the new exception as we are just trying
             // to match different versions of the route, if it fails then we
             // throw the original one
             throw $e;
         }
     }
 }
コード例 #6
0
ファイル: SilexRouter.php プロジェクト: spryker/Application
 /**
  * Tries to match a URL path with a set of routes.
  *
  * If the matcher can not find information, it must throw one of the exceptions documented
  * below.
  *
  * @api
  *
  * @param string $pathinfo The path info to be parsed (raw format, i.e. not urldecoded)
  *
  * @return array An array of parameters
  */
 public function match($pathinfo)
 {
     $matcher = new RedirectableUrlMatcher($this->getRouteCollection(), $this->getContext());
     return $matcher->match($pathinfo);
 }
コード例 #7
0
ファイル: Application.php プロジェクト: NoDiskInDriveA/Silex
 /**
  * Handles onKernelRequest events.
  */
 public function onKernelRequest(KernelEvent $event)
 {
     $this['request'] = $event->getRequest();
     $this['request_context'] = new RequestContext($this['request']->getBaseUrl(), $this['request']->getMethod(), $this['request']->getHost(), $this['request']->getScheme(), !$this['request']->isSecure() ? $this['request']->getPort() : $this['request.http_port'], $this['request']->isSecure() ? $this['request']->getPort() : $this['request.https_port']);
     $this['controllers']->flush();
     $matcher = new RedirectableUrlMatcher($this['routes'], $this['request_context']);
     try {
         $attributes = $matcher->match($this['request']->getPathInfo());
         $this['request']->attributes->add($attributes);
     } catch (RoutingException $e) {
         // make sure onSilexBefore event is dispatched
         $this['dispatcher']->dispatch(SilexEvents::BEFORE);
         if ($e instanceof ResourceNotFoundException) {
             $message = sprintf('No route found for "%s %s"', $this['request']->getMethod(), $this['request']->getPathInfo());
             throw new NotFoundHttpException($message, $e);
         } else {
             if ($e instanceof MethodNotAllowedException) {
                 $message = sprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $this['request']->getMethod(), $this['request']->getPathInfo(), strtoupper(implode(', ', $e->getAllowedMethods())));
                 throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e);
             }
         }
         throw $e;
     }
     $this['dispatcher']->dispatch(SilexEvents::BEFORE);
 }