/** * @param TemplateReferenceInterface $template */ private function warmUpTemplate(TemplateReferenceInterface $template) { /** @var ThemeInterface $theme */ foreach ($this->themeRepository->findAll() as $theme) { $this->warmUpThemeTemplate($template, $theme); } }
function it_returns_null_if_channel_has_no_theme(ChannelContextInterface $channelContext, ThemeRepositoryInterface $themeRepository, ChannelInterface $channel) { $channelContext->getChannel()->willReturn($channel); $channel->getThemeName()->willReturn(null); $themeRepository->findOneByName(null)->willReturn(null); $this->getTheme()->shouldReturn(null); }
/** * @param string $themeName * * @return ThemeInterface */ private function getTheme($themeName) { $theme = $this->themeRepository->findOneByName($themeName); if (null === $theme) { throw new NotFoundHttpException(sprintf('Theme with name "%s" not found', $themeName)); } return $theme; }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(['choices' => function (Options $options) { return $this->themeRepository->findAll(); }, 'choice_label' => function (ThemeInterface $theme) { return (string) $theme; }]); }
/** * @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')); }
/** * @param string $themeName * * @return ThemeInterface * * @throws \InvalidArgumentException If theme is not found */ private function getTheme($themeName) { $theme = $this->themeRepository->findOneByName($themeName); if (null === $theme) { throw new \InvalidArgumentException(sprintf('Theme "%s" not found!', $themeName)); } return $theme; }
function it_adds_theme_name_to_keys_if_given_file_is_included_in_theme(LoaderInterface $loader, ThemeRepositoryInterface $themeRepository, MessageCatalogueInterface $messageCatalogue, ThemeInterface $theme) { $loader->load('/theme/resource.en.xml', 'en', 'messages')->willReturn($messageCatalogue); $themeRepository->findOneByPath('/theme/resource.en.xml')->willReturn($theme); $theme->getName()->willReturn('sylius/sample-theme'); $messageCatalogue->all('messages')->willReturn(['key' => 'value']); $messageCatalogue->replace(['key|sylius/sample-theme' => 'value'], 'messages')->shouldBeCalled(); $this->load('/theme/resource.en.xml', 'en', 'messages')->shouldReturn($messageCatalogue); }
public function it_returns_a_theme(TenantContextInterface $tenantContext, ThemeAwareTenantInterface $tenant, ThemeInterface $theme, ThemeRepositoryInterface $themeRepository) { $tenantContext->getTenant()->willReturn($tenant); $tenant->getSubdomain()->willReturn('subdomain1'); $tenant->getCode()->willReturn('code'); $tenant->getThemeName()->willReturn('swp/default-theme'); $themeRepository->findOneByName('swp/default-theme@code')->willReturn($theme); $this->getTheme()->shouldReturn($theme); }
function it_returns_theme_list_in_hierarchized_order(ThemeRepositoryInterface $themeRepository, ThemeInterface $firstTheme, ThemeInterface $secondTheme) { $firstTheme->getName()->willReturn('foo/bar1'); $firstTheme->getParentsNames()->willReturn(['foo/bar2']); $secondTheme->getName()->willReturn('foo/bar2'); $secondTheme->getParentsNames()->willReturn([]); $themeRepository->findOneByName('foo/bar1')->willReturn($firstTheme); $themeRepository->findOneByName('foo/bar2')->willReturn($secondTheme); $this->getThemeHierarchy($firstTheme)->shouldReturn([$firstTheme, $secondTheme]); }
function it_returns_theme_list_in_hierarchized_order(ThemeRepositoryInterface $themeRepository, ThemeInterface $firstTheme, ThemeInterface $secondTheme) { $firstTheme->getSlug()->willReturn("foo/bar1"); $firstTheme->getParentsSlugs()->willReturn(["foo/bar2"]); $secondTheme->getSlug()->willReturn("foo/bar2"); $secondTheme->getParentsSlugs()->willReturn([]); $themeRepository->findOneBySlug("foo/bar1")->willReturn($firstTheme); $themeRepository->findOneBySlug("foo/bar2")->willReturn($secondTheme); $this->getThemeHierarchy($firstTheme)->shouldReturn([$firstTheme, $secondTheme]); }
/** * {@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; }
function it_resolves_themes(ThemeRepositoryInterface $themeRepository, ThemeInterface $firstTheme, ThemeInterface $secondTheme) { $firstTheme->getLogicalName()->willReturn("foo/bar1"); $firstTheme->getParentsNames()->willReturn(["foo/bar2"]); $secondTheme->getLogicalName()->willReturn("foo/bar2"); $secondTheme->getParentsNames()->willReturn([]); $themeRepository->findByLogicalName("foo/bar1")->willReturn($firstTheme); $themeRepository->findByLogicalName("foo/bar2")->willReturn($secondTheme); $this->getDependencies($firstTheme)->shouldReturn([$secondTheme]); }
/** * @Given the store has :themeName theme */ public function storeHasTheme($themeName) { $theme = $this->themeFactory->createNamed($themeName); $theme->setTitle($themeName); $theme->setPath(sys_get_temp_dir() . '/theme-' . $theme->getCode() . time() . '/'); if (!file_exists($theme->getPath())) { mkdir($theme->getPath(), 0777, true); } $this->themeRepository->add($theme); $this->sharedStorage->set('theme', $theme); }
/** * {@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) { $resolver->setDefaults(['choices' => function (Options $options) { $themes = $this->themeRepository->findAll(); $choices = []; foreach ($themes as $theme) { $choices[(string) $theme] = $theme->getName(); } return $choices; }]); }
/** * {@inheritdoc} */ public function getTheme() { try { /** @var ChannelInterface $channel */ $channel = $this->channelContext->getChannel(); return $this->themeRepository->findOneByName($channel->getThemeName()); } catch (ChannelNotFoundException $exception) { return null; } catch (\Exception $exception) { return null; } }
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); }
/** * {@inheritdoc} */ public function getDependencies(ThemeInterface $theme) { $parents = []; $parentsNames = $theme->getParentsNames(); foreach ($parentsNames as $parentName) { $parent = $this->themeRepository->findByLogicalName($parentName); if (null === $parent) { throw new \InvalidArgumentException(sprintf('Theme "%s" not found (required by theme "%s")!', $parentName, $theme->getLogicalName()), 0); } $parents = array_merge($parents, [$parent], $this->getDependencies($parent)); } return $parents; }
/** * {@inheritdoc} */ public function load($resource, $locale, $domain = 'messages') { $messageCatalogue = $this->loader->load($resource, $locale, $domain); $theme = $this->themeRepository->findOneByPath($resource); if (null !== $theme) { $messages = $messageCatalogue->all($domain); foreach ($messages as $key => $value) { unset($messages[$key]); $messages[$key . '|' . $theme->getSlug()] = $value; } $messageCatalogue->replace($messages, $domain); } return $messageCatalogue; }
/** * {@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; }); }
/** * @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); }
/** * {@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))); }
/** * {@inheritdoc} */ public function findOneByName($name) { try { return $this->unstableRepository->findOneByName($name); } catch (\Exception $exception) { return $this->fallbackRepository->findOneByName($name); } }
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(); }
/** * {@inheritdoc} */ public function getTheme() { /* @var ThemeAwareTenantInterface $tenant */ $tenant = $this->tenantContext->getTenant(); $key = md5($tenant->getCode()); if (array_key_exists($key, $this->themes)) { return $this->themes[$key]; } if ($this->cacheService->contains('theme_' . $key)) { return $this->themes[$key] = $this->cacheService->fetch('theme_' . $key); } $theme = $this->themeRepository->findOneByName($this->resolveThemeName($tenant)); unset($tenant); if (null === $theme) { throw new NoThemeException(); } $this->themes[$key] = $theme; $this->cacheService->save('theme_' . $key, $theme, 600); return $theme; }
/** * {@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; }
/** * @param ThemeInterface[] $persistedThemes * @param ThemeInterface[] $loadedThemes * * @return ThemeInterface[] Removed themes */ private function removeAbandonedThemes(array $persistedThemes, array $loadedThemes) { if (0 === count($persistedThemes)) { return []; } $loadedThemesNames = array_map(function (ThemeInterface $theme) { return $theme->getName(); }, $loadedThemes); $removedThemes = []; foreach ($persistedThemes as $persistedTheme) { if (!in_array($persistedTheme->getName(), $loadedThemesNames, true)) { $removedThemes[] = $persistedTheme; $this->themeRepository->remove($persistedTheme); } } return $removedThemes; }
/** * {@inheritdoc} */ public function collect(Request $request, Response $response, \Exception $exception = null) { $this->usedThemes = $this->themeContext->getThemes(); $this->allThemes = $this->themeRepository->findAll(); }
/** * @Transform :theme * @Transform /^"([^"]+)" theme$/ * @Transform /^theme "([^"]+)"$/ */ public function getThemeByThemeTitle($themeTitle) { return $this->themeRepository->findOneBy(['title' => $themeTitle]); }
/** * {@inheritdoc} */ public function getCurrentTenantAvailableThemes() { $themes = $this->themeRepository->findAll(); return iterator_to_array($this->filterThemesByTenantCode($themes)); }