Skip to content

[8.x] Removed action from SymfonyRoute options #35451

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

Closed

Conversation

TomHAnderson
Copy link
Contributor

@TomHAnderson TomHAnderson commented Dec 2, 2020

Description

Illuminate\Routing\Route::toSymfonyRoute() included two options: utf8 and action. The options do not include a compiler_class option so the default Symfony\Component\Routing\RouteCompiler will always be used. This compiler does not utilize an action parameter and, because you cannot override the RouteCompiler, I have removed that option from the toSymfonyRoute() options array.

Unit Tests

This PR removes unused code so no new unit tests would be useful. Removing the ephemera and testing with the current unit tests shows this does not affect the framework.

Discussion

Removing this unused (in Symfony) code from the Route simplifies the toSymfonyRoute() method and prevents developers from going on a wild goose chase to figure out why this code is there in the first place. There is no direct benefit to the end consumer.

The extraneous option was sent to Symfony classes so there are no Laravel unit tests which could apply to the call to the constructor of the Symfony Route class.

This change benefits the developer community around Laravel by only including code which has a purpose.

External Resources

This change is directed against the constructor of https://github.com/symfony/symfony/blob/5.x/src/Symfony/Component/Routing/Route.php#L53
and involves the route compiler https://github.com/symfony/symfony/blob/5.x/src/Symfony/Component/Routing/RouteCompiler.php
Additionally the valid options are listed in the comments of the constructor: https://github.com/symfony/symfony/blob/5.x/src/Symfony/Component/Routing/Route.php#L41

@TomHAnderson TomHAnderson changed the title Removed action from SymfonyRoute options [8.x] Removed action from SymfonyRoute options Dec 2, 2020
@TomHAnderson
Copy link
Contributor Author

It should be noted that any options passed to the toSymfonyRoute() will be available from the object. For that reason, there may be justifiable cause for the action to be passed.

// Get action from symfony route
$action = $route->toSymfonyRoute()->getOptions()['action'];

// A proper way to get the action
$action = $route->getAction();

@taylorotwell
Copy link
Member

Since this doesn't seem to be breaking anything it seems prudent to leave it be for now.

@driesvints
Copy link
Member

I've looked further into this but also can't say for sure why this is present. At the least it seems to be because of the reason you mentioned in #35451 (comment)

I agree with Taylor to let this be since it's not breaking anything atm.

@TomHAnderson
Copy link
Contributor Author

Thanks for the follow-up @driesvints I was going to let sleeping dogs lie but, anyway,

If creating a Symfony route includes the action then why not jump all the way into the pool and include the Laravel route in the Symfony route options? My reasoning is if there is value to include the action then wouldn't the whole $route be more valuable? Maybe this is reductio ad absurdum but it demonstrates the usefulness, or not, of the action.

return new SymfonyRoute(
    preg_replace('/\{(\w+?)\?\}/', '{$1}', $this->uri()), $this->getOptionalParameterNames(),
    $this->wheres, ['utf8' => true, 'action' => $this->action, 'laravelRoute' => $this],
    $this->getDomain() ?: '', [], $this->methods
);

@driesvints
Copy link
Member

@TomHAnderson Let's just leave things be here.

@driesvints
Copy link
Member

Hey @TomHAnderson. I spoke to Taylor about this again and we'd like to revisit this but only on the next release. Would you be willing to send in a PR to master? Thanks for investigating this 🙂

@TomHAnderson
Copy link
Contributor Author

TomHAnderson commented Dec 7, 2020

Sure, I'll put together a PR.

@TomHAnderson TomHAnderson deleted the hotfix/route-symfony-action branch December 7, 2020 18:57
@TomHAnderson TomHAnderson restored the hotfix/route-symfony-action branch December 7, 2020 18:57
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.

3 participants