Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DI] Deprecate XML services without ID#22903

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:3.4fromro0NL:di/xml-service
May 25, 2017
Merged

[DI] Deprecate XML services without ID#22903

fabpot merged 1 commit intosymfony:3.4fromro0NL:di/xml-service
May 25, 2017

Conversation

ro0NL
Copy link
Contributor

QA
Branch?3.4
Bug fix?no, confusing though
New feature?yes
BC breaks?no
Deprecations?yes
Tests pass?yes
Fixed tickets#...
LicenseMIT
Doc PRsymfony/symfony-docs#...

On slack someone had a issue with class named services;

So, probably should have done this sooner, I stepped through with a debugger and it looks like \Symfony\Component\DependencyInjection\Loader\XmlFileLoader::processAnonymousServices assigns a sha256 to services that don't have any IDs
When my manually wired service is registered, it has an ID that looks like 1_344b468f6069ffe8c32092409d99c59abc218f41071ce4c4230c198876129bc0, so it doesn't override the auto-loaded one
I swear I read that IDs default to the class name now...

The fix was easy; doing<service/> instead of<service/>. However the thing is... i made the exact same mistake trying to reproduce 😅

I think given the recent developments (dropping type based autowiring and class named services) it makes sense to force XML service to specify an ID attribute (the top level ones). This would be consistent with YAML and PHP as well.

Fixing deprecations is also easy, just changeclass attribute toid like i've done for the frameworkbundle in this PR.

Any thoughts?

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment
edited
Loading

Choose a reason for hiding this comment

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

👍 makes sense to me

++$num;
}
if ($num) {
@trigger_error(sprintf('Anonymous services (%d) in file %s are deprecated since 3.4 and wont be supported in 4.0', $num, $file), E_USER_DEPRECATED);

Choose a reason for hiding this comment

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

imho, no need for $num. To be a bit more explicit, I propose:
Anonymous services are deprecated since Symfony 3.4, the "id" attribute will be required in version 4.0 in %s.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

it will allow for missing deprecations more easy that way, but that's more or less related to loose comparison of those.

Updated :)

@ro0NL
Copy link
ContributorAuthor

failures unrelated.

@@ -412,6 +412,10 @@ private function processAnonymousServices(\DOMDocument $xml, $file, $defaults)

// anonymous services "in the wild"
if (false !== $nodes = $xpath->query('//container:services/container:service[not(@id)]')) {
if ($nodes->length) {
@trigger_error(sprintf('Anonymous services are deprecated since Symfony 3.4, the "id" attribute will be required in version 4.0 in %s.', $file), E_USER_DEPRECATED);
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@nicolas-grekas worth mentioning this only applies to outlined anon. services (top level, non-inlined... how should we call that?)

Choose a reason for hiding this comment

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

Top-level anonymous services... then?

ro0NL reacted with thumbs up emoji
@nicolas-grekasnicolas-grekas changed the base branch frommaster to3.4May 25, 2017 08:02
@@ -11,5 +16,5 @@ Finder
Validator
---------

*not setting the `strict` option of the `Choice` constraint to `true` is
*Not setting the `strict` option of the `Choice` constraint to `true` is
Copy link
Member

Choose a reason for hiding this comment

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

should IMO be reverted as the sentence does not end with a dot

@xabbuh
Copy link
Member

Do we still have a test which ensures that deprecations are not triggered for nested anonymous definitions?

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedMay 25, 2017
edited
Loading

Yep :)https://github.com/symfony/symfony/pull/22903/files#diff-25d0b562ad1c177bac8f4f9d0247b2acR7

it's tricky though due loose comparison of deprecations; if it triggered we wouldnt catch it (before it did by including the no. of occurences)

@xabbuh
Copy link
Member

@ro0NL But this one is only tested in a@legacy test. So we would never notice when it accidentally triggered a deprecation.

@@ -230,6 +230,17 @@ public function testLoadAnonymousServices()
$this->assertSame($fooArgs[0], $barArgs[0]);
}

/**
* @group legacy
* @expectedDeprecation Top-level anonymous services are deprecated since Symfony 3.4, the "id" attribute will be required in version 4.0 in %sservices_without_id.xml.
Copy link
Member

@xabbuhxabbuhMay 25, 2017
edited
Loading

Choose a reason for hiding this comment

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

the%s seems to be a left-over from thesprintf pattern

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

it includes an absolute path, so this deals with phpunit'sassertStringMatchesFormat

xabbuh reacted with thumbs up emoji
@@ -412,6 +412,10 @@ private function processAnonymousServices(\DOMDocument $xml, $file, $defaults)

// anonymous services "in the wild"
if (false !== $nodes = $xpath->query('//container:services/container:service[not(@id)]')) {
if ($nodes->length) {
@trigger_error(sprintf('Top-level anonymous services are deprecated since Symfony 3.4, the "id" attribute will be required in version 4.0 in %s.', $file), E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

maybe we should include the class in the deprecation message to make it easier to find the place

sstok reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

currently it triggers one deprecation per file, kinda like that; it goes away after you solved everything. Also class can be empty... not helping :)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@ro0NL
Copy link
ContributorAuthor

@xabbuh extra test added

@fabpot
Copy link
Member

Thank you@ro0NL.

@fabpotfabpot merged commitb8c68da intosymfony:3.4May 25, 2017
fabpot added a commit that referenced this pull requestMay 25, 2017
This PR was merged into the 3.4 branch.Discussion----------[DI] Deprecate XML services without ID| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | no, confusing though| New feature?  | yes| BC breaks?    | no| Deprecations? | yes| Tests pass?   | yes| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->| License       | MIT| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->On slack someone had a issue with class named services;> So, probably should have done this sooner, I stepped through with a debugger and it looks like \Symfony\Component\DependencyInjection\Loader\XmlFileLoader::processAnonymousServices assigns a sha256 to services that don't have any IDs> When my manually wired service is registered, it has an ID that looks like 1_344b468f6069ffe8c32092409d99c59abc218f41071ce4c4230c198876129bc0, so it doesn't override the auto-loaded one> I swear I read that IDs default to the class name now...The fix was easy; doing `<service/>` instead of `<service/>`. However the thing is... i made the exact same mistake trying to reproduce 😅I think given the recent developments (dropping type based autowiring and class named services) it makes sense to force XML service to specify an ID attribute (the top level ones). This would be consistent with YAML and PHP as well.Fixing deprecations is also easy, just change `class` attribute to `id` like i've done for the frameworkbundle in this PR.Any thoughts?Commits-------b8c68da [DI] Deprecate XML services without ID
@ro0NLro0NL deleted the di/xml-service branchMay 26, 2017 07:13
@backbone87
Copy link
Contributor

Is it possible to allow unnamed toplevel services, which will be implicitly named after the class name?
So that<service> will generate a service of classFoo namedFoo?
Imho the current behavior is quite counter intuitive since one expect with an unnamed toplevel service to be implicitly assigned the class name. If there are multiple unnamed top level services an error should be thrown during compilation.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@xabbuhxabbuhxabbuh approved these changes

@ogizanagiogizanagiogizanagi approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
3.4
Development

Successfully merging this pull request may close these issues.

7 participants
@ro0NL@xabbuh@fabpot@backbone87@nicolas-grekas@ogizanagi@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp