-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle][SecurityBundle] Moved security expression providers pass logic to SecurityBundle #27611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicolas-grekas
merged 1 commit into
symfony:master
from
HeahDude:security-expression-pass
Jun 19, 2018
Merged
[FrameworkBundle][SecurityBundle] Moved security expression providers pass logic to SecurityBundle #27611
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
"symfony/dom-crawler": "~3.4|~4.0", | ||
"symfony/event-dispatcher": "~3.4|~4.0", | ||
"symfony/form": "~3.4|~4.0", | ||
"symfony/framework-bundle": "~4.1", | ||
"symfony/framework-bundle": "~4.2", | ||
"symfony/http-foundation": "~3.4|~4.0", | ||
"symfony/translation": "~3.4|~4.0", | ||
"symfony/twig-bundle": "~3.4|~4.0", | ||
|
@@ -46,7 +46,7 @@ | |
"conflict": { | ||
"symfony/var-dumper": "<3.4", | ||
"symfony/event-dispatcher": "<3.4", | ||
"symfony/framework-bundle": "<4.1.1", | ||
"symfony/framework-bundle": "<4.2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. L33 should bump to 4.2 also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
"symfony/console": "<3.4" | ||
}, | ||
"autoload": { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a guard clause now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the code remains cleans and small with one indent, I would keep a readable true condition here. I'll wait for other opinions before changing the style.