/**
  * {@inheritdoc}
  */
 private function getTemplates($name)
 {
     $posA = strrpos($name, ':');
     $posB = strrpos($name, '/');
     $posC = strrpos($name, '/');
     $b = $this->siteContext->getCurrentBrandingName();
     $l = $this->siteContext->getCurrentLocale();
     if ($posA === false && $posB === false && $posC === false) {
         $prefix = '';
         $suffix = '/' . $name;
     } else {
         $pos = max($posA, $posB, $posC);
         $prefix = substr($name, 0, $pos + 1);
         $suffix = '/' . substr($name, $pos + 1);
     }
     return array($prefix . '_' . $b . '_' . $l . '' . $suffix, $prefix . '_' . $b . '_' . $suffix, $prefix . '__' . $l . '' . $suffix, $name);
 }
 /**
  * Specific method to add a multisite route to the collection.
  *
  * Paths option should not be null.
  */
 protected function addMultisiteRoute(RouteCollection $collection, $annot, $globals, \ReflectionClass $class, \ReflectionMethod $method)
 {
     $paths = $this->siteContext->normalizePaths($annot->getPaths());
     foreach ($paths as $branding => $locales) {
         foreach ($locales as $locale => $path) {
             // this block of code is copied from Symfony\Component\Routing\Loader\AnnotationFileLoader
             $name = $annot->getName();
             if (null === $name) {
                 $name = $this->getDefaultRouteName($class, $method);
             }
             $name = MultisiteRouter::ROUTE_PREFIX . '_' . $branding . '_' . $locale . '__' . $name;
             $defaults = array_replace($globals['defaults'], $annot->getDefaults());
             foreach ($method->getParameters() as $param) {
                 if (!isset($defaults[$param->getName()]) && $param->isOptional()) {
                     $defaults[$param->getName()] = $param->getDefaultValue();
                 }
             }
             // +2 lines
             $defaults['_branding'] = $branding;
             $defaults['_locale'] = $locale;
             $requirements = array_replace($globals['requirements'], $annot->getRequirements());
             $options = array_replace($globals['options'], $annot->getOptions());
             $schemes = array_replace($globals['schemes'], $annot->getSchemes());
             $methods = array_replace($globals['methods'], $annot->getMethods());
             $host = $annot->getHost();
             if (null === $host) {
                 $host = $globals['host'];
             }
             // +3 lines
             if (!$host) {
                 $host = $this->siteContext->getBranding($branding)->getHost($locale);
             }
             $condition = $annot->getCondition();
             if (null === $condition) {
                 $condition = $globals['condition'];
             }
             $route = new Route($globals['path'] . $path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition);
             $this->configureRoute($route, $class, $method, $annot);
             $collection->add($name, $route);
         }
     }
     // cache will refresh when file is modified
     $collection->addResource(new FileResource($class->getFileName()));
     return $collection;
 }
 /**
  * Changes router context and site context according to matched route.
  *
  * @param array $match
  */
 private function setMatchContext(array $match)
 {
     if (isset($match['_branding'])) {
         $this->context->setParameter('_branding', $match['_branding']);
         $this->siteContext->setCurrentBranding($this->siteContext->getBranding($match['_branding']));
     }
     if (isset($match['_locale'])) {
         $this->context->setParameter('_locale', $match['_locale']);
         $this->siteContext->setCurrentLocale($match['_locale']);
     }
 }