/** * @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')); }
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]); }
/** * {@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; }
/** * @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); }