Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Routing] Changing RouteCollectionBuilder::import() behavior to add to the builder #16477

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

weaverryan
Copy link
Member

Q A
Bug fix? behavior change
New feature? behavior change
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

Based on conversation starting here: #15990 (comment).

// Before:
$routes->mount('/admin', $routes->import(__DIR__.'/config/admin.yml');

// After:
$routes->import(__DIR__.'/config/admin.yml', '/admin');

This makes import() actually add the RouteCollectionBuilder into itself. We didn't do this before at Fabien's request, and actually the current implementation (before this PR) is quite "clean". However, I agree with @wouterj that import() really sounds/looks like it will actually import those routes into this RouteCollectionBuilder.

This change is subjective - we just need to pick which way we like better and run full steam with it.

*
* @param mixed $resource
* @param string $prefix
* @param string $type
Copy link
Contributor

Choose a reason for hiding this comment

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

string|null

@weaverryan
Copy link
Member Author

Ping @symfony/deciders - this is totally subjective, but we should decide either way.

@henrikbjorn
Copy link
Contributor

Would it be possible to change load to be public and return a new builder instance? That way it would support both type of usage (mutable,immutable)

@weaverryan
Copy link
Member Author

@henrikbjorn The import method does return the new RouteCollectionBuilder - so you could still mutate it after it's been added:

$adminRoutes = $routes->import(__DIR__.'/config/admin.yml', '/admin');
$adminRoutes->setDefault('_locale', 'fr');

Is that what you're after? Btw, I saw your Muse test app - thanks for testing things.

@henrikbjorn
Copy link
Contributor

@weaverryan almost, i can think of cases where i want the "old" behavior where it isnt automatically added. That is what i want load() to do, and have import be load & mount.

No problem :)

@weaverryan
Copy link
Member Author

@henrikbjorn What's your use-case for that? Obviously making load() public is trivial, but we want to keep the public API as small as possible.

@henrikbjorn
Copy link
Contributor

If i wanted to build something using this class by itself then it would be a good idea to have a immutable option of loading routes. But maybe i am grasping for straws (thats a thing right?)

@weaverryan
Copy link
Member Author

@henrikbjorn Ha, it is a thing ;). I still don't quite understand the mutable versus immutable thing and what use-case you're thinking of. But not necessarily because what you're asking doesn't make sense - I may just need more info. Can you give a code example of what you might want to accomplish that isn't possible/easy with the current interface? Would the change in this PR improve things, or not matter?

@henrikbjorn
Copy link
Contributor

The change currently does exactly what is was assuming it would do eg $builder->import('@MuseBundle/Resources/routing/routing.xml') 👍

@GromNaN
Copy link
Member

GromNaN commented Nov 11, 2015

I see an inconsistency in method signatures:

function import($resource, $prefix = '/', $type = null)
function mount($prefix, RouteCollectionBuilder $builder)

I perceive $resource and $builder as similar things in this context. They both define a set of routes.

@weaverryan
Copy link
Member Author

@GromNaN I don't understand, what would you change?

@weaverryan
Copy link
Member Author

Btw, if we're going to merge this or make any other changes... it needs to happen... like yesterday :). So any constructive 👍 , 👎 or specific changes would be ideal

@henrikbjorn
Copy link
Contributor

@weaverryan he wants the $builder to be the first argument to mount, which makes sense to me.

@henrikbjorn
Copy link
Contributor

👍

@weaverryan
Copy link
Member Author

I'd still like to see this merged - as I was just thinking how import() for all other loaders (e.g. YamlFileLoader) actually imports the configuration, whereas here it really just "loads" and returns it.

@symfony/deciders can we either close or merge this?

@DavidBadura
Copy link
Contributor

This change makes it more understandable what happens 👍

@fabpot
Copy link
Member

fabpot commented Nov 23, 2015

Thank you @weaverryan.

@fabpot fabpot closed this in 57e0468 Nov 23, 2015
This was referenced Nov 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants