Skip to content

[RFC] Provide event for collecting routes from bundles #343

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
Koc opened this issue Mar 9, 2016 · 9 comments
Closed

[RFC] Provide event for collecting routes from bundles #343

Koc opened this issue Mar 9, 2016 · 9 comments

Comments

@Koc
Copy link

Koc commented Mar 9, 2016

It would be useful if we can add route resources files when enabling bundle in kernel with zero-config changes.

<?php

namespace MyBundle\EventListener;

class RouteCollectionEventListener
{
    public function addRoutes(BuldRouteCollectionEvent $event)
    {
        $event->add('@MyBundle/routing.yml');
        $event->add('@MyBundle/Controller', 'annotation'); // maybe we can also add priority option
    }
}

See https://github.com/modera/ModeraRoutingBundle/blob/master/Routing/Loader.php and https://github.com/modera/ModeraRoutingBundle/blob/master/README.md for similar approach

@dbu
Copy link
Member

dbu commented Mar 29, 2016

is the idea to dynamically decide which routing files to load? i am not sure if this would be in the scope of the cmf routing. our goal is to load specific routes on demand, to handle large amounts of routes that would be too much to all load at once.

symfony itself knows custom route loaders: http://symfony.com/doc/current/cookbook/routing/custom_route_loader.html - i think it would make more sense to use that instead. you could write a custom loader that triggers an event if you want to, to make things simpler than they currently are done in FOSRestBundle or SonataAdminBundle. this could be a separate RouteAutoLoaderBundle or something like that.

@Koc
Copy link
Author

Koc commented Mar 29, 2016

maybe not 100% dynamically, maybe dynamically on cache warming pass. Idea register routing from bundles without editing configuration (config.yml, routing.yml).

@dbu
Copy link
Member

dbu commented Mar 29, 2016 via email

@Koc
Copy link
Author

Koc commented Mar 29, 2016

Suggest where better locate it. Inside separate bundle or inside core or ...?

@Koc
Copy link
Author

Koc commented Mar 29, 2016

I've opened ticket here because this is feature for cms/cmf - install and enable module without config changes

@dbu
Copy link
Member

dbu commented Mar 30, 2016

i think @xabbuh introduced the feature to simply tag a service as route provider to simplify the setup. not sure if an event would fit into symfony core as well, or if its considered not enough additional value to justify adding the code.

the symfony-cmf is not so much about simplifying plugging bundles, its more about working with content data. but i came across other projects that try to make bundles more "auto-pluggable" - unfortunately don't remember the names of those.

@xabbuh
Copy link
Contributor

xabbuh commented Mar 30, 2016

@dbu I think you are talking about the feature Ryan introduced in symfony/symfony#15742. Unfortunately, this isn't documented yet (see symfony/symfony-docs#5747).

@dbu
Copy link
Member

dbu commented Mar 30, 2016

indeed, thanks and sorry for the ping xabbuh. @weaverryan do you have any input for @Koc , do you feel an event could fit into core symfony as an addition to the service tagging or is your new feature an alternative solution to the event based idea?

@wouterj
Copy link
Member

wouterj commented Mar 30, 2016

IIRC, this feature has been rejected from Core several times, as order is very important for routing (while it isn't for bundle registration). Allowing bundles to register routes means things can be messed up pretty badly because the first route that matches is taken. Also, this removes the ability to add a prefix for bundle routes.

In any way, this feature doesn't fit in the scope of the CmfRoutingBundle, so I think this issue can be closed.

@dbu dbu closed this as completed Mar 31, 2016
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

No branches or pull requests

4 participants