Beispiel #1
0
 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];
 }
Beispiel #2
0
 public function run()
 {
     $this->migrateSettings();
     $app = $this->xtr->getApplication();
     $routes = $this->xtr['routes'];
     /** @var $appRoutes \Symfony\Component\Routing\RouteCollection */
     $appRoutes = $app['routes'];
     // adding allowed routes before routing, silex could match one:
     foreach ($this->config['settings']['allow'] as $allowed) {
         if ($allowed == '*') {
             $silexRoutes = RouteCollection::FromArray($routes)->flat()->toSilexCollection();
         } else {
             if (!isset($routes[$allowed]) or !is_array($routes[$allowed])) {
                 throw new \RuntimeException('Allowed distinct block "' . $allowed . '" not found or illegal.');
             }
             $silexRoutes = RouteCollection::FromArray($routes[$allowed])->flat()->toSilexCollection();
         }
         $appRoutes->addCollection($silexRoutes);
     }
     // adding denied routes before the controller executes, because these might be needed for generating URLs:
     $app->before(function (Request $request, Application $app) use($routes, $appRoutes) {
         foreach ($this->config['settings']['deny'] as $denied) {
             if ($denied == '-') {
                 break;
             }
             if (!isset($routes[$denied]) or !is_array($routes[$denied])) {
                 throw new \RuntimeException('Denied distinct block "' . $denied . '" not found or illegal.');
             }
             $silexRoutes = RouteCollection::FromArray($routes[$denied])->flat()->toSilexCollection();
             $appRoutes->addCollection($silexRoutes);
         }
     });
     // flagging XTR service that we completed the handling of routes, no more sub-services need to be executed:
     $this->xtr->flagProcessed();
 }
Beispiel #3
0
 public function run()
 {
     if (strtolower($this->config['locale']) == 'none') {
         return;
     }
     if (strtolower($this->config['locale']) == 'auto') {
         $get_locale = $this->config['get_locale'];
         if (!function_exists($get_locale)) {
             throw new \RuntimeException('Unable to find an implementation for get_locale(Application $app) function by config value: "' . $get_locale . '"');
         }
         $locale = $get_locale($this->xtr->getApplication());
     } else {
         $locale = strtolower($this->config['locale']);
     }
     $routes = $this->xtr['routes'];
     if (!is_array($routes)) {
         throw new \RuntimeException('Unable to find routes definitions.');
     }
     if (!isset($routes[$locale])) {
         throw new \RuntimeException('Unable to find routes for locale in settings at "routes.' . $locale . '".');
     }
     $this->xtr['routes'] = $routes[$locale];
 }