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]; }