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

Skip to content

[DependencyInjection] Deprecate scope concept #14984

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
Jun 24, 2015
Merged

[DependencyInjection] Deprecate scope concept #14984

merged 1 commit into from
Jun 24, 2015

Conversation

dosten
Copy link
Contributor

@dosten dosten commented Jun 15, 2015

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
License MIT

This PR mark as deprecated the concept of scopes in the DI container. See #10557 (comment).
Also adds a new shared flag to the service definitions in replacement of the prototype scope.

@dosten dosten changed the title [DependencyInjection] Deprecate scope concept [WIP][DependencyInjection] Deprecate scope concept Jun 15, 2015
@stof
Copy link
Member

stof commented Jun 15, 2015

You need to make sure that core code does not trigger such deprecation though (for the request service for instance).

and the loaders should trigger their own deprecations when using scope to have a better message (same than done in a few other places)

@dosten
Copy link
Contributor Author

dosten commented Jun 15, 2015

@stof The only cases in the core code are the request scope and the test.client service with the prototype scope. What's the best approach?

@fabpot
Copy link
Member

fabpot commented Jun 21, 2015

@dosten As you can see on Travis, there are still many tests that need to be moved as legacy ones. For the test.client, I think that we need to keep the prototype scope as it was done before the introduction of scopes. Back then, we had a flag for prototype. As we decided to call it factory in Pimple (as this is where prototypes make more sense), I think we can add a factory flag which would replace the prototype scope.

@dosten
Copy link
Contributor Author

dosten commented Jun 21, 2015

@fabpot Thank you for your feedback, I didn't have enough time to continue with this PR. I'll work on this soon.
I've searched for the flag that you refer, and I have found this commit 1d5b6ed. Are you refering to the shared flag?
IMO if we add a factory flag this would be confusing, we already have the concept of factories in the DI. shared is a good name IMO.

@dosten
Copy link
Contributor Author

dosten commented Jun 22, 2015

I've added a initial implementation of a shared flag in the service definition, so any service that sets this flag as false will return a new instance every time, like the prototype scope. There is many failing tests because the deprecation messages, but i want to discuss this before fix the tests.

@dosten
Copy link
Contributor Author

dosten commented Jun 22, 2015

I can't trigger an error on the methods of the ContainerInterface because the BC promise, any idea?

@fabpot
Copy link
Member

fabpot commented Jun 22, 2015

@dosten I was indeed refering to the old shared flag (and you are right that using factory like in Pimple is probably confusing). ping @symfony/deciders

@Tobion
Copy link
Contributor

Tobion commented Jun 22, 2015

shared makes sense to me.

@dosten dosten changed the title [WIP][DependencyInjection] Deprecate scope concept [DependencyInjection] Deprecate scope concept Jun 24, 2015
@dosten
Copy link
Contributor Author

dosten commented Jun 24, 2015

@fabpot This PR is ready to be reviewed.

@Tobion
Copy link
Contributor

Tobion commented Jun 24, 2015

👍 good job

*/
public function setShared($shared)
{
$this->shared = (bool) $shared;
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 really want to cast here? The docblock is explicit about the expected type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We actually cast in the other methods of the Definition class

@fabpot
Copy link
Member

fabpot commented Jun 24, 2015

👍

@dosten
Copy link
Contributor Author

dosten commented Jun 24, 2015

@fabpot Comments addressed

@fabpot
Copy link
Member

fabpot commented Jun 24, 2015

Thank you @dosten.

@fabpot fabpot merged commit 6c4a676 into symfony:2.8 Jun 24, 2015
fabpot added a commit that referenced this pull request Jun 24, 2015
This PR was merged into the 2.8 branch.

Discussion
----------

[DependencyInjection] Deprecate scope concept

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| License       | MIT

This PR mark as deprecated the concept of scopes in the DI container. See #10557 (comment).
Also adds a new `shared` flag to the service definitions in replacement of the `prototype` scope.

Commits
-------

6c4a676 Add "shared" flag and deprecate scopes concept
@dosten dosten deleted the dependency-injection/deprecate-scope-concept branch June 24, 2015 16:23
if (isset($service['scope'])) {
$definition->setScope($service['scope']);
if ('request' !== $id) {
@trigger_error(sprintf('The "scope" key in file "%s" is deprecated since version 2.8 and will be removed in 3.0.', $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.

the deprecation message should mention the service id IMO to make it easier to understand

Copy link
Member

Choose a reason for hiding this comment

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

see #15113

weaverryan added a commit to symfony/symfony-docs that referenced this pull request Nov 30, 2015
…outerJ)

This PR was merged into the 2.8 branch.

Discussion
----------

Added minimal cookbook article about the shared flag

| Q | A
| --- | ---
| Doc fix? | no
| New docs? | yes (symfony/symfony#14984)
| Applies to | 2.8+
| Fixed tickets | #5437

Commits
-------

943ee0c Added minimal cookbook article about shared
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.

5 participants