-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
101 additions
and
6 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
35 changes: 35 additions & 0 deletions
35
src/DependencyInjection/Compiler/TwigStringExtensionCompilerPass.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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Twig\Extra\String\StringExtension; | ||
|
||
final class TwigStringExtensionCompilerPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
foreach ($container->findTaggedServiceIds('twig.extension') as $id => $attributes) { | ||
if (StringExtension::class === $container->getDefinition($id)->getClass()) { | ||
return; | ||
} | ||
} | ||
|
||
$definition = new Definition(StringExtension::class); | ||
$definition->addTag('twig.extension'); | ||
$container->setDefinition(StringExtension::class, $definition); | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
tests/DependencyInjection/Compiler/TwigStringExtensionCompilerPassTest.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,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
use Sonata\AdminBundle\DependencyInjection\Compiler\TwigStringExtensionCompilerPass; | ||
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Twig\Extra\String\StringExtension; | ||
|
||
class TwigStringExtensionCompilerPassTest extends AbstractCompilerPassTestCase | ||
{ | ||
public function testLoadTwigStringExtension(): void | ||
{ | ||
$this->compile(); | ||
|
||
$this->assertContainerBuilderHasServiceDefinitionWithTag(StringExtension::class, 'twig.extension'); | ||
} | ||
|
||
public function testLoadTwigStringExtensionWithExtraBundle(): void | ||
{ | ||
$definition = new Definition(StringExtension::class); | ||
$definition->addTag('twig.extension'); | ||
$this->container->setDefinition('twig.extension.string', $definition); | ||
$this->compile(); | ||
|
||
$this->assertContainerBuilderHasServiceDefinitionWithTag('twig.extension.string', 'twig.extension'); | ||
$this->assertContainerBuilderNotHasService(StringExtension::class); | ||
} | ||
|
||
protected function registerCompilerPass(ContainerBuilder $container): void | ||
{ | ||
$container->addCompilerPass(new TwigEnvironmentPass()); | ||
$container->addCompilerPass(new TwigStringExtensionCompilerPass()); | ||
} | ||
} |
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