-
Notifications
You must be signed in to change notification settings - Fork 155
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
Sylius route with attributes #334
Sylius route with attributes #334
Conversation
e2ba131
to
c373b7f
Compare
fba67b2
to
cc1ae18
Compare
@@ -13,14 +13,21 @@ | |||
|
|||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | |||
<services> | |||
<defaults public="true" /> | |||
<defaults public="false" /> |
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.
Keeping it public would make it more coherent with Sylius itself
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.
done
<argument type="service" id="sylius.resource_registry" /> | ||
<argument type="service"> | ||
<service class="Sylius\Bundle\ResourceBundle\Routing\RouteFactory" /> | ||
</argument> | ||
<tag name="routing.loader" /> | ||
</service> | ||
|
||
<service id="sylius.routing.loader.attributes" class="Sylius\Bundle\ResourceBundle\Routing\AttributesLoader"> | ||
<!-- TODO make it configurable --> |
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.
What do you mean?
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.
I forgot to remove the TODO :)
That's done.
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.
I just have to remove the TODO.
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.
done for this one.
$syliusOptions['serialization_version'] = $arguments['serializationVersion']; | ||
} | ||
|
||
$route = new Route( |
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.
Probably \Sylius\Bundle\ResourceBundle\Routing\RouteFactory
should be used. But I'm even thinking about createRoute
method extraction from \Sylius\Bundle\ResourceBundle\Routing\ResourceLoader
or making it public, so it could be here. Won't it make sense?
sylius_resource: | ||
resource: 'sylius.routing.loader.attributes' | ||
type: service |
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.
Do I understand i correctly, that without this configuration, attributes won't work?
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.
Yes without this configuration, the routes would not be generated.
But It should be added on a Symfony flex recipe.
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.
Shouldn't it be part of sylius_resource configuration tree?
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.
That's not possible.
On ApiPlatform it's done on a recipe.
https://github.com/symfony/recipes/blob/master/api-platform/core/2.5/config/routes/api_platform.yaml
But we have to mention it on documentation.
|
||
} | ||
|
||
private function getResourcesByPath(string $path): array |
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 class or its parent seems to be a great candidate for extraction as well. This should be probably tested with spec/phpunit to check its finding behaviour. Right now, a lot is happening in this class alone. Is it fetched from some other project? Could it make sense, to reuse this logic somewhere else?
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.
Yes it's extracted from here
https://github.com/symfony/symfony/blob/6.1/src/Symfony/Component/Validator/Command/DebugCommand.php#L172
It's my only one contribution on Symfony 👍
really nice work! |
b8ea7f6
to
43e42a5
Compare
return $reflectionClass->getAttributes($attributeName); | ||
} | ||
|
||
private function getReflectionClasses(): iterable |
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.
I would extract this one to separate service/method as well, as it is 100% duplicated. But it is good to go for me as well
@@ -0,0 +1,7 @@ | |||
sylius_crud_routes: |
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.
As this configuration is required to make route attribute work, we should probably mention it in some docs or UPGRADE file (or both 💃)
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.
I'd like to add it on a documentation PR. Cause it's not documented yet.
Co-authored-by: Łukasz Chruściel <lchrusciel@gmail.com>
04f5653
to
732f512
Compare
58994e1
to
6c8092b
Compare
Thanks Loïc! Spectacular work 🎉 🚀 |
This PR was merged into the 1.9-dev branch
This PR was merged into the 1.9-dev branch
Crud routes
Single routes