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

Skip to content

[DependencyInjection] Forbid container cloning #15290

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
Jul 16, 2015

Conversation

jakzal
Copy link
Contributor

@jakzal jakzal commented Jul 16, 2015

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #15261
License MIT
Doc PR -

@jakzal jakzal force-pushed the forbid-container-cloning branch from df5f4ec to 85c8451 Compare July 16, 2015 08:26
@@ -90,6 +90,11 @@ public function __construct(ParameterBagInterface $parameterBag = null)
$this->parameterBag = $parameterBag ?: new ParameterBag();
}

public function __clone()
Copy link
Member

Choose a reason for hiding this comment

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

I suggest using a private (final) __clone method. This way, PHP itself will figure out that the class cannot be cloned (ReflectionClass::isCloneable will return false)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion. Applied.

@jakzal jakzal force-pushed the forbid-container-cloning branch from 85c8451 to 68fb163 Compare July 16, 2015 08:42
{
$class = new \ReflectionClass('Symfony\Component\DependencyInjection\Container');
$clone = $class->getMethod('__clone');
$this->assertTrue($clone->isPrivate());
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 assert that $class->isCloneable() returns false too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. This check would actually be sufficient. Added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, isCloneable() is available for PHP >= 5.4.

@jakzal jakzal force-pushed the forbid-container-cloning branch from 68fb163 to 8fcc4bd Compare July 16, 2015 08:53
@jakzal jakzal force-pushed the forbid-container-cloning branch from 8fcc4bd to ba12904 Compare July 16, 2015 10:11
@fabpot
Copy link
Member

fabpot commented Jul 16, 2015

👍

@jakzal
Copy link
Contributor Author

jakzal commented Jul 16, 2015

Let's wait for a green build. Previous one failed on PHP 5.3 ;)

@fabpot
Copy link
Member

fabpot commented Jul 16, 2015

What about merging this one on 2.3? Cloning a container does not work anyway, so it should be safe.

@jakzal
Copy link
Contributor Author

jakzal commented Jul 16, 2015

I'm fine with merging to 2.3. I just checked and there should be no issues in merging this PR to the 2.3 branch.

We can't get a green build, as tests from the tty group are blocking phpunit process on travis. Once 2.7 is merged to 2.8, there should be no blocking, but tests will still be failing. I'll work on fixing them as soon as 2.8 is updated.

@fabpot
Copy link
Member

fabpot commented Jul 16, 2015

After more thought, I'm going to merge it into 2.8.

@fabpot
Copy link
Member

fabpot commented Jul 16, 2015

Thank you @jakzal.

@fabpot fabpot merged commit ba12904 into symfony:2.8 Jul 16, 2015
fabpot added a commit that referenced this pull request Jul 16, 2015
This PR was merged into the 2.8 branch.

Discussion
----------

[DependencyInjection] Forbid container cloning

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #15261
| License       | MIT
| Doc PR        | -

Commits
-------

ba12904 [DependencyInjection] Forbid container cloning
@fabpot
Copy link
Member

fabpot commented Jul 16, 2015

@jakzal I've just merged 2.7 into 2.8.

@jakzal jakzal deleted the forbid-container-cloning branch July 16, 2015 12:30
@jakzal
Copy link
Contributor Author

jakzal commented Jul 16, 2015

@fabpot cool. Looks like the fix is already in 2.8. Tests should be passing now.

@SongoQ
Copy link
Contributor

SongoQ commented Jul 16, 2015

👍

@dosten
Copy link
Contributor

dosten commented Jul 16, 2015

The ContainerBuilder should be clonable?

@jakzal
Copy link
Contributor Author

jakzal commented Jul 16, 2015

@dosten we've decided not to support cloning of any containers. See #15261.

@stof
Copy link
Member

stof commented Jul 16, 2015

@dosten cloning a ContainerBuilder is a huge pain (see my comment in the issue)

@fabpot fabpot mentioned this pull request Nov 16, 2015
jakzal referenced this pull request in symfony/dependency-injection Dec 1, 2015
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