Ejemplo n.º 1
0
 /**
  * Tries to match a URL with a set of routes.
  *
  * Returns false if no route matches the URL.
  *
  * @param string $url URL to be parsed
  *
  * @return array|false An array of parameters or false if no route matches
  */
 public function match($url)
 {
     $params = $this->getMatcher()->match($url);
     if (false === $params) {
         throw new ResourceNotFoundException();
     }
     $currentLocale = 'en_GB';
     $request = $this->container->get('request_stack')->getCurrentRequest();
     if ($request instanceof Request) {
         $currentLocale = $this->localeResolver->resolveLocale($request);
     }
     // Clean the route name
     if (false !== ($pos = strpos($params['_route'], I18nLoader::ROUTING_PREFIX))) {
         $params['_route'] = substr($params['_route'], $pos + strlen(I18nLoader::ROUTING_PREFIX));
     }
     // Retrieve all authorized locales for the given route
     $routeLocales = [];
     if (isset($params['_locale'])) {
         $routeLocales = [$params['_locale']];
     } elseif (isset($params['_locales'])) {
         $routeLocales = $params['_locales'];
         unset($params['_locales']);
     }
     if (0 === count($routeLocales) || in_array($currentLocale, $routeLocales)) {
         $params['_locale'] = $currentLocale;
         return $params;
     }
     throw new ResourceNotFoundException();
 }
 /**
  * Tries to match a URL with a set of routes.
  *
  * Returns false if no route matches the URL.
  *
  * @param string $url URL to be parsed
  *
  * @return array|false An array of parameters or false if no route matches
  */
 public function match($url)
 {
     $params = $this->getMatcher()->match($url);
     if (false === $params) {
         throw new ResourceNotFoundException();
     }
     // No request. What append ?
     $currentLocale = null;
     if ($this->container->isScopeActive('request')) {
         $currentLocale = $this->localeResolver->resolveLocale($this->container->get('request'));
     }
     // Clean the route name
     if (false !== ($pos = strpos($params['_route'], I18nLoader::ROUTING_PREFIX))) {
         $params['_route'] = substr($params['_route'], $pos + strlen(I18nLoader::ROUTING_PREFIX));
     }
     // Retrieve all authorized locales for the given route
     $routeLocales = array();
     if (isset($params['_locale'])) {
         $routeLocales = array($params['_locale']);
     } elseif (isset($params['_locales'])) {
         $routeLocales = $params['_locales'];
         unset($params['_locales']);
     }
     if (0 === count($routeLocales) || in_array($currentLocale, $routeLocales)) {
         $params['_locale'] = $currentLocale;
         return $params;
     }
     throw new ResourceNotFoundException();
 }