8000 [Routing][Translation] Assert return value for PHP configuration by ro0NL · Pull Request #23522 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Routing][Translation] Assert return value for PHP configuration #23522

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
wants to merge 2 commits into from
Closed

[Routing][Translation] Assert return value for PHP configuration #23522

wants to merge 2 commits into from

Conversation

ro0NL
Copy link
Contributor
@ro0NL ro0NL commented Jul 15, 2017
Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #23518
License MIT
Doc PR symfony/symfony-docs#...

@ro0NL ro0NL changed the title [Routing] Assert return value for PHP configuration [Routing][Translation] Assert return value for PHP configuration Jul 15, 2017
@@ -37,6 +37,10 @@ public function load($resource, $locale, $domain = 'messages')

$messages = require $resource;

if (!is_array($messages)) {
throw new \UnexpectedValueException(sprintf('PHP routing configuration must return an array, got "%s" in "%s".', is_object($messages) ? get_class($messages) : gettype($messages), $resource));
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo. It's not about routing here 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was faster.. was i?

Copy link
Contributor

Choose a reason for hiding this comment

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

@xabbuh
Copy link
Member
xabbuh commented Jul 15, 2017

Do any of the other PHP config file loaders have the same behaviour and could profit from such a change too?

@ro0NL
Copy link
Contributor Author
ro0NL commented Jul 15, 2017

Think we're good. Serializer/Validator dont have php file loaders. DI doesnt rely on any return value (strictly it could assert null though, but i dont think we should :))

@fabpot
Copy link
Member
fabpot commented Jul 16, 2017

I'm 👎 on this one. We don't do such check anywhere else in the code and we rejected similar PRs (not on this specific use case) in the past. The linked ticket is about something very different anyway. The routing directory is only about the router configuration as well files are automatically loaded from there. The same goes for the packages directory by the way. That's a convention that should be documented.

@ro0NL
Copy link
Contributor Author
ro0NL commented Jul 16, 2017

It doesnt hurt.. but i see your point. It's a safeguard for sure.

I do like the better error though, given it contains a clear file ref. But that can be found in trace as well.

Closing for now as the issue is fixed.

@ro0NL ro0NL closed this Jul 16, 2017
@ro0NL ro0NL deleted the routing/phpfile branch July 16, 2017 10:49
@javiereguiluz
Copy link
Member

@ro0NL you closed this PR too fast. I'd love to discuss about this a bit more :(


Adding features for DX is tricky. Let me show you two quick examples:

  1. In [DI] Allow imports in string format for YAML #22176 you proposed a simplification for imports. The change is great ... but for DX I don't think is that great. The reason is that it creates "a divide" because it adds an alternative solution for a well-known problem.

Which format should we show in the Symfony Docs? Both? Very verbose! Only one of them? But which one !? Moreover, people will start using any of those solutions interchangeably, so applications will use both formats and will be a bit more confusing. Besides, this adds another problem: can I mix both formats in the same file? If yes, it may be confusing. If no, why not? etc.

  1. In this case, the proposed solution is to improve docs. But for DX, I think it's better to show an immediate and precise error message that explains the problem and how to solve it.

@ro0NL
Copy link
Contributor Author
ro0NL commented Jul 16, 2017

Fair points!

For this PR, i closed it for the same reason as #19960. We dont really have to care, that's reasonable :)

For #22176, i hope we can settle with it as is. Errors are annoying, lets try not to add them :P for the end user it doesnt matter at least. Besides it works the same as DI service tags in yaml.

I personally favor short notation, and use long if needed. So i would do that in docs; not saying we should update all current docs - we could though - but we do need to mention it somewhere in 3.4 i guess.

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.

6 participants
0