8000 [DI][DX] Do not map id to class for global classes by ogizanagi · Pull Request #21453 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI][DX] Do not map id to class for global classes #21453

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

Merged
merged 1 commit into from
Jan 29, 2017
Merged

[DI][DX] Do not map id to class for global classes #21453

merged 1 commit into from
Jan 29, 2017

Conversation

ogizanagi
Copy link
Contributor
@ogizanagi ogizanagi commented Jan 29, 2017
Q A
Branch? master
Bug fix? yesish
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #21380
License MIT
Doc PR N/A

Using a global classname as service id without specifying the definition class attribute won't work anymore after this, in the benefit of properly throwing an exception at compilation time for a misconfigured service. Service ids could previously be wrongly interpreted as a class name.

So:

services:
    app_bar:
        arguments: ['foo']

will now properly result into:

Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\RuntimeException: The definition for "app_bar" has no class.

at compilation time.

@carsonbot carsonbot added Status: Needs Review DependencyInjection DX DX = Developer eXperience (anything that improves the experience of using Symfony) Bug labels Jan 29, 2017
@nicolas-grekas
Copy link
Member

👍 looks sensible to me

@xabbuh
Copy link
Member
xabbuh commented Jan 29, 2017

👍

Copy link
Contributor
@theofidry theofidry left a comment

Choose a reason for hiding this comment

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

👌

/**
* @dataProvider provideInvalidClassId
*/
public function testWontResolveClassFromId($serviceId)
Copy link
Contributor

Choose a reason for hiding this comment

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

is it a Symfony convention to put the providers before the test method? (I personally tend to put them all as the last ones)

Copy link
Member

Choose a reason for hiding this comment

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

Actually, the Symfyon "convention" is to put the provider just after the test using it.

Copy link
Contributor Author
@ogizanagi ogizanagi Jan 29, 2017

Choose a reason for hiding this comment

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

It's a personal preference. I prefer showing the dataset before the testcase itself, as I find it more readable like this (the test case might be long, so having the dataset right before the method allows to quickly see the tested data, whereas having it after the method may not fit your screen). It's totally arguable.

Should I change that?

Copy link
Member

Choose a reason for hiding this comment

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

As this is Symfony code, there is personal preference, but consistency with the code base. So, I would indeed change that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough :)
Done.

@fabpot
Copy link
Member
fabpot commented Jan 29, 2017

Thank you @ogizanagi.

@fabpot fabpot merged commit bb87030 into symfony:master Jan 29, 2017
fabpot added a commit that referenced this pull request Jan 29, 2017
…anagi)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI][DX] Do not map id to class for global classes

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yesish
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21380
| License       | MIT
| Doc PR        | N/A

Using a global classname as service id without specifying the definition class attribute won't work anymore after this, in the benefit of properly throwing an exception at compilation time for a misconfigured service. Service ids could previously be wrongly interpreted as a class name.

So:
```yml
services:
    app_bar:
        arguments: ['foo']
```

will now properly result into:
> Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\RuntimeException: The definition for "app_bar" has no class.

at compilation time.

Commits
-------

bb87030 [DI][DX] Do not map id to class for global classes
@ogizanagi ogizanagi deleted the fix/di/dx/no_global_class_id branch January 29, 2017 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug DependencyInjection DX DX = Developer eXperience (anything that improves the experience of using Symfony) Status: Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0