diff --git a/CHANGELOG.md b/CHANGELOG.md index af813a5..c1f9d07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. +## [1.11.2] - 2021-07-06 +- fixed symfony 5 issue +- fixed missing dependencies +- some small code enhancements + ## [1.11.1] - 2021-05-06 - fixed vendor dependency issue if non-head scripts were loaded after the head scripts while the head scripts contained diff --git a/composer.json b/composer.json index 6074475..1083946 100644 --- a/composer.json +++ b/composer.json @@ -19,10 +19,17 @@ "php": "^7.1", "ext-json": "*", "contao/core-bundle": "^4.4", + "symfony/cache": "^3.4|^4.4|^5.0", + "symfony/config": "^3.4|^4.4|^5.0", + "symfony/console": "^3.4|^4.4|^5.0", + "symfony/dependency-injection": "^3.4|^4.4|^5.0", + "symfony/http-foundation": "^3.4|^4.4|^5.0", + "symfony/http-kernel": "^3.4|^4.4|^5.0", + "symfony/translation": "^3.4|^4.4|^5.0", "symfony/webpack-encore-bundle": "^1.0", "heimrichhannot/contao-multi-column-editor-bundle": "^1.0|^2.0", "heimrichhannot/contao-utils-bundle": "^2.90", - "twig/twig": "^1.38.3|^2.7", + "twig/twig": "^1.38.3|^2.7|^3.0", "webmozart/path-util": "^2.3" }, "require-dev": { diff --git a/src/Asset/EntrypointsJsonLookup.php b/src/Asset/EntrypointsJsonLookup.php index 2156458..620992e 100644 --- a/src/Asset/EntrypointsJsonLookup.php +++ b/src/Asset/EntrypointsJsonLookup.php @@ -10,7 +10,6 @@ use Contao\LayoutModel; use Psr\Cache\CacheItemPoolInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; class EntrypointsJsonLookup { @@ -26,8 +25,6 @@ class EntrypointsJsonLookup /** * EntrypointsJsonLookup constructor. - * - * @param ContainerInterface $container */ public function __construct(array $bundleConfig, CacheItemPoolInterface $cache = null) { diff --git a/src/Asset/PageEntrypoints.php b/src/Asset/PageEntrypoints.php index 4be7f93..edef308 100644 --- a/src/Asset/PageEntrypoints.php +++ b/src/Asset/PageEntrypoints.php @@ -11,6 +11,7 @@ use Contao\LayoutModel; use Contao\PageModel; use Contao\StringUtil; +use Exception; use HeimrichHannot\EncoreBundle\Helper\ArrayHelper; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -148,7 +149,7 @@ public function collectPageEntries(LayoutModel $layout, PageModel $currentPage, } /** - * @throws \Exception + * @throws Exception */ public function getJsEntries(): array { @@ -158,7 +159,7 @@ public function getJsEntries(): array } /** - * @throws \Exception + * @throws Exception */ public function getCssEntries(): array { @@ -168,7 +169,7 @@ public function getCssEntries(): array } /** - * @throws \Exception + * @throws Exception */ public function getJsHeadEntries(): array { @@ -180,7 +181,7 @@ public function getJsHeadEntries(): array /** * Return all active entrypoints. * - * @throws \Exception + * @throws Exception */ public function getActiveEntries(): array { @@ -202,12 +203,12 @@ public function createInstance() /** * Check if initialized and throws exception, if not. * - * @throws \Exception + * @throws Exception */ protected function isInitalized(): void { if (!$this->initialized) { - throw new \Exception('Page entrypoints are not initialized!'); + throw new Exception('Page entrypoints are not initialized!'); } } } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 224eb05..5781a81 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -15,9 +15,14 @@ class Configuration implements ConfigurationInterface { public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); + $treeBuilder = new TreeBuilder('huh_encore'); - $rootNode = $treeBuilder->root('huh_encore'); + // Keep compatibility with symfony/config < 4.2 + if (!method_exists($treeBuilder, 'getRootNode')) { + $rootNode = $treeBuilder->root('huh_encore'); + } else { + $rootNode = $treeBuilder->getRootNode(); + } $rootNode ->children() @@ -92,66 +97,83 @@ public function getConfigTreeBuilder() ->info('Remove jQuery from global array, if addJQuery is enabled in layout section.') ->defaultFalse() ->end() - // TODO: Remove in version 2.0 - ->arrayNode('encore') + ->append($this->addLegacyNode()) + ->end() + ; + + return $treeBuilder; + } + + /** + * @deprecated Will be removed in version 2.0 + */ + public function addLegacyNode() + { + $treeBuilder = new TreeBuilder('encore'); + + // Keep compatibility with symfony/config < 4.2 + if (!method_exists($treeBuilder, 'getRootNode')) { + $node = $treeBuilder->root('encore'); + } else { + $node = $treeBuilder->getRootNode(); + } + + $node + ->addDefaultsIfNotSet() + ->setDeprecated('Configs within encore key are deprecated and will be removed in next major version.') + ->children() + ->arrayNode('entries') + ->arrayPrototype() + ->children() + ->scalarNode('name') + ->isRequired() + ->cannotBeEmpty() + ->end() + ->scalarNode('file') + ->isRequired() + ->cannotBeEmpty() + ->end() + ->booleanNode('requiresCss')->end() + ->booleanNode('head')->end() + ->end() + ->end() + ->end() + ->arrayNode('templates') ->addDefaultsIfNotSet() - ->setDeprecated('Configs within encore key are deprecated and will be removed in next major version.') ->children() - ->arrayNode('entries') + ->arrayNode('imports') ->arrayPrototype() ->children() ->scalarNode('name') ->isRequired() ->cannotBeEmpty() ->end() - ->scalarNode('file') + ->scalarNode('template') ->isRequired() ->cannotBeEmpty() ->end() - ->booleanNode('requiresCss') - ->end() - ->booleanNode('head') - ->end() ->end() ->end() ->end() - ->arrayNode('templates') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('imports') - ->arrayPrototype() - ->children() - ->scalarNode('name') - ->isRequired() - ->cannotBeEmpty() - ->end() - ->scalarNode('template') - ->isRequired() - ->cannotBeEmpty() - ->end() - ->end() - ->end() - ->end() - ->end() + ->end() + ->end() + ->arrayNode('legacy') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('js') + ->scalarPrototype()->end() ->end() - ->arrayNode('legacy') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('js') - ->scalarPrototype()->end() - ->end() - ->arrayNode('jquery') - ->scalarPrototype()->end() - ->end() - ->arrayNode('css') - ->scalarPrototype()->end() - ->end() - ->end() + ->arrayNode('jquery') + ->scalarPrototype()->end() + ->end() + ->arrayNode('css') + ->scalarPrototype()->end() ->end() ->end() ->end() - ->end(); + ->end() + ; - return $treeBuilder; + return $node; } } diff --git a/src/EventListener/GeneratePageListener.php b/src/EventListener/GeneratePageListener.php index 535d914..8820fbd 100644 --- a/src/EventListener/GeneratePageListener.php +++ b/src/EventListener/GeneratePageListener.php @@ -8,14 +8,12 @@ namespace HeimrichHannot\EncoreBundle\EventListener; -use Contao\CoreBundle\Framework\ContaoFrameworkInterface; use Contao\LayoutModel; use Contao\PageModel; use Contao\PageRegular; use HeimrichHannot\EncoreBundle\Asset\TemplateAsset; use HeimrichHannot\EncoreBundle\Helper\EntryHelper; use Symfony\Component\DependencyInjection\ContainerInterface; -use Twig\Environment; class GeneratePageListener { @@ -27,26 +25,17 @@ class GeneratePageListener * @var TemplateAsset */ private $templateAsset; - /** - * @var Environment - */ - private $twig; + /** * @var ContainerInterface */ private $container; - /** - * @var \Contao\CoreBundle\Framework\ContaoFramework|object|null - */ - private $framework; /** * Constructor. */ - public function __construct(array $bundleConfig, ContaoFrameworkInterface $framework, ContainerInterface $container, Environment $twig, TemplateAsset $templateAsset) + public function __construct(array $bundleConfig, ContainerInterface $container, TemplateAsset $templateAsset) { - $this->framework = $framework; - $this->twig = $twig; $this->container = $container; $this->templateAsset = $templateAsset; $this->bundleConfig = $bundleConfig; diff --git a/tests/EventListener/GeneratePageListenerTest.php b/tests/EventListener/GeneratePageListenerTest.php index 2aa9674..579f79f 100644 --- a/tests/EventListener/GeneratePageListenerTest.php +++ b/tests/EventListener/GeneratePageListenerTest.php @@ -17,7 +17,6 @@ use HeimrichHannot\EncoreBundle\Test\ModelMockTrait; use PHPUnit\Framework\MockObject\MockBuilder; use PHPUnit\Framework\MockObject\MockObject; -use Twig\Environment; class GeneratePageListenerTest extends ContaoTestCase { @@ -36,15 +35,6 @@ public function createTestInstance(array $parameters = [], $hookListenerMock = n if (!isset($parameters['container'])) { $parameters['container'] = $this->mockContainer(); } - if (!isset($parameters['framework'])) { - $parameters['framework'] = $this->mockContaoFramework(); - } - if (!isset($parameters['twig'])) { - /** @var Environment|MockObject $twig */ - $twig = $this->createMock(Environment::class); - $twig->method('render')->willReturnArgument(1); - $parameters['twig'] = $twig; - } if (!isset($parameters['templateAsset'])) { /** @var TemplateAsset|MockObject $templateAsset */ $templateAsset = $this->createMock(TemplateAsset::class); @@ -59,17 +49,13 @@ public function createTestInstance(array $parameters = [], $hookListenerMock = n if (!$hookListenerMock) { $hookListener = new GeneratePageListener( $parameters['bundleConfig'], - $parameters['framework'], $parameters['container'], - $parameters['twig'], $parameters['templateAsset'] ); } else { $hookListener = $hookListenerMock->setConstructorArgs([ $parameters['bundleConfig'], - $parameters['framework'], $parameters['container'], - $parameters['twig'], $parameters['templateAsset'], ])->getMock(); }