-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2773 from acrobat/change-pagerfanta-dependencies
[AdminListBundle] Change pagerfanta dependencies to require the minimum needed packages
- Loading branch information
Showing
15 changed files
with
266 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/Kunstmaan/AdminBundle/DependencyInjection/Compiler/PagerfantaBridgePass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kunstmaan\AdminBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Alias; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* Compiler pass to bridge the configuration from WhiteOctoberPagerfantaBundle to BabDevPagerfantaBundle | ||
* NEXT_MAJOR remove class | ||
* | ||
* @deprecated since KunstmaanAdminBundle 5.9. Migrate your Pagerfanta configuration from WhiteOctoberPagerfantaBundle to BabDevPagerfantaBundle, the configuration bridge will be removed in KunstmaanAdminBundle 6.0. | ||
* | ||
* @internal | ||
*/ | ||
final class PagerfantaBridgePass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
$this->changeViewFactoryClass($container); | ||
$this->aliasRenamedServices($container); | ||
} | ||
|
||
private function changeViewFactoryClass(ContainerBuilder $container): void | ||
{ | ||
if (!$container->hasParameter('white_october_pagerfanta.view_factory.class') || !$container->hasDefinition('pagerfanta.view_factory')) { | ||
return; | ||
} | ||
|
||
$container->getDefinition('pagerfanta.view_factory') | ||
->setClass($container->getParameter('white_october_pagerfanta.view_factory.class')); | ||
} | ||
|
||
private function aliasRenamedServices(ContainerBuilder $container): void | ||
{ | ||
if ($container->hasDefinition('pagerfanta.twig_extension')) { | ||
$alias = $container->setAlias('twig.extension.pagerfanta', 'pagerfanta.twig_extension'); | ||
if (method_exists(Alias::class, 'setDeprecated')) { | ||
$alias->setDeprecated(true, 'The "%alias_id%" service alias is deprecated since KunstmaanAdminBundle 5.9, use the "pagerfanta.twig_extension" service ID instead.'); | ||
} | ||
} | ||
|
||
if ($container->hasDefinition('pagerfanta.view_factory')) { | ||
$alias = $container->setAlias('white_october_pagerfanta.view_factory', 'pagerfanta.view_factory'); | ||
if (method_exists(Alias::class, 'setDeprecated')) { | ||
$alias->setDeprecated(true, 'The "%alias_id%" service alias is deprecated since KunstmaanAdminBundle 5.9, use the "pagerfanta.view_factory" service ID instead.'); | ||
} | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/Kunstmaan/AdminBundle/DependencyInjection/PagerfantaConfiguration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\AdminBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
/** | ||
* Container configuration to bridge the configuration from WhiteOctoberPagerfantaBundle to BabDevPagerfantaBundle | ||
* NEXT_MAJOR remove class | ||
* | ||
* @deprecated since KunstmaanAdminBundle 5.9. Migrate your Pagerfanta configuration from WhiteOctoberPagerfantaBundle to BabDevPagerfantaBundle, the configuration bridge will be removed in KunstmaanAdminBundle 6.0. | ||
* | ||
* @internal | ||
*/ | ||
final class PagerfantaConfiguration implements ConfigurationInterface | ||
{ | ||
public const EXCEPTION_STRATEGY_TO_HTTP_NOT_FOUND = 'to_http_not_found'; | ||
|
||
public function getConfigTreeBuilder(): TreeBuilder | ||
{ | ||
$treeBuilder = new TreeBuilder('white_october_pagerfanta'); | ||
if (method_exists($treeBuilder, 'getRootNode')) { | ||
$rootNode = $treeBuilder->getRootNode(); | ||
} else { | ||
// BC layer for symfony/config 4.1 and older | ||
$rootNode = $treeBuilder->root('white_october_pagerfanta'); | ||
} | ||
|
||
$this->addExceptionsStrategySection($rootNode); | ||
|
||
$rootNode | ||
->children() | ||
->scalarNode('default_view') | ||
->defaultValue('default') | ||
->end() | ||
->end() | ||
; | ||
|
||
return $treeBuilder; | ||
} | ||
|
||
private function addExceptionsStrategySection(ArrayNodeDefinition $node): void | ||
{ | ||
$node | ||
->children() | ||
->arrayNode('exceptions_strategy') | ||
->addDefaultsIfNotSet() | ||
->children() | ||
->scalarNode('out_of_range_page')->defaultValue(self::EXCEPTION_STRATEGY_TO_HTTP_NOT_FOUND)->end() | ||
->scalarNode('not_valid_current_page')->defaultValue(self::EXCEPTION_STRATEGY_TO_HTTP_NOT_FOUND)->end() | ||
->end() | ||
->end() | ||
->end() | ||
; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/Kunstmaan/AdminBundle/DependencyInjection/PagerfantaExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\AdminBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
/** | ||
* Container extension to bridge the configuration from WhiteOctoberPagerfantaBundle to BabDevPagerfantaBundle | ||
* NEXT_MAJOR remove class | ||
* | ||
* @deprecated since KunstmaanAdminBundle 5.9. Migrate your Pagerfanta configuration from WhiteOctoberPagerfantaBundle to BabDevPagerfantaBundle, the configuration bridge will be removed in KunstmaanAdminBundle 6.0. | ||
* | ||
* @internal | ||
*/ | ||
class PagerfantaExtension extends Extension implements PrependExtensionInterface | ||
{ | ||
public function getAlias(): string | ||
{ | ||
return 'white_october_pagerfanta'; | ||
} | ||
|
||
public function getConfiguration(array $config, ContainerBuilder $container): PagerfantaConfiguration | ||
{ | ||
return new PagerfantaConfiguration(); | ||
} | ||
|
||
public function load(array $config, ContainerBuilder $container): void | ||
{ | ||
$config = $this->processConfiguration($this->getConfiguration($config, $container), $config); | ||
|
||
$container->setParameter('white_october_pagerfanta.default_view', $config['default_view']); | ||
} | ||
|
||
public function prepend(ContainerBuilder $container): void | ||
{ | ||
$config = $this->processConfiguration($this->getConfiguration([], $container), $container->getExtensionConfig($this->getAlias())); | ||
|
||
$container->prependExtensionConfig('babdev_pagerfanta', $config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Kunstmaan/AdminBundle/Tests/DependencyInjection/Compiler/PagerfantaBridgePassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\AdminBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use Kunstmaan\AdminBundle\DependencyInjection\Compiler\PagerfantaBridgePass; | ||
use Kunstmaan\AdminBundle\DependencyInjection\PagerfantaExtension; | ||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
use Pagerfanta\View\ViewFactory; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class PagerfantaBridgePassTest extends AbstractCompilerPassTestCase | ||
{ | ||
public function testWhiteOctoberAliasedServicesAndParametersAreCreated(): void | ||
{ | ||
$this->registerService('pagerfanta.twig_extension', PagerfantaExtension::class); | ||
$this->registerService('pagerfanta.view_factory', ViewFactory::class); | ||
|
||
$this->setParameter('white_october_pagerfanta.view_factory.class', 'My\ViewFactory'); | ||
|
||
$this->compile(); | ||
|
||
$this->assertContainerBuilderHasAlias('twig.extension.pagerfanta', 'pagerfanta.twig_extension'); | ||
$this->assertContainerBuilderHasAlias('white_october_pagerfanta.view_factory', 'pagerfanta.view_factory'); | ||
$this->assertContainerBuilderHasService('pagerfanta.view_factory', 'My\ViewFactory'); | ||
} | ||
|
||
protected function registerCompilerPass(ContainerBuilder $container): void | ||
{ | ||
$container->addCompilerPass(new PagerfantaBridgePass()); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/Kunstmaan/AdminBundle/Tests/DependencyInjection/PagerfantaExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\AdminBundle\Tests\DependencyInjection; | ||
|
||
use BabDev\PagerfantaBundle\BabDevPagerfantaBundle; | ||
use BabDev\PagerfantaBundle\DependencyInjection\BabDevPagerfantaExtension; | ||
use Kunstmaan\AdminBundle\DependencyInjection\PagerfantaExtension; | ||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; | ||
use Symfony\Bundle\TwigBundle\TwigBundle; | ||
|
||
class PagerfantaExtensionTest extends AbstractExtensionTestCase | ||
{ | ||
public function testWhiteOctoberBundleConfigPrependedToBabDevBundle(): void | ||
{ | ||
$this->container->setParameter( | ||
'kernel.bundles', | ||
[ | ||
'BabDevPagerfantaBundle' => BabDevPagerfantaBundle::class, | ||
'TwigBundle' => TwigBundle::class, | ||
] | ||
); | ||
|
||
$bundleConfig = [ | ||
'default_view' => 'twitter_bootstrap', | ||
'exceptions_strategy' => [ | ||
'out_of_range_page' => 'custom', | ||
'not_valid_current_page' => 'to_http_not_found', | ||
], | ||
]; | ||
|
||
// Prepend config now to allow the prepend pass to work | ||
$this->container->prependExtensionConfig('white_october_pagerfanta', $bundleConfig); | ||
|
||
$this->load($bundleConfig); | ||
|
||
$this->assertSame([$bundleConfig], $this->container->getExtensionConfig('babdev_pagerfanta')); | ||
$this->assertContainerBuilderHasParameter('white_october_pagerfanta.default_view', $bundleConfig['default_view']); | ||
} | ||
|
||
protected function getContainerExtensions(): array | ||
{ | ||
return [ | ||
new PagerfantaExtension(), | ||
new BabDevPagerfantaExtension(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters