Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #27611 [FrameworkBundle][SecurityBundle] Moved security expre…
…ssion providers pass logic to SecurityBundle (HeahDude) This PR was merged into the 4.2-dev branch. Discussion ---------- [FrameworkBundle][SecurityBundle] Moved security expression providers pass logic to SecurityBundle | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ~ | License | MIT | Doc PR | ~ Commits ------- a8017be [FrameworkBundle][SecurityBundle] Moved security expression providers pass logic to SecurityBundle
- Loading branch information
Showing
9 changed files
with
164 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
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
37 changes: 37 additions & 0 deletions
37
...Bundle/SecurityBundle/DependencyInjection/Compiler/AddExpressionLanguageProvidersPass.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,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Registers the expression language providers. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class AddExpressionLanguageProvidersPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if ($container->has('security.expression_language')) { | ||
$definition = $container->findDefinition('security.expression_language'); | ||
foreach ($container->findTaggedServiceIds('security.expression_language_provider', true) as $id => $attributes) { | ||
$definition->addMethodCall('registerProvider', array(new Reference($id))); | ||
} | ||
} | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
...urityBundle/Tests/DependencyInjection/Compiler/AddExpressionLanguageProvidersPassTest.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 | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class AddExpressionLanguageProvidersPassTest extends TestCase | ||
{ | ||
public function testProcessForSecurity() | ||
{ | ||
$container = new ContainerBuilder(); | ||
$container->addCompilerPass(new AddExpressionLanguageProvidersPass()); | ||
|
||
$definition = new Definition('\stdClass'); | ||
$definition->addTag('security.expression_language_provider'); | ||
$container->setDefinition('some_security_provider', $definition->setPublic(true)); | ||
|
||
$container->register('security.expression_language', '\stdClass')->setPublic(true); | ||
$container->compile(); | ||
|
||
$calls = $container->getDefinition('security.expression_language')->getMethodCalls(); | ||
$this->assertCount(1, $calls); | ||
$this->assertEquals('registerProvider', $calls[0][0]); | ||
$this->assertEquals(new Reference('some_security_provider'), $calls[0][1][0]); | ||
} | ||
|
||
public function testProcessForSecurityAlias() | ||
{ | ||
$container = new ContainerBuilder(); | ||
$container->addCompilerPass(new AddExpressionLanguageProvidersPass()); | ||
|
||
$definition = new Definition('\stdClass'); | ||
$definition->addTag('security.expression_language_provider'); | ||
$container->setDefinition('some_security_provider', $definition->setPublic(true)); | ||
|
||
$container->register('my_security.expression_language', '\stdClass')->setPublic(true); | ||
$container->setAlias('security.expression_language', 'my_security.expression_language'); | ||
$container->compile(); | ||
|
||
$calls = $container->getDefinition('my_security.expression_language')->getMethodCalls(); | ||
$this->assertCount(1, $calls); | ||
$this->assertEquals('registerProvider', $calls[0][0]); | ||
$this->assertEquals(new Reference('some_security_provider'), $calls[0][1][0]); | ||
} | ||
} |
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