Skip to content
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

add a way to filter areas on route by annotation #1460

Merged
merged 1 commit into from
Feb 13, 2019

Conversation

babaorum
Copy link
Contributor

@babaorum babaorum commented Jan 8, 2019

Fix #1246

Description

A new boolean configuration is available in the areas: with_annotation.
By setting it to true, every route will be filtered by annotation.
Every route to match will need to add the @Areas with the area name.

Example

the default area would only match the testAction(), while the area2 will match both.

areas:
    default:
        path_patterns:
            - '^/api/'
        with_annotation: true
    area2:
        with_annotation: true
class ApiController
{
    /**
     * @Areas({'default', 'area2'})
     */
    public function testAction()
    {
    }

    /**
     * @Areas({'area2'})
     */
    public function test2Action()
    {
    }
}

Copy link
Collaborator

@GuilhemN GuilhemN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great, thanks!
I left a few comments :)

public function __construct(array $properties)
{
if (!array_key_exists('value', $properties) || !is_array($properties['value'])) {
throw new \InvalidArgumentException('An array of areas were expected');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was?

}

try {
$method = $this->routeReflector->controllerReflectionMethod($route);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a worth an util class, could we inline it please ?

->addArgument($areaConfig),
->setArguments(
[
new Reference('annotations.cached_reader'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

annotation_reader instead, caching is managed by symfony

@babaorum
Copy link
Contributor Author

babaorum commented Feb 5, 2019

I fixed everything according to your comments.
Let me know if you see anything else.

@GuilhemN GuilhemN merged commit b171794 into nelmio:master Feb 13, 2019
@GuilhemN
Copy link
Collaborator

GuilhemN commented Feb 13, 2019

Thank you @babaorum!

@ikleiman
Copy link

Thanks @babaorum

Worked like a charm, but had to use it with double quotes instead of single ones (as explained in https://stackoverflow.com/questions/6338178/troubleshooting-syntax-error-expected-plainvalue-got):


    /**
     * @Areas({"area2"})
     */
    public function test2Action()
    {
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an annotation to specify the area(s) of a route
3 participants