Пример #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 GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         // don't do anything if it's not the master request
         return;
     }
     $this->themeContext->setTheme($this->themeRepository->findByLogicalName('sylius/first-test-theme'));
 }
Пример #3
0
 public function it_should_return_global_variables(ThemeInterface $theme, ThemeContextInterface $themeContext)
 {
     $theme->getName()->willReturn('swp/theme-one');
     $theme->getPath()->willReturn('/path/to/theme/');
     $themeContext->getTheme()->shouldBeCalled()->willReturn($theme);
     $globals = ['theme' => $theme];
     $this->getGlobals()->shouldReturn($globals);
 }
Пример #4
0
 /**
  * @return array
  */
 public function getThemeSettings()
 {
     $theme = $this->themeContext->getTheme();
     if (null === $theme) {
         return [];
     }
     return $this->themeSettingsManager->load($theme);
 }
Пример #5
0
 function it_returns_modified_url_if_there_is_active_theme(ThemeContextInterface $themeContext, VersionStrategyInterface $versionStrategy, PathResolverInterface $pathResolver, ThemeInterface $theme)
 {
     $path = 'bundles/sample/asset.js';
     $themeAssetPath = 'bundles/theme/foo/bar/sample/asset.js';
     $themeContext->getTheme()->shouldBeCalled()->willReturn($theme);
     $pathResolver->resolve($path, $theme)->shouldBeCalled()->willReturn($themeAssetPath);
     $versionStrategy->applyVersion($themeAssetPath)->shouldBeCalled()->willReturn($themeAssetPath);
     $this->getUrl($path)->shouldReturn('/' . $themeAssetPath);
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public function getUrl($path)
 {
     if ($this->isAbsoluteUrl($path)) {
         return $path;
     }
     $theme = $this->themeContext->getTheme();
     if (null !== $theme) {
         $path = $this->pathResolver->resolve($path, $theme);
     }
     return $this->getBasePath() . ltrim($this->getVersionStrategy()->applyVersion($path), '/');
 }
 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         // don't do anything if it's not the master request
         return;
     }
     $themeName = $this->session->get('theme');
     if (null === $themeName) {
         return;
     }
     if (null === ($theme = $this->themeRepository->findByLogicalName($themeName))) {
         return;
     }
     $this->themeContext->setTheme($theme);
 }
Пример #8
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);
 }
 /**
  * {@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)));
 }
Пример #10
0
 /**
  * @param string $id
  *
  * @return \Generator
  */
 private function getPossibleIds($id)
 {
     $themes = $this->themeContext->getThemeHierarchy();
     foreach ($themes as $theme) {
         (yield $id . "|" . $theme->getSlug());
     }
     (yield $id);
 }
Пример #11
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);
 }
Пример #12
0
 /**
  * @param string $locale
  *
  * @return string
  */
 private function transformLocale($locale)
 {
     $theme = $this->themeContext->getTheme();
     if (null === $theme) {
         return $locale;
     }
     if (null === $locale) {
         $locale = $this->getLocale();
     }
     $locale = $locale . '@' . str_replace('/', '-', $theme->getName());
     return $locale;
 }
Пример #13
0
 /**
  * @param string $locale
  *
  * @return string
  */
 private function transformLocale($locale)
 {
     $theme = $this->themeContext->getTheme();
     if (null === $theme) {
         return $locale;
     }
     if (null === $locale) {
         $locale = $this->getLocale();
     }
     $locale = $locale . '_' . $theme->getCode();
     return $locale;
 }
 function it_proxies_choice_translating_with_modified_custom_locale(TranslatorInterface $translator, ThemeContextInterface $themeContext, ThemeInterface $theme)
 {
     $themeContext->getTheme()->willReturn($theme);
     $theme->getName()->willReturn('theme/name');
     $translator->transChoice('id', 2, ['param'], 'domain', 'customlocale@theme-name')->willReturn('translated string');
     $this->transChoice('id', 2, ['param'], 'domain', 'customlocale')->shouldReturn('translated string');
 }
Пример #15
0
 /**
  * @param TemplateReferenceInterface $template
  * @param ThemeInterface[] $themes
  *
  * @return null|string
  */
 protected function locateAppTemplateUsingThemes(TemplateReferenceInterface $template, array $themes = [])
 {
     $cacheKey = $this->getCacheKey($template, $this->themeContext->getTheme());
     return $this->cache[$cacheKey] = $this->applicationResourceLocator->locateResource($template->getPath(), $themes);
 }
Пример #16
0
 function it_returns_loaded_theme_settings(ThemeContextInterface $themeContext, ThemeSettingsManagerInterface $themeSettingsManager, ThemeInterface $theme, SettingsInterface $settings)
 {
     $themeContext->getTheme()->willReturn($theme);
     $themeSettingsManager->load($theme)->willReturn($settings);
     $this->getThemeSettings()->shouldReturn($settings);
 }
Пример #17
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();
 }
Пример #18
0
 /**
  * {@inheritdoc}
  */
 public function getGlobals()
 {
     return ['theme' => $this->themeContext->getTheme()];
 }
Пример #19
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');
 }
 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     $this->usedThemes = $this->themeContext->getThemes();
     $this->allThemes = $this->themeRepository->findAll();
 }
Пример #21
0
 /**
  * {@inheritdoc}
  */
 public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null)
 {
     return $this->doTranslate($id, $parameters, $domain, $locale, $number, $this->themeContext->getThemes());
 }