[Routing] Using Symfony string for routing path instead of Gedmo urlizer#1108
[Routing] Using Symfony string for routing path instead of Gedmo urlizer#1108NoResponseMate merged 4 commits intoSylius:1.14from
Conversation
3210bdb to
3da89d0
Compare
ba32bea to
fdd8689
Compare
6510148 to
9d78614
Compare
9d78614 to
8e478b8
Compare
| gedmo-doctrine-extensions: [""] | ||
| symfony: ["6.4.*", "7.4.*"] | ||
| include: | ||
| # with Behat transliterator and Gedmo Doctrine extensions optional packages |
There was a problem hiding this comment.
I started here a new way to handle optional packages.
I plan to remove all of them from dev requirements and add tests with them.
This way, we are sure they are really optional. Moreover we are able to support a new version of Symfony without waiting for their SF8 support.
| ->booleanNode('routing_path_bc_layer') | ||
| ->defaultTrue() | ||
| ->booleanNode('routing_path_bc_layer')->end() | ||
| ->scalarNode('path_segment_name_generator') |
There was a problem hiding this comment.
this is inspired by API Platform code source.
| $routingPathBcLayer = class_exists(Transliterator::class); | ||
| } | ||
|
|
||
| if ($routingPathBcLayer && !class_exists(Transliterator::class)) { |
There was a problem hiding this comment.
Cause Behat Transliterator is moved to optional packages (it's deprecated), using another system to urlize might change the routing path. That's why I decided to use the existing routing_path_bc_layer key that we introduced on this branch which has no release yet.
| ]); | ||
|
|
||
| $services->set('sylius.resource_metadata_collection.factory.plural_name', PluralNameResourceMetadataCollectionFactory::class) | ||
| ->decorate('sylius.resource_metadata_collection.factory', null, 300) |
There was a problem hiding this comment.
we can reuse the same priority as the next one. It doesn't matter.
and of course, if this is configured before, it will be first.
| ->private() | ||
| ->args([service('sylius.routing.factory.operation_route_path_factory')]); | ||
| ->args([ | ||
| service('sylius.routing.factory.operation_route_path_factory'), |
There was a problem hiding this comment.
OperationRouteFactory is experimental and have been introduced recently.
| $this->routePathFactory = $this->createMock(OperationRoutePathFactoryInterface::class); | ||
| $this->operationRouteFactory = new OperationRouteFactory($this->routePathFactory); | ||
| $this->operationRouteFactory = new OperationRouteFactory($this->routePathFactory, new DashPathSegmentNameGenerator(), false); | ||
| $this->legacyOperationRouteFactory = new OperationRouteFactory($this->routePathFactory, new DashPathSegmentNameGenerator(), true); |
There was a problem hiding this comment.
legacy is not well-named.... Maybe withBcLayerEnabledOperationRouteFactory
There was a problem hiding this comment.
Think just bcOperationRouteFactory would suffice 🤷
There was a problem hiding this comment.
done, thank you for the proposal.
| $this->markAsSkippedIfNecessary(); | ||
|
|
||
| $this->client->request('POST', '/blog-posts/', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); | ||
| $this->client->request('POST', $this->isRoutingPathBcLayerEnabled() ? '/blog-posts/' : 'blog-posts', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); |
There was a problem hiding this comment.
This way, we can run these tests with or without bc layer enabled.
There was a problem hiding this comment.
Personally, I'd be for extracting these cases into separate tests (similar to OperationRouteFactoryTest), as it would be easier to track and remove them after the BC layer goes away.
There was a problem hiding this comment.
Done, I agree, this is better.
| $this->assertResponseStatusCodeSame(Response::HTTP_OK); | ||
| $this->assertResponseHeaderSame('content-type', 'application/json'); | ||
|
|
||
| $selfHref = $this->isRoutingPathBcLayerEnabled() ? "\/v1\/comic-books\/?page=1&limit=10" : "\/v1\/comic-books?page=1&limit=10"; |
There was a problem hiding this comment.
we handle the trailing slash with bc layer enabled.
| ]); | ||
| } | ||
|
|
||
| if (class_exists(Urlizer::class)) { |
There was a problem hiding this comment.
No more Symfony APP_ENV usage which was too much complicated.
We now handle the configuration depending on the optional packages that are installed.
| ### FROM `1.12.x` to `1.13.x` | ||
|
|
||
| The `Sylius\Resource\Exception\VariantWithNoOptionsValuesException` and `Sylius\Component\Resource\Exception\VariantWithNoOptionsValuesException` | ||
| The `Sylius\Resource\Exception\VariantWithNoOptionsValuesException` and |
There was a problem hiding this comment.
I may have applied a reformat code...
| ?InflectorInterface $inflector = null, | ||
| private readonly bool $routingBcLayerEnabled = true, | ||
| private readonly ?RegistryInterface $resourceRegistry = null, |
There was a problem hiding this comment.
The first 2 don't seem to need the default values; the last one is questionable, though it is set within the service definition.
Is it possible to not have the resource registry declared?
There was a problem hiding this comment.
I've changed the inflector to be mandatory.
For the last one. I keep it like this, cause we already know that argument will be removed when bc layer will be removed.
Moreover, we don't know if we'll use that registry forever. It uses the MetadataInterface but we have the new ResourceMetadata system.
| $this->routePathFactory = $this->createMock(OperationRoutePathFactoryInterface::class); | ||
| $this->operationRouteFactory = new OperationRouteFactory($this->routePathFactory); | ||
| $this->operationRouteFactory = new OperationRouteFactory($this->routePathFactory, new DashPathSegmentNameGenerator(), false); | ||
| $this->legacyOperationRouteFactory = new OperationRouteFactory($this->routePathFactory, new DashPathSegmentNameGenerator(), true); |
There was a problem hiding this comment.
Think just bcOperationRouteFactory would suffice 🤷
| $this->markAsSkippedIfNecessary(); | ||
|
|
||
| $this->client->request('POST', '/blog-posts/', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); | ||
| $this->client->request('POST', $this->isRoutingPathBcLayerEnabled() ? '/blog-posts/' : 'blog-posts', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); |
There was a problem hiding this comment.
Personally, I'd be for extracting these cases into separate tests (similar to OperationRouteFactoryTest), as it would be easier to track and remove them after the BC layer goes away.
Co-authored-by: Jan Góralski <jan.wojciech.goralski@gmail.com>
4bbf54a to
b7ef483
Compare
866acd7 to
ecbdd69
Compare
| Q | A | --------------- | ----- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | | License | MIT Based on #1108
#1151) …names | Q | A | --------------- | ----- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | | License | MIT We introduced the PathSegmentNameGeneratorInterface in #1108, but we do not use it when using the operation short name to generate the route path. You can look at the UPGRADE.md for more details.
Behat transliteration is deprecated. It's not maintained anymore.
I reused the
routing_path_bc_layerthat we introduced in this branch that have no release yet.Why reusing this one? Cause it might have a difference in the plurialization. So it could lead to a path change.