Ejemplo n.º 1
0
 function it_falls_back_to_decorated_template_locator_if_there_are_no_themes_active(FileLocatorInterface $decoratedFileLocator, ThemeContextInterface $themeContext, ThemeHierarchyProviderInterface $themeHierarchyProvider, TemplateReferenceInterface $template)
 {
     $themeContext->getTheme()->willReturn(null);
     $themeHierarchyProvider->getThemeHierarchy(null)->willReturn([]);
     $decoratedFileLocator->locate($template, Argument::cetera())->willReturn('/app/template/path');
     $this->locate($template)->shouldReturn('/app/template/path');
 }
 /**
  * @param ThemeInterface $mainTheme
  *
  * @return array
  */
 private function extractResourcesFromTheme(ThemeInterface $mainTheme)
 {
     /** @var ThemeInterface[] $themes */
     $themes = array_reverse($this->themeHierarchyProvider->getThemeHierarchy($mainTheme));
     $resources = [];
     foreach ($themes as $theme) {
         $paths = $this->translationFilesFinder->findTranslationFiles($theme->getPath());
         foreach ($paths as $path) {
             $resources[] = new ThemeTranslationResource($mainTheme, $path);
         }
     }
     return $resources;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function locate($template, $currentPath = null, $first = true)
 {
     if (!$template instanceof TemplateReferenceInterface) {
         throw new \InvalidArgumentException('The template must be an instance of TemplateReferenceInterface.');
     }
     $themes = $this->themeHierarchyProvider->getThemeHierarchy($this->themeContext->getTheme());
     foreach ($themes as $theme) {
         try {
             return $this->templateLocator->locateTemplate($template, $theme);
         } catch (ResourceNotFoundException $exception) {
             // Ignore if resource cannot be found in given theme.
         }
     }
     return $this->decoratedFileLocator->locate($template, $currentPath, $first);
 }
Ejemplo n.º 4
0
 /**
  * @param string $id
  *
  * @return \Generator
  */
 private function getPossibleIds($id)
 {
     $themes = $this->themeHierarchyProvider->getThemeHierarchy($this->themeContext->getTheme());
     foreach ($themes as $theme) {
         (yield $id . '|' . $theme->getName());
     }
     (yield $id);
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function installBundleAssets(BundleInterface $bundle, $targetDir, $symlinkMask)
 {
     $targetDir .= preg_replace('/bundle$/', '', strtolower($bundle->getName()));
     $this->filesystem->remove($targetDir);
     $effectiveSymlinkMask = $symlinkMask;
     foreach ($this->findAssetsPaths($bundle) as $originDir) {
         $effectiveSymlinkMask = min($effectiveSymlinkMask, $this->installVanillaBundleAssets($originDir, $targetDir, $symlinkMask));
     }
     foreach ($this->themeRepository->findAll() as $theme) {
         $themes = $this->themeHierarchyProvider->getThemeHierarchy($theme);
         foreach ($this->findAssetsPaths($bundle, $themes) as $originDir) {
             $effectiveSymlinkMask = min($effectiveSymlinkMask, $this->installThemedBundleAssets($theme, $originDir, $targetDir, $symlinkMask));
         }
     }
     return $effectiveSymlinkMask;
 }
Ejemplo n.º 6
0
 function it_returns_an_empty_array_as_theme_hierarchy_if_there_is_no_current_theme(ThemeHierarchyProviderInterface $themeHierarchyProvider)
 {
     $themeHierarchyProvider->getThemeHierarchy(Argument::any())->shouldNotBeCalled();
     $this->getThemeHierarchy()->shouldReturn([]);
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     $this->data['used_theme'] = $this->themeContext->getTheme();
     $this->data['used_themes'] = $this->themeHierarchyProvider->getThemeHierarchy($this->themeContext->getTheme());
     $this->data['themes'] = $this->themeRepository->findAll();
 }
Ejemplo n.º 8
0
 function it_returns_id_if_there_is_no_given_choice_translation(TranslatorInterface $translator, ThemeContextInterface $themeContext, ThemeHierarchyProviderInterface $themeHierarchyProvider, ThemeInterface $theme)
 {
     $theme->getName()->willReturn('theme/name');
     $themeContext->getTheme()->willReturn($theme);
     $themeHierarchyProvider->getThemeHierarchy($theme)->willReturn([$theme]);
     $translator->transChoice('id|theme/name', 42, Argument::cetera())->willReturn('id|theme/name');
     $translator->transChoice('id', 42, Argument::cetera())->willReturn('id');
     $this->transChoice('id', 42)->shouldReturn('id');
 }
 function it_returns_resources_locales_while_using_more_than_one_theme(TranslationFilesFinderInterface $translationFilesFinder, ThemeRepositoryInterface $themeRepository, ThemeHierarchyProviderInterface $themeHierarchyProvider, ThemeInterface $mainTheme, ThemeInterface $parentTheme)
 {
     $themeRepository->findAll()->willReturn([$mainTheme, $parentTheme]);
     $themeHierarchyProvider->getThemeHierarchy($mainTheme)->willReturn([$mainTheme, $parentTheme]);
     $themeHierarchyProvider->getThemeHierarchy($parentTheme)->willReturn([$parentTheme]);
     $mainTheme->getPath()->willReturn('/main/theme/path');
     $mainTheme->getName()->willReturn('main-theme/name');
     $parentTheme->getPath()->willReturn('/parent/theme/path');
     $parentTheme->getName()->willReturn('parent-theme/name');
     $translationFilesFinder->findTranslationFiles('/main/theme/path')->willReturn(['/main/theme/path/messages.en.yml']);
     $translationFilesFinder->findTranslationFiles('/parent/theme/path')->willReturn(['/parent/theme/path/messages.en.yml']);
     $this->getResourcesLocales()->shouldReturn(['en@main-theme-name', 'en@parent-theme-name']);
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function getThemeHierarchy()
 {
     return null !== $this->theme ? $this->themeHierarchyProvider->getThemeHierarchy($this->theme) : [];
 }