Merge branch '4.3' into 4.4

* 4.3:
  [DI] fix locators with numeric keys
  Fix error when we use VO for the marking property
This commit is contained in:
Nicolas Grekas 2019-11-08 17:24:33 +01:00
commit f459fd01a2
4 changed files with 40 additions and 2 deletions

View File

@ -52,6 +52,8 @@ final class ServiceLocatorTagPass extends AbstractRecursivePass
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.', $this->currentId));
}
$i = 0;
foreach ($arguments[0] as $k => $v) {
if ($v instanceof ServiceClosureArgument) {
continue;
@ -60,10 +62,13 @@ final class ServiceLocatorTagPass extends AbstractRecursivePass
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)) {
if ($i === $k) {
unset($arguments[0][$k]);
$k = (string) $v;
++$i;
} elseif (\is_int($k)) {
$i = null;
}
$arguments[0][$k] = new ServiceClosureArgument($v);
}

View File

@ -114,6 +114,7 @@ class ServiceLocatorTagPassTest extends TestCase
->setArguments([[
'bar' => new Reference('baz'),
new Reference('bar'),
16 => new Reference('baz'),
]])
->addTag('container.service_locator')
;
@ -124,6 +125,7 @@ class ServiceLocatorTagPassTest extends TestCase
$locator = $container->get('foo');
$this->assertSame(TestDefinition1::class, \get_class($locator('bar')));
$this->assertSame(TestDefinition2::class, \get_class($locator(16)));
}
public function testBindingsAreCopied()

View File

@ -61,7 +61,7 @@ final class MethodMarkingStore implements MarkingStoreInterface
}
if ($this->singleState) {
$marking = [$marking => 1];
$marking = [(string) $marking => 1];
}
return new Marking($marking);

View File

@ -52,4 +52,35 @@ class MethodMarkingStoreTest extends TestCase
$this->assertEquals($marking, $marking2);
}
public function testGetMarkingWithValueObject()
{
$subject = new Subject($this->createValueObject('first_place'));
$markingStore = new MethodMarkingStore(true);
$marking = $markingStore->getMarking($subject);
$this->assertInstanceOf(Marking::class, $marking);
$this->assertCount(1, $marking->getPlaces());
$this->assertSame('first_place', (string) $subject->getMarking());
}
private function createValueObject(string $markingValue)
{
return new class($markingValue) {
/** @var string */
private $markingValue;
public function __construct(string $markingValue)
{
$this->markingValue = $markingValue;
}
public function __toString()
{
return $this->markingValue;
}
};
}
}