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] Optional class for named services#21133

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 2 commits intosymfony:masterfromnicolas-grekas:class-service
Jan 7, 2017

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedJan 2, 2017
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?yes
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PR-

Continues#20264:

From@hason:

I prefer class named services (in applications) because naming things are too hard:

services:Vendor\Namespace\Class:class:Vendor\Namespace\Classautowire:true

This PR solves redundant parameter for class:

services:Vendor\Namespace\Class:autowire:true

Inspirations:https://laravel.com/docs/5.3/container,#18268,http://php-di.org/,

theofidry, dunglas, mnapoli, tyx, noniagriconomie, and TomasVotruba reacted with thumbs up emojimnapoli and TomasVotruba reacted with hooray emoji
return;
}
if (null !==$this->resolveClassPass) {
$this->resolveClassPassChanges =$this->resolveClassPass->getChanges();
Copy link
Member

Choose a reason for hiding this comment

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

this property should be reset at the end of processing to release memory

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

fixed

Copy link
Member

Choose a reason for hiding this comment

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

Did you forget to push the change or do I miss something? I don't see where it is reset.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Saw it now.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

in fact, I removed the property completely for a local variable instead

@nicolas-grekasnicolas-grekasforce-pushed theclass-service branch 2 times, most recently fromaf7dfda to5def4a7CompareJanuary 2, 2017 16:09
* @param string $id
*
* @return string
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

What aboutgetRawId() orgetOriginalId()?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

bof :)

Copy link
Contributor

Choose a reason for hiding this comment

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

But doescase full id really exists in english ?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, if anything it should becasefullId (orgetCasefullId). But I like@theofidry'scaseSensitiveId more 👍

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

updated to caseSensitive

GuilhemN reacted with thumbs up emoji

