/**
  * @param TemplateReferenceInterface $template
  */
 private function warmUpTemplate(TemplateReferenceInterface $template)
 {
     /** @var ThemeInterface $theme */
     foreach ($this->themeRepository->findAll() as $theme) {
         $this->warmUpThemeTemplate($template, $theme);
     }
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function findAll()
 {
     try {
         return $this->unstableRepository->findAll();
     } catch (\Exception $exception) {
         return $this->fallbackRepository->findAll();
     }
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(['choices' => function (Options $options) {
         return $this->themeRepository->findAll();
     }, 'choice_label' => function (ThemeInterface $theme) {
         return (string) $theme;
     }]);
 }
 /**
  * {@inheritdoc}
  */
 public function getResources()
 {
     /** @var ThemeInterface[] $themes */
     $themes = $this->themeRepository->findAll();
     $resources = [];
     foreach ($themes as $theme) {
         $resources = array_merge($resources, $this->extractResourcesFromTheme($theme));
     }
     return $resources;
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function synchronize()
 {
     $persistedThemes = $this->themeRepository->findAll();
     $loadedThemes = $this->themeLoader->load();
     $removedThemes = $this->removeAbandonedThemes($persistedThemes, $loadedThemes);
     $existingThemes = array_udiff($persistedThemes, $removedThemes, function (ThemeInterface $firstTheme, ThemeInterface $secondTheme) {
         return (int) ($firstTheme->getName() === $secondTheme->getName());
     });
     $this->updateThemes($existingThemes, $loadedThemes);
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(['choices' => function (Options $options) {
         $themes = $this->themeRepository->findAll();
         $choices = [];
         foreach ($themes as $theme) {
             $choices[(string) $theme] = $theme->getName();
         }
         return $choices;
     }]);
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     // Normalizer instead of default as it should not be overwritten
     $resolver->setNormalizer('choices', function () {
         return $this->themeRepository->findAll();
     })->setNormalizer('choices_as_values', function () {
         return true;
     })->setDefault('choice_label', function (ThemeInterface $theme) {
         return (string) $theme;
     });
 }
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     // Normalizer instead of default as it should not be overwritten
     $resolver->setNormalizer('choices', function () {
         $themes = $this->themeRepository->findAll();
         $choices = [];
         foreach ($themes as $theme) {
             $choices[(string) $theme] = $theme->getName();
         }
         return $choices;
     })->setNormalizer('choices_as_values', function () {
         return true;
     });
 }
 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     $templates = [];
     $themes = $this->themeRepository->findAll();
     /** @var TemplateReferenceInterface $template */
     foreach ($this->finder->findAllTemplates() as $template) {
         $this->themeContext->clear();
         foreach ($themes as $theme) {
             $this->themeContext->setTheme($theme);
             $path = $this->locator->locate($template);
             $templates[$template->getLogicalName() . "|" . $theme->getLogicalName()] = $path;
         }
         $templates[$template->getLogicalName()] = $this->locator->locate($template);
     }
     $this->writeCacheFile($cacheDir . '/templates.php', sprintf('<?php return %s;', var_export($templates, true)));
 }
 function it_builds_cache_by_warming_up_every_template_and_every_theme_together(TemplateFinderInterface $templateFinder, TemplateLocatorInterface $templateLocator, ThemeRepositoryInterface $themeRepository, Cache $cache, ThemeInterface $theme, TemplateReferenceInterface $firstTemplate, TemplateReferenceInterface $secondTemplate)
 {
     $templateFinder->findAllTemplates()->willReturn([$firstTemplate, $secondTemplate]);
     $themeRepository->findAll()->willReturn([$theme]);
     $theme->getName()->willReturn('theme/name');
     $firstTemplate->getLogicalName()->willReturn('Logical:Name:First');
     $secondTemplate->getLogicalName()->willReturn('Logical:Name:Second');
     $templateLocator->locateTemplate($firstTemplate, $theme)->willReturn('/First/Theme/index.html.twig');
     $templateLocator->locateTemplate($secondTemplate, $theme)->willThrow(ResourceNotFoundException::class);
     $cache->save('Logical:Name:First|theme/name', '/First/Theme/index.html.twig')->shouldBeCalled();
     $cache->save('Logical:Name:Second|theme/name', null)->shouldBeCalled();
     $this->warmUp(null);
 }
Пример #11
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 = array_merge([$theme], $this->themeDependenciesResolver->getDependencies($theme));
         foreach ($this->findAssetsPaths($bundle, $themes) as $originDir) {
             $effectiveSymlinkMask = min($effectiveSymlinkMask, $this->installThemedBundleAssets($theme, $originDir, $targetDir, $symlinkMask));
         }
     }
     return $effectiveSymlinkMask;
 }
Пример #12
0
 function it_ensures_cohesion_between_parent_themes(ThemeLoaderInterface $themeLoader, ThemeRepositoryInterface $themeRepository, ThemeMergerInterface $themeMerger, ThemeInterface $loadedTheme, ThemeInterface $loadedParentTheme, ThemeInterface $existingParentTheme)
 {
     $themeRepository->findAll()->willReturn([$existingParentTheme]);
     $existingParentTheme->getName()->willReturn('parent-theme/name');
     $themeLoader->load()->willReturn([$loadedTheme, $loadedParentTheme]);
     $loadedTheme->getName()->willReturn('theme/name');
     $loadedTheme->getParents()->willReturn([$loadedParentTheme]);
     $themeRepository->findOneByName('theme/name')->willReturn(null);
     $loadedParentTheme->getName()->willReturn('parent-theme/name');
     $loadedParentTheme->getParents()->willReturn([]);
     $themeRepository->findOneByName('parent-theme/name')->willReturn($existingParentTheme);
     $loadedTheme->removeParent($loadedParentTheme)->shouldBeCalled();
     $loadedTheme->addParent($existingParentTheme)->shouldBeCalled();
     $themeMerger->merge($existingParentTheme, $loadedParentTheme)->willReturn($existingParentTheme);
     $themeRepository->add($loadedTheme)->shouldBeCalled();
     $themeRepository->add($existingParentTheme)->shouldBeCalled();
     $themeRepository->add($loadedParentTheme)->shouldNotBeCalled();
     $this->synchronize();
 }
Пример #13
0
 /**
  * {@inheritdoc}
  */
 public function getCurrentTenantAvailableThemes()
 {
     $themes = $this->themeRepository->findAll();
     return iterator_to_array($this->filterThemesByTenantCode($themes));
 }
Пример #14
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();
 }
 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']);
 }
Пример #16
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $themes = $this->themeRepository->findAll();
     $resolver->setDefault('choice_list', new ObjectChoiceList($themes, 'title', [], null, 'name'));
 }
 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     $this->usedThemes = $this->themeContext->getThemes();
     $this->allThemes = $this->themeRepository->findAll();
 }
Пример #18
0
 function it_has_options(OptionsResolver $resolver, ThemeRepositoryInterface $themeRepository, ThemeInterface $theme)
 {
     $resolver->setDefault('choice_list', Argument::type(ObjectChoiceList::class))->shouldBeCalled()->willReturn($resolver);
     $themeRepository->findAll()->shouldBeCalled()->willReturn([$theme]);
     $this->configureOptions($resolver);
 }