Skip to content

Commit 938fcd4

Browse files
committed
Merge branch '5.1'
2 parents 6afa93d + 9536b70 commit 938fcd4

File tree

5 files changed

+26
-19
lines changed

5 files changed

+26
-19
lines changed

Compiler/CheckTypeDeclarationsPass.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
198198
}
199199
} elseif (\is_string($value)) {
200200
if ('%' === ($value[0] ?? '') && preg_match('/^%([^%]+)%$/', $value, $match)) {
201-
// Only array parameters are not inlined when dumped.
202-
$value = [];
201+
$value = $this->container->getParameter(substr($value, 1, -1));
203202
} elseif ($envPlaceholderUniquePrefix && false !== strpos($value, 'env_')) {
204203
// If the value is an env placeholder that is either mixed with a string or with another env placeholder, then its resolved value will always be a string, so we don't need to resolve it.
205204
// We don't need to change the value because it is already a string.

Dumper/PhpDumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ private function generateProxyClasses(): array
567567
$proxyClass = explode(' ', $this->inlineRequires ? substr($proxyCode, \strlen($code)) : $proxyCode, 3)[1];
568568

569569
if ($this->asFiles || $this->namespace) {
570-
$proxyCode .= "\n\\class_alias(__NAMESPACE__.'\\\\$proxyClass', '$proxyClass', false);\n";
570+
$proxyCode .= "\nif (!\\class_exists('$proxyClass', false)) {\n \\class_alias(__NAMESPACE__.'\\\\$proxyClass', '$proxyClass', false);\n}\n";
571571
}
572572

573573
$proxyClasses[$proxyClass.'.php'] = $proxyCode;
@@ -1086,7 +1086,7 @@ private function addNewInstance(Definition $definition, string $return = '', str
10861086
// If the class is a string we can optimize away
10871087
if (0 === strpos($class, "'") && false === strpos($class, '$')) {
10881088
if ("''" === $class) {
1089-
throw new RuntimeException(sprintf('Cannot dump definition: %s service is defined to be created by a factory but is missing the service reference, did you forget to define the factory service id or class?', $id ? 'The "'.$id.'"' : 'inline'));
1089+
throw new RuntimeException(sprintf('Cannot dump definition: "%s" service is defined to be created by a factory but is missing the service reference, did you forget to define the factory service id or class?', $id ? 'The "'.$id.'"' : 'inline'));
10901090
}
10911091

10921092
return $return.sprintf('%s::%s(%s)', $this->dumpLiteralClass($class), $callable[1], $arguments ? implode(', ', $arguments) : '').$tail;

Tests/Compiler/CheckTypeDeclarationsPassTest.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -612,20 +612,6 @@ public function testProcessThrowsOnIterableTypeWhenScalarPassed()
612612
$this->assertInstanceOf(\stdClass::class, $container->get('bar')->foo);
613613
}
614614

615-
public function testProcessResolveArrayParameters()
616-
{
617-
$container = new ContainerBuilder();
618-
$container->setParameter('ccc', ['foobar']);
619-
620-
$container
621-
->register('foobar', BarMethodCall::class)
622-
->addMethodCall('setArray', ['%ccc%']);
623-
624-
(new CheckTypeDeclarationsPass(true))->process($container);
625-
626-
$this->addToAssertionCount(1);
627-
}
628-
629615
public function testProcessResolveExpressions()
630616
{
631617
$container = new ContainerBuilder();
@@ -791,4 +777,20 @@ public function testExpressionLanguageWithSyntheticService()
791777

792778
$this->addToAssertionCount(1);
793779
}
780+
781+
public function testProcessResolveParameters()
782+
{
783+
$container = new ContainerBuilder();
784+
$container->setParameter('array_param', ['foobar']);
785+
$container->setParameter('string_param', 'ccc');
786+
787+
$container
788+
->register('foobar', BarMethodCall::class)
789+
->addMethodCall('setArray', ['%array_param%'])
790+
->addMethodCall('setString', ['%string_param%']);
791+
792+
(new CheckTypeDeclarationsPass(true))->process($container);
793+
794+
$this->addToAssertionCount(1);
795+
}
794796
}

Tests/Fixtures/CheckTypeDeclarationsPass/BarMethodCall.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@ public function setCallable(callable $callable): void
4444
public function setClosure(\Closure $closure): void
4545
{
4646
}
47+
48+
public function setString(string $string)
49+
{
50+
}
4751
}

Tests/Fixtures/php/services9_lazy_inlined_factories.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ class FooClass_%s extends \Bar\FooClass implements \ProxyManager\Proxy\VirtualPr
160160
%A
161161
}
162162

163-
\class_alias(__NAMESPACE__.'\\FooClass_%s', 'FooClass_%s', false);
163+
if (!\class_exists('FooClass_%s', false)) {
164+
\class_alias(__NAMESPACE__.'\\FooClass_%s', 'FooClass_%s', false);
165+
}
164166

165167
[ProjectServiceContainer.preload.php] => <?php
166168

0 commit comments

Comments
 (0)