From a89c386f9481cd9c9673853262008fce51427b36 Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Sun, 17 Dec 2017 16:09:58 +0100 Subject: [PATCH 1/6] move license to the root --- Resources/meta/LICENSE => LICENSE | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Resources/meta/LICENSE => LICENSE (100%) diff --git a/Resources/meta/LICENSE b/LICENSE similarity index 100% rename from Resources/meta/LICENSE rename to LICENSE From 3815dae2048c29dc53a41d971ff1664a5b54a0c6 Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Sun, 17 Dec 2017 16:14:16 +0100 Subject: [PATCH 2/6] cookie setting is optional --- Controller/ThemeController.php | 30 ++++++++++++++++-------------- Resources/config/controller.xml | 6 +----- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Controller/ThemeController.php b/Controller/ThemeController.php index be9cd77..f7e62ce 100644 --- a/Controller/ThemeController.php +++ b/Controller/ThemeController.php @@ -36,7 +36,7 @@ class ThemeController /** * Options of the cookie to store active theme. * - * @var array + * @var array|null */ protected $cookieOptions; @@ -45,9 +45,9 @@ class ThemeController * * @param ActiveTheme $activeTheme active theme instance * @param array $themes Available themes - * @param array $cookieOptions The options of the cookie we look for the theme to set + * @param array|null $cookieOptions The options of the cookie we look for the theme to set */ - public function __construct(ActiveTheme $activeTheme, array $themes, array $cookieOptions) + public function __construct(ActiveTheme $activeTheme, array $themes, array $cookieOptions = null) { $this->activeTheme = $activeTheme; $this->themes = $themes; @@ -74,19 +74,21 @@ public function switchAction(Request $request) $this->activeTheme->setName($theme); $url = $request->headers->get('Referer', '/'); + $response = new RedirectResponse($url); - $cookie = new Cookie( - $this->cookieOptions['name'], - $theme, - time() + $this->cookieOptions['lifetime'], - $this->cookieOptions['path'], - $this->cookieOptions['domain'], - (bool) $this->cookieOptions['secure'], - (bool) $this->cookieOptions['http_only'] - ); + if (!empty($this->cookieOptions)) { + $cookie = new Cookie( + $this->cookieOptions['name'], + $theme, + time() + $this->cookieOptions['lifetime'], + $this->cookieOptions['path'], + $this->cookieOptions['domain'], + (bool) $this->cookieOptions['secure'], + (bool) $this->cookieOptions['http_only'] + ); - $response = new RedirectResponse($url); - $response->headers->setCookie($cookie); + $response->headers->setCookie($cookie); + } return $response; } diff --git a/Resources/config/controller.xml b/Resources/config/controller.xml index c440c9d..f027a9e 100755 --- a/Resources/config/controller.xml +++ b/Resources/config/controller.xml @@ -4,12 +4,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - Liip\ThemeBundle\Controller\ThemeController - - - + %liip_theme.themes% %liip_theme.cookie% From 1cce39fd2fc1a48ef0d35794bcdcaf68af6aa56e Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Sun, 17 Dec 2017 16:15:12 +0100 Subject: [PATCH 3/6] ensure the compiler passes run after other bundles --- DependencyInjection/Compiler/TemplateResourcesPass.php | 8 -------- LiipThemeBundle.php | 8 +++++--- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/DependencyInjection/Compiler/TemplateResourcesPass.php b/DependencyInjection/Compiler/TemplateResourcesPass.php index 0e549ab..59f8c02 100644 --- a/DependencyInjection/Compiler/TemplateResourcesPass.php +++ b/DependencyInjection/Compiler/TemplateResourcesPass.php @@ -48,10 +48,6 @@ public function process(ContainerBuilder $container) protected function setBundleDirectoryResources(ContainerBuilder $container, $engine, $bundleDirName, $bundleName) { - if (!$container->hasDefinition('assetic.'.$engine.'_directory_resource.'.$bundleName)) { - throw new LogicException('The LiipThemeBundle must be registered after the AsseticBundle in the application Kernel.'); - } - $resources = $container->getDefinition('assetic.'.$engine.'_directory_resource.'.$bundleName)->getArgument(0); $themes = $container->getParameter('liip_theme.themes'); foreach ($themes as $theme) { @@ -70,10 +66,6 @@ protected function setBundleDirectoryResources(ContainerBuilder $container, $eng protected function setAppDirectoryResources(ContainerBuilder $container, $engine) { - if (!$container->hasDefinition('assetic.'.$engine.'_directory_resource.kernel')) { - throw new LogicException('The LiipThemeBundle must be registered after the AsseticBundle in the application Kernel.'); - } - $themes = $container->getParameter('liip_theme.themes'); foreach ($themes as $key => $theme) { $themes[$key] = $container->getParameter('kernel.root_dir').'/Resources/themes/'.$theme; diff --git a/LiipThemeBundle.php b/LiipThemeBundle.php index 1e979a7..e38fb65 100644 --- a/LiipThemeBundle.php +++ b/LiipThemeBundle.php @@ -11,6 +11,7 @@ namespace Liip\ThemeBundle; +use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; use Liip\ThemeBundle\DependencyInjection\Compiler\ThemeCompilerPass; @@ -22,8 +23,9 @@ class LiipThemeBundle extends Bundle public function build(ContainerBuilder $container) { parent::build($container); - $container->addCompilerPass(new ThemeCompilerPass()); - $container->addCompilerPass(new TemplateResourcesPass()); - $container->addCompilerPass(new AsseticTwigFormulaPass()); + + $container->addCompilerPass(new ThemeCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 100); + $container->addCompilerPass(new TemplateResourcesPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 10); + $container->addCompilerPass(new AsseticTwigFormulaPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 10); } } From 8dea2fefb99398bec26e21fa6787eed12b8c054e Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Sun, 17 Dec 2017 16:15:18 +0100 Subject: [PATCH 4/6] ws tweaks --- Tests/DependencyInjection/Compiler/ThemeCompilerPassTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/DependencyInjection/Compiler/ThemeCompilerPassTest.php b/Tests/DependencyInjection/Compiler/ThemeCompilerPassTest.php index b239d18..72e5701 100644 --- a/Tests/DependencyInjection/Compiler/ThemeCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/ThemeCompilerPassTest.php @@ -23,8 +23,8 @@ public function testProcess() ->method('getParameter') ->will($this->returnValueMap( array( - array('liip_theme.cache_warming', true), - array('liip_theme.filesystem_loader.class', 'Liip\ThemeBundle\Twig\Loader\FilesystemLoader'), + array('liip_theme.cache_warming', true), + array('liip_theme.filesystem_loader.class', 'Liip\ThemeBundle\Twig\Loader\FilesystemLoader'), ) ) ) From ce4af915c8e8ce8955372cdab629f421787b5f85 Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Sun, 17 Dec 2017 16:15:32 +0100 Subject: [PATCH 5/6] removed .class parameters --- Resources/config/templating.xml | 18 ++++++------------ Resources/config/theme_request_listener.xml | 6 +----- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/Resources/config/templating.xml b/Resources/config/templating.xml index b106f8f..c17f194 100644 --- a/Resources/config/templating.xml +++ b/Resources/config/templating.xml @@ -4,37 +4,31 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - Liip\ThemeBundle\Locator\TemplateLocator - Liip\ThemeBundle\Locator\FileLocator Liip\ThemeBundle\Twig\Loader\FilesystemLoader - Liip\ThemeBundle\ActiveTheme - Liip\ThemeBundle\CacheWarmer\TemplatePathsCacheWarmer - Liip\ThemeBundle\Helper\DeviceDetection - Liip\ThemeBundle\CacheWarmer\TemplateFinder - + - + %kernel.root_dir%/Resources - + %kernel.cache_dir% - + %kernel.root_dir%/Resources @@ -42,9 +36,9 @@ %liip_theme.path_patterns% - + - + %liip_theme.active_theme% %liip_theme.themes% diff --git a/Resources/config/theme_request_listener.xml b/Resources/config/theme_request_listener.xml index 1213f48..61f2753 100644 --- a/Resources/config/theme_request_listener.xml +++ b/Resources/config/theme_request_listener.xml @@ -4,12 +4,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - Liip\ThemeBundle\EventListener\ThemeRequestListener - - - + %liip_theme.cookie% From 58af4350415e8576e3c1ff0ffe9036f7a1d4c70a Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Sun, 17 Dec 2017 16:39:46 +0100 Subject: [PATCH 6/6] fix php version in allowed failure --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f637860..a9a4a7b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,7 @@ matrix: - php: 7.1 env: DEPENDENCIES=beta allow_failures: - - php: 5.6 + - php: 7.2 env: SYMFONY_VERSION=@dev;ASSETIC=skip before_install: