Skip to content
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

[DI] fix using bindings with locators of service subscribers #31541

Merged
merged 1 commit into from May 22, 2019

Conversation

nicolas-grekas
Copy link
Member

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

Spotted during the workshop in Sao Paulo, with @tsantos84, @andreia and others :)

@@ -48,6 +48,12 @@ protected function processValue($value, $isRoot = false)
if (!$v instanceof Reference) {
throw new InvalidArgumentException(sprintf('Invalid definition for service "%s": an array of references is expected as first argument when the "container.service_locator" tag is set, "%s" found for key "%s".', $this->currentId, \is_object($v) ? \get_class($v) : \gettype($v), $k));
}

if (\is_int($k)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This fix is borrowed from 4.2.


require_once __DIR__.'/../Fixtures/includes/classes.php';

class ServiceLocatorTagPassTest extends TestCase
Copy link
Member Author

Choose a reason for hiding this comment

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

Test class borrowed from 4.2.

$this->assertSame(TestDefinition1::class, \get_class($locator('bar')));
}

public function testBindingsAreCopied()
Copy link
Member Author

Choose a reason for hiding this comment

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

The new test case for this fix.

@nicolas-grekas nicolas-grekas merged commit 7146b95 into symfony:3.4 May 22, 2019
nicolas-grekas added a commit that referenced this pull request May 22, 2019
…rs (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] fix using bindings with locators of service subscribers

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

Spotted during the workshop in Sao Paulo, with @tsantos84, @andreia and others :)

Commits
-------

7146b95 [DI] fix using bindings with locators of service subscribers
$locator->setBindings($container->getDefinition($callerId)->getBindings());
}

if (!$container->hasDefinition($id = 'service_locator.'.ContainerBuilder::hash($locator))) {
Copy link
Member

Choose a reason for hiding this comment

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

are bindings taken into account by the hashing ? If no, that would cause issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

correct, hash() uses serialize() so all the state is hashed

@fabpot fabpot mentioned this pull request May 28, 2019
@nicolas-grekas nicolas-grekas deleted the di-locator-bind branch May 28, 2019 10:30
This was referenced May 28, 2019
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.

None yet

3 participants