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

[5.5] Promote RouteGroup to first-class citizen, enabling $router->getGroups(). #20820

Conversation

DanielCoulbourne
Copy link
Contributor

I've always wanted to do more with Route groups, but because they have been primarily used as stacks of attributes which were immediately flattened and didn't persist outside of their registration, there wasn't much to do.

This PR introduces a RouteGroup object and a $groups array on Router which is a persistent registry of RouteGroups. RouteGroup objects are aware of their routes via a RouteCollection.

I also added a getGroups() method to Router.

While pretty in depth in its changes, this is just an introductory "testing the waters" PR. If this PR is merged there are lots of things that could be built on top of persistent route groups:

  • Routes could know their groups, allowing $router->getRoutes()->getRoutesByGroup()
  • Groups could be refactored to contain all of their own attributes and know their parent groups, allowing all of the "group stack" and "attribute flattening" logic to live inside RouteGroup (which seems more natural to me)

Note that the classname RouteGroup was already in use for a class of static methods relating to merging Route Group Attributes. I renamed this class to RouteGroupAttributes

Please let me know what you think of this PR. I think its a step in the right direction. I love Route Groups and would love to do more work with them, but I think they deserve a promotion.

@browner12
Copy link
Contributor

I'm not super familiar with the code here, so I can't speak to that, but the idea sounds really interesting.

@tillkruss tillkruss changed the title Promote RouteGroup to first-class citizen, enabling $router->getGroups(). [5.5] Promote RouteGroup to first-class citizen, enabling $router->getGroups(). Aug 30, 2017
@tillkruss
Copy link
Collaborator

That will have to go to v5.6 now.

@GrahamCampbell GrahamCampbell changed the title [5.5] Promote RouteGroup to first-class citizen, enabling $router->getGroups(). [5.6] Promote RouteGroup to first-class citizen, enabling $router->getGroups(). Aug 30, 2017
@DanielCoulbourne
Copy link
Contributor Author

Just noting that I don't think this actually needs to go in 5.6
There are no breaking changes and all the 5.5 tests still pass. I think this is minor enough that it can go in 5.5

@DanielCoulbourne DanielCoulbourne changed the title [5.6] Promote RouteGroup to first-class citizen, enabling $router->getGroups(). [5.5] Promote RouteGroup to first-class citizen, enabling $router->getGroups(). Sep 5, 2017
@GrahamCampbell GrahamCampbell changed the title [5.5] Promote RouteGroup to first-class citizen, enabling $router->getGroups(). [5.6] Promote RouteGroup to first-class citizen, enabling $router->getGroups(). Sep 5, 2017
@tillkruss tillkruss changed the base branch from master to 5.5 September 6, 2017 00:35
@tillkruss tillkruss changed the title [5.6] Promote RouteGroup to first-class citizen, enabling $router->getGroups(). [5.5] Promote RouteGroup to first-class citizen, enabling $router->getGroups(). Sep 6, 2017
@tillkruss
Copy link
Collaborator

I changed the branch to v5.5.

@DanielCoulbourne
Copy link
Contributor Author

Oh yeah thanks! Shoulda remembered that.

@taylorotwell
Copy link
Member

What will this enable application developers to do?

@j-shelfwood
Copy link

I believe this was tied to this package:
https://github.com/tightenco/ziggy

I'm not sure what exactly it was for, it can be found on the twenty percent time podcast. Would be nice if @DanielCoulbourne could explain though ^^

@DanielCoulbourne
Copy link
Contributor Author

DanielCoulbourne commented Sep 9, 2017

@taylorotwell This pull itself will only enable devs to get the route groups. Probably not the most useful feature on its own. But like I said above this is kind of a "test the waters" PR to see if you're even open to this sort of thing. If you are, there are a few ancillary things I'd like to PR in that I do have a need for:

The biggest one is building $routeCollection->getRoutesByGroup() which would be SUPER useful to me in building out configuration options for Ziggy (but also could be useful to anyone who wants to do stuff with group-structured routes). This could even allow me to write a Route::macro that would let me do something like Route::getResources() (since resources appear to just be groups with a wrapper function) which would be awesome if someone (who may or may not be me) was dreaming of building a frontend client for resources.

@m1guelpf
Copy link
Contributor

m1guelpf commented Sep 9, 2017

For reference, this PR, its implications, etc. were discussed in Twenty Percent Time.

@taylorotwell
Copy link
Member

Could you take a look at the conflicts on this? I plan to pull it down today to play with it.

@DanielCoulbourne
Copy link
Contributor Author

DanielCoulbourne commented Sep 12, 2017

Yep just a sec

(I broke something)

@DanielCoulbourne
Copy link
Contributor Author

@taylorotwell fixed. Sorry about that. I was trying to resolve merge conflicts in the branch I used for the 5.4 version and lost my mind for a bit. Derp.

@m1guelpf
Copy link
Contributor

@taylorotwell Any updates?

@DanielCoulbourne
Copy link
Contributor Author

@m1guelpf We've been talking back and forth on it a bit. I know Taylor has taken a look at it.

@GrahamCampbell
Copy link
Member

There definitely are breaking changes. Protected methods have been deleted from non-final classes. Should go to 5.6.

@taylorotwell
Copy link
Member

Going to hold off for now until I see the end-goal macro implemented using this PR's functionality. Without that I'm scared we don't have hard proof this acutally solves what we're trying to achieve.

@DanielCoulbourne
Copy link
Contributor Author

Challenge accepted 😛
It's gonna be a week or two though.

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.

None yet

7 participants