Ejemplo n.º 1
0
 /**
  * @param RouteCollection $collection
  * @param string $name
  * @param array $config
  * @param string $path
  */
 protected function parseRoute(RouteCollection $collection, $name, array $config, $path)
 {
     $defaults = isset($config['defaults']) ? $config['defaults'] : array();
     $requirements = isset($config['requirements']) ? $config['requirements'] : array();
     $options = isset($config['options']) ? $config['options'] : array();
     $host = isset($config['host']) ? $config['host'] : '';
     $schemes = isset($config['schemes']) ? $config['schemes'] : array();
     $methods = isset($config['methods']) ? $config['methods'] : array();
     $i18n = isset($config['i18n']) ? $config['i18n'] : true;
     foreach ($this->registry->getRegisteredLocales() as $locale) {
         $route = new Route($config['path'], $defaults, $requirements, $options, $host, $schemes, $methods);
         if ($i18n) {
             $route->setPath('/' . $locale . '/' . ltrim($this->helper->alterPath($config['path'], $locale), '/'));
             $route->setDefaults($this->helper->alterDefaults($defaults, $locale));
         }
         $i18nName = $i18n ? $this->helper->alterName($name, $locale) : $name;
         $collection->add($i18nName, $route);
     }
 }
 /**
  * @param RouteCollection $collection
  * @param $annot
  * @param $globals
  * @param \ReflectionClass $class
  * @param \ReflectionMethod $method
  */
 protected function addRoute(RouteCollection $collection, $annot, $globals, \ReflectionClass $class, \ReflectionMethod $method)
 {
     $i18n = isset($annot->data['i18n']) ? $annot->data['i18n'] : true;
     unset($annot->data['i18n']);
     foreach ($this->registry->getRegisteredLocales() as $locale) {
         $i18nAnnot = new Route($annot->data);
         $i18nGlobals = $globals;
         if ($i18n) {
             $i18nAnnot->setName($this->helper->alterName($i18nAnnot->getName(), $locale));
             $i18nAnnot->setPath($this->helper->alterPath($i18nAnnot->getPath(), $locale));
             $i18nAnnot->setDefaults($this->helper->alterDefaults($i18nAnnot->getDefaults(), $locale));
             if (isset($i18nGlobals['path']) && !empty($i18nGlobals['path'])) {
                 $i18nGlobals['path'] = '/' . $locale . '/' . ltrim($this->helper->alterPath($i18nGlobals['path'], $locale), '/');
             } else {
                 $i18nGlobals['path'] = '/' . $locale;
             }
         }
         parent::addRoute($collection, $i18nAnnot, $i18nGlobals, $class, $method);
     }
 }