Skip to content

Commit

Permalink
fixed symfony 5 issue, added missing dependencies, some small code en…
Browse files Browse the repository at this point in the history
…hancements
  • Loading branch information
koertho committed Jul 6, 2021
1 parent 4a6dcfd commit ff1e579
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 81 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 0 additions & 3 deletions src/Asset/EntrypointsJsonLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use Contao\LayoutModel;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class EntrypointsJsonLookup
{
Expand All @@ -26,8 +25,6 @@ class EntrypointsJsonLookup

/**
* EntrypointsJsonLookup constructor.
*
* @param ContainerInterface $container
*/
public function __construct(array $bundleConfig, CacheItemPoolInterface $cache = null)
{
Expand Down
13 changes: 7 additions & 6 deletions src/Asset/PageEntrypoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -148,7 +149,7 @@ public function collectPageEntries(LayoutModel $layout, PageModel $currentPage,
}

/**
* @throws \Exception
* @throws Exception
*/
public function getJsEntries(): array
{
Expand All @@ -158,7 +159,7 @@ public function getJsEntries(): array
}

/**
* @throws \Exception
* @throws Exception
*/
public function getCssEntries(): array
{
Expand All @@ -168,7 +169,7 @@ public function getCssEntries(): array
}

/**
* @throws \Exception
* @throws Exception
*/
public function getJsHeadEntries(): array
{
Expand All @@ -180,7 +181,7 @@ public function getJsHeadEntries(): array
/**
* Return all active entrypoints.
*
* @throws \Exception
* @throws Exception
*/
public function getActiveEntries(): array
{
Expand All @@ -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!');
}
}
}
110 changes: 66 additions & 44 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}
}
15 changes: 2 additions & 13 deletions src/EventListener/GeneratePageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand Down
14 changes: 0 additions & 14 deletions tests/EventListener/GeneratePageListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
Expand All @@ -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();
}
Expand Down

0 comments on commit ff1e579

Please sign in to comment.