unset($this->definitions[$id],$this->aliasDefinitions[$id]);
if ($id !==$caseFullId) {
$this->caseFullIds[$id] =$caseFullId;
Copy link
Contributor

Choose a reason for hiding this comment

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

caseSensitiveIds?

GuilhemN and wouterj reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

👍 seems more obvious what is meant

*/
private$envCounters =array();

/**
Copy link
Member

Choose a reason for hiding this comment

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

string[] does not cover arrays where keys are no integers, does it?

return$this->getDefinition($id);
}

/**
Copy link
Member

Choose a reason for hiding this comment

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

I would remove the "if any" part because we always return the id that was used when defining the definition. This makes it look likenull might be returned in some cases too.

@nicolas-grekasnicolas-grekasforce-pushed theclass-service branch 4 times, most recently fromf18bbe7 to1d766abCompareJanuary 3, 2017 08:18
@nicolas-grekasnicolas-grekas changed the title [DI] Optional class for class named services[DI] Optional class for named servicesJan 3, 2017
@nicolas-grekasnicolas-grekasforce-pushed theclass-service branch 3 times, most recently from4b7cd67 to01afe39CompareJanuary 3, 2017 08:44
foreach ($nodesas$node) {
// give it a unique name
$id =sprintf('%s_%d',hash('sha256',$file), ++$count);
$id =sprintf('%d_%s',++$count,hash('sha256',$file));
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

just made these changes so that anonymous classes won't have their class set to a random string (+ added corresponding regexp check in ResolveClassPass)

Copy link
Member

Choose a reason for hiding this comment

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

Why hashing it? Wouldn't it be more explicit with the plain file name?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

not related to this PR :)

dunglas reacted with thumbs up emoji
if ($definitioninstanceof ChildDefinition ||$definition->isSynthetic() ||null !==$definition->getClass()) {
continue;
}
if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/',$id)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be covered by a test?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

covered now

Copy link
Contributor

Choose a reason for hiding this comment

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

thank you 👍

@nicolas-grekasnicolas-grekasforce-pushed theclass-service branch 2 times, most recently from68e9588 to405b151CompareJanuary 3, 2017 17:39

unset($this->definitions[$alias]);
if ($alias !==$caseSensitiveAlias) {
$this->caseSensitiveIds[$alias] =$caseSensitiveAlias;
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need the entry for aliases or could we just remove existing entries here?

Copy link
MemberAuthor

@nicolas-grekasnicolas-grekasJan 3, 2017
edited
Loading

Choose a reason for hiding this comment

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

For completeness yes: we track any id, wherever it comes from

@xabbuh
Copy link
Member

👍

Status: Reviewed

publicfunctionset($id,$service)
{
$id =strtolower($id);
$caseSensitiveId = (string)$id;
Copy link
Member

Choose a reason for hiding this comment

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

Why do you add a cast here?

Copy link
Member

@wouterjwouterjJan 7, 2017
edited
Loading

Choose a reason for hiding this comment

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

Probably to be BC with the previous behaviour: It was possible to pass e.g. an object with__toString() as$id asstrtolower() cast everything to a string.

Copy link
Member

Choose a reason for hiding this comment

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

If that's the reason, I would revert this as$id is documented as being a string.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

reverted

@fabpot
Copy link
Member

Thank you@nicolas-grekas.

@fabpotfabpot merged commita18c4b6 intosymfony:masterJan 7, 2017
fabpot added a commit that referenced this pull requestJan 7, 2017
…-grekas)This PR was merged into the 3.3-dev branch.Discussion----------[DI] Optional class for named services| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | yes| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -Continues#20264:- makes the id-to-class mapping context-free (no `class_exist` check),- deals with ChildDefinition (which should not have this rule applied on them),- deprecates FactoryReturnTypePass as discussed on slack and reported in this comment:#19191 (comment)From@hason:> I prefer class named services (in applications) because naming things are too hard:``` yamlservices:    Vendor\Namespace\Class:        class: Vendor\Namespace\Class        autowire: true```> This PR solves redundant parameter for class:``` yamlservices:    Vendor\Namespace\Class:        autowire: true```> Inspirations:https://laravel.com/docs/5.3/container,#18268,http://php-di.org/,Commits-------a18c4b6 [DI] Add tests for class named services71b17c7 [DI] Optional class for named services
@nicolas-grekasnicolas-grekas deleted the class-service branchJanuary 7, 2017 16:32
@wouterj
Copy link
Member

Fyi, created a doc issue for this great feature:symfony/symfony-docs#7329

theofidry reacted with thumbs up emoji

fabpot added a commit that referenced this pull requestJan 8, 2017
…tainer pass list (fabpot)This PR was merged into the 3.3-dev branch.Discussion----------[DependencyInjection] moved up ResolveClassPass in the container pass list| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | bug from#21133| License       | MIT| Doc PR        | n/aSome compiler passes need access to the service class names. But when using an empty class name (the service id being the class name), the resolution happens too late (during the optimization step). This PR fixes this by moving up the ResolveClassPass earlier in the stack.Commits-------2e5b69f [DependencyInjection] moved up ResolveClassPass in the container pass list
fabpot added a commit that referenced this pull requestJan 23, 2017
…izanagi)This PR was merged into the 3.3-dev branch.Discussion----------[DI] Add Yaml syntax for short services definition| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | N/A| License       | MIT| Doc PR        | todoIn my experience, most (at least, a lot) of the service definitions in an end-application only require the class and constructor arguments.#21133 allows to get rid of the `class` attribute by using the service id.Which means only arguments remain for most use-cases. Hence, we could support this syntax:#### Before:```ymlservices:    App\Foo\Bar:        arguments: ['@baz', 'foo', '%qux%']```#### After:```ymlservices:    App\Foo\Bar: ['@baz', 'foo', '%qux%']```It works especially well along with services `_defaults` introduced in#21071 :```ymlservices:    _defaults:        public: false        autowire: ['set*']        tags: ['serializer.normalizer']    App\Serializer\FooNormalizer: ['@baz', 'foo', '%qux%']```Commits-------83b599c [DI] Add Yaml syntax for short services definition
@fabpotfabpot mentioned this pull requestMay 1, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@dunglasdunglasdunglas approved these changes

@stofstofstof left review comments

@wouterjwouterjwouterj left review comments

@OskarStarkOskarStarkOskarStark left review comments

@xabbuhxabbuhxabbuh left review comments

+2 more reviewers

@theofidrytheofidrytheofidry left review comments

@GuilhemNGuilhemNGuilhemN left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

11 participants

@nicolas-grekas@xabbuh@fabpot@wouterj@dunglas@stof@OskarStark@theofidry@GuilhemN@carsonbot@hason

[8]ページ先頭

©2009-2025 Movatter.jp