Skip to content

[Routing] Using Symfony string for routing path instead of Gedmo urlizer#1108

Merged
NoResponseMate merged 4 commits intoSylius:1.14from
loic425:using-symfony-string
Dec 19, 2025
Merged

[Routing] Using Symfony string for routing path instead of Gedmo urlizer#1108
NoResponseMate merged 4 commits intoSylius:1.14from
loic425:using-symfony-string

Conversation

@loic425
Copy link
Copy Markdown
Member

@loic425 loic425 commented Dec 5, 2025

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets
License MIT

Behat transliteration is deprecated. It's not maintained anymore.
I reused the routing_path_bc_layer that 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.

  • Configure default plural name on resource in a metadata factory without using legacy MetadataInterface.

@loic425 loic425 marked this pull request as draft December 5, 2025 11:46
@loic425 loic425 force-pushed the using-symfony-string branch 7 times, most recently from 3210bdb to 3da89d0 Compare December 8, 2025 15:51
@loic425 loic425 marked this pull request as ready for review December 8, 2025 15:51
@loic425 loic425 marked this pull request as draft December 8, 2025 15:53
@loic425 loic425 force-pushed the using-symfony-string branch 11 times, most recently from ba32bea to fdd8689 Compare December 8, 2025 19:59
@loic425 loic425 marked this pull request as ready for review December 8, 2025 20:13
@loic425 loic425 marked this pull request as draft December 9, 2025 08:41
@loic425 loic425 force-pushed the using-symfony-string branch 5 times, most recently from 6510148 to 9d78614 Compare December 10, 2025 19:55
@loic425 loic425 force-pushed the using-symfony-string branch from 9d78614 to 8e478b8 Compare December 10, 2025 19:56
@loic425 loic425 marked this pull request as ready for review December 10, 2025 20:00
gedmo-doctrine-extensions: [""]
symfony: ["6.4.*", "7.4.*"]
include:
# with Behat transliterator and Gedmo Doctrine extensions optional packages
Copy link
Copy Markdown
Member Author

@loic425 loic425 Dec 11, 2025

Choose a reason for hiding this comment

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

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')
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is inspired by API Platform code source.

$routingPathBcLayer = class_exists(Transliterator::class);
}

if ($routingPathBcLayer && !class_exists(Transliterator::class)) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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'),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

legacy is not well-named.... Maybe withBcLayerEnabledOperationRouteFactory

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Think just bcOperationRouteFactory would suffice 🤷

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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'], '{}');
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This way, we can run these tests with or without bc layer enabled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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";
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we handle the trailing slash with bc layer enabled.

]);
}

if (class_exists(Urlizer::class)) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I may have applied a reformat code...

Comment on lines +33 to +35
?InflectorInterface $inflector = null,
private readonly bool $routingBcLayerEnabled = true,
private readonly ?RegistryInterface $resourceRegistry = null,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member Author

@loic425 loic425 Dec 18, 2025

Choose a reason for hiding this comment

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

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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'], '{}');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

loic425 and others added 2 commits December 16, 2025 10:43
Co-authored-by: Jan Góralski <jan.wojciech.goralski@gmail.com>
@loic425 loic425 force-pushed the using-symfony-string branch from 4bbf54a to b7ef483 Compare December 16, 2025 19:15
@loic425 loic425 force-pushed the using-symfony-string branch from 866acd7 to ecbdd69 Compare December 18, 2025 08:03
@loic425 loic425 mentioned this pull request Dec 18, 2025
15 tasks
@NoResponseMate NoResponseMate merged commit 564f576 into Sylius:1.14 Dec 19, 2025
14 checks passed
@loic425 loic425 deleted the using-symfony-string branch December 19, 2025 08:37
NoResponseMate added a commit that referenced this pull request Dec 19, 2025
| Q               | A
| --------------- | -----
| Bug fix?        | no
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | 
| License         | MIT

Based on #1108
NoResponseMate added a commit that referenced this pull request Feb 17, 2026
#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.
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.

2 participants