Skip to content

Commit 66e5020

Browse files
Merge branch '4.4' into 5.0
* 4.4: [VarDumper] fix typo Fix support for PHP8 union types [FrameworkBundle] preserve dots in query-string when redirecting [3.4] Fix support for PHP8 union types [PhpUnitBridge] Streamline ansi/no-ansi of composer according to phpunit --colors option [3.4] Small update in our internal terminology [Cache] fix compat with DBAL v3 [HttpClient] Convert CurlHttpClient::handlePush() to instance method [VarDumper] Fix CliDumper coloration [DI] tighten detection of local dirs to prevent false positives [FrameworkBundle] preserve dots in query-string when redirecting Fix precendence in 4.4 bumped Symfony version to 3.4.43 updated VERSION for 3.4.42 update CONTRIBUTORS for 3.4.42 updated CHANGELOG for 3.4.42
2 parents de63ab0 + 365f147 commit 66e5020

File tree

7 files changed

+73
-35
lines changed

7 files changed

+73
-35
lines changed

Compiler/CheckTypeDeclarationsPass.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,26 @@ private function checkTypeDeclarations(Definition $checkedDefinition, \Reflectio
153153
/**
154154
* @throws InvalidParameterTypeException When a parameter is not compatible with the declared type
155155
*/
156-
private function checkType(Definition $checkedDefinition, $value, \ReflectionParameter $parameter, ?string $envPlaceholderUniquePrefix): void
156+
private function checkType(Definition $checkedDefinition, $value, \ReflectionParameter $parameter, ?string $envPlaceholderUniquePrefix, string $type = null): void
157157
{
158-
$type = $parameter->getType()->getName();
158+
if (null === $type) {
159+
$type = $parameter->getType();
160+
161+
if ($type instanceof \ReflectionUnionType) {
162+
foreach ($type->getTypes() as $type) {
163+
try {
164+
$this->checkType($checkedDefinition, $value, $parameter, $envPlaceholderUniquePrefix, $type);
165+
166+
return;
167+
} catch (InvalidParameterTypeException $e) {
168+
}
169+
}
170+
171+
throw new InvalidParameterTypeException($this->currentId, $e->getCode(), $parameter);
172+
}
173+
174+
$type = $type->getName();
175+
}
159176

160177
if ($value instanceof Reference) {
161178
if (!$this->container->has($value = (string) $value)) {
@@ -266,7 +283,7 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
266283
return;
267284
}
268285

269-
$checkFunction = sprintf('is_%s', $parameter->getType()->getName());
286+
$checkFunction = sprintf('is_%s', $type);
270287

271288
if (!$parameter->getType()->isBuiltin() || !$checkFunction($value)) {
272289
throw new InvalidParameterTypeException($this->currentId, \is_object($value) ? $class : \gettype($value), $parameter);

Dumper/PhpDumper.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function dump(array $options = [])
223223
$regex = preg_quote(\DIRECTORY_SEPARATOR.$dir[$i], '#').$regex;
224224
} while (0 < --$i);
225225

226-
$this->targetDirRegex = '#'.preg_quote($dir[0], '#').$regex.'#';
226+
$this->targetDirRegex = '#(^|file://|[:;, \|\r\n])'.preg_quote($dir[0], '#').$regex.'#';
227227
}
228228
}
229229

@@ -2008,11 +2008,12 @@ private function isSingleUsePrivateNode(ServiceReferenceGraphNode $node): bool
20082008
private function export($value)
20092009
{
20102010
if (null !== $this->targetDirRegex && \is_string($value) && preg_match($this->targetDirRegex, $value, $matches, PREG_OFFSET_CAPTURE)) {
2011-
$prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1]), true).'.' : '';
20122011
$suffix = $matches[0][1] + \strlen($matches[0][0]);
2012+
$matches[0][1] += \strlen($matches[1][0]);
2013+
$prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1]), true).'.' : '';
20132014
$suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix), true) : '';
20142015
$dirname = $this->asFiles ? '$this->containerDir' : '__DIR__';
2015-
$offset = 1 + $this->targetDirMaxMatches - \count($matches);
2016+
$offset = 2 + $this->targetDirMaxMatches - \count($matches);
20162017

20172018
if (0 < $offset) {
20182019
$dirname = sprintf('\dirname(__DIR__, %d)', $offset + (int) $this->asFiles);

Dumper/Preloader.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static function preload(array $classes)
4848
}
4949
}
5050

51-
private static function doPreload(string $class, array &$preloaded)
51+
private static function doPreload(string $class, array &$preloaded): void
5252
{
5353
if (isset($preloaded[$class]) || \in_array($class, ['self', 'static', 'parent'], true)) {
5454
return;
@@ -68,9 +68,7 @@ private static function doPreload(string $class, array &$preloaded)
6868

6969
if (\PHP_VERSION_ID >= 70400) {
7070
foreach ($r->getProperties(\ReflectionProperty::IS_PUBLIC) as $p) {
71-
if (($t = $p->getType()) && !$t->isBuiltin()) {
72-
self::doPreload($t->getName(), $preloaded);
73-
}
71+
self::preloadType($p->getType(), $preloaded);
7472
}
7573
}
7674

@@ -84,17 +82,26 @@ private static function doPreload(string $class, array &$preloaded)
8482
}
8583
}
8684

87-
if (($t = $p->getType()) && !$t->isBuiltin()) {
88-
self::doPreload($t->getName(), $preloaded);
89-
}
85+
self::preloadType($p->getType(), $preloaded);
9086
}
9187

92-
if (($t = $m->getReturnType()) && !$t->isBuiltin()) {
93-
self::doPreload($t->getName(), $preloaded);
94-
}
88+
self::preloadType($p->getReturnType(), $preloaded);
9589
}
9690
} catch (\ReflectionException $e) {
9791
// ignore missing classes
9892
}
9993
}
94+
95+
private static function preloadType(?\ReflectionType $t, array &$preloaded): void
96+
{
97+
if (!$t || $t->isBuiltin()) {
98+
return;
99+
}
100+
101+
foreach ($t instanceof \ReflectionUnionType ? $t->getTypes() : [$t] as $t) {
102+
if (!$t->isBuiltin()) {
103+
self::doPreload($t instanceof \ReflectionNamedType ? $t->getName() : $t, $preloaded);
104+
}
105+
}
106+
}
100107
}

Exception/InvalidParameterTypeException.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class InvalidParameterTypeException extends InvalidArgumentException
2121
{
2222
public function __construct(string $serviceId, string $type, \ReflectionParameter $parameter)
2323
{
24-
parent::__construct(sprintf('Invalid definition for service "%s": argument %d of "%s::%s" accepts "%s", "%s" passed.', $serviceId, 1 + $parameter->getPosition(), $parameter->getDeclaringClass()->getName(), $parameter->getDeclaringFunction()->getName(), $parameter->getType()->getName(), $type));
24+
$acceptedType = $parameter->getType();
25+
$acceptedType = $acceptedType instanceof \ReflectionNamedType ? $acceptedType->getName() : (string) $acceptedType;
26+
27+
parent::__construct(sprintf('Invalid definition for service "%s": argument %d of "%s::%s" accepts "%s", "%s" passed.', $serviceId, 1 + $parameter->getPosition(), $parameter->getDeclaringClass()->getName(), $parameter->getDeclaringFunction()->getName(), $acceptedType, $type), $type);
2528
}
2629
}

LazyProxy/ProxyHelper.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,36 @@ public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionPa
3131
if (!$type) {
3232
return null;
3333
}
34-
if (!\is_string($type)) {
35-
$name = $type->getName();
34+
35+
$types = [];
36+
37+
foreach ($type instanceof \ReflectionUnionType ? $type->getTypes() : [$type] as $type) {
38+
$name = $type instanceof \ReflectionNamedType ? $type->getName() : (string) $type;
3639

3740
if ($type->isBuiltin()) {
38-
return $noBuiltin ? null : $name;
41+
if (!$noBuiltin) {
42+
$types[] = $name;
43+
}
44+
continue;
3945
}
40-
}
41-
$lcName = strtolower($name);
42-
$prefix = $noBuiltin ? '' : '\\';
4346

44-
if ('self' !== $lcName && 'parent' !== $lcName) {
45-
return $prefix.$name;
46-
}
47-
if (!$r instanceof \ReflectionMethod) {
48-
return null;
49-
}
50-
if ('self' === $lcName) {
51-
return $prefix.$r->getDeclaringClass()->name;
47+
$lcName = strtolower($name);
48+
$prefix = $noBuiltin ? '' : '\\';
49+
50+
if ('self' !== $lcName && 'parent' !== $lcName) {
51+
$types[] = '' !== $prefix ? $prefix.$name : $name;
52+
continue;
53+
}
54+
if (!$r instanceof \ReflectionMethod) {
55+
continue;
56+
}
57+
if ('self' === $lcName) {
58+
$types[] = $prefix.$r->getDeclaringClass()->name;
59+
} else {
60+
$types[] = ($parent = $r->getDeclaringClass()->getParentClass()) ? $prefix.$parent->name : null;
61+
}
5262
}
5363

54-
return ($parent = $r->getDeclaringClass()->getParentClass()) ? $prefix.$parent->name : null;
64+
return $types ? implode('|', $types) : null;
5565
}
5666
}

Tests/Dumper/PhpDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function testDumpRelativeDir()
107107

108108
$container = new ContainerBuilder();
109109
$container->setDefinition('test', $definition);
110-
$container->setParameter('foo', 'wiz'.\dirname(__DIR__));
110+
$container->setParameter('foo', 'file://'.\dirname(__DIR__));
111111
$container->setParameter('bar', __DIR__);
112112
$container->setParameter('baz', '%bar%/PhpDumperTest.php');
113113
$container->setParameter('buz', \dirname(__DIR__, 2));

Tests/Fixtures/php/services12.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getRemovedIds(): array
5656
*/
5757
protected function getTestService()
5858
{
59-
return $this->services['test'] = new \stdClass(('wiz'.\dirname(__DIR__, 1)), [('wiz'.\dirname(__DIR__, 1)) => (\dirname(__DIR__, 2).'/')]);
59+
return $this->services['test'] = new \stdClass(('file://'.\dirname(__DIR__, 1)), [('file://'.\dirname(__DIR__, 1)) => (\dirname(__DIR__, 2).'/')]);
6060
}
6161

6262
public function getParameter(string $name)
@@ -105,7 +105,7 @@ private function getDynamicParameter(string $name)
105105
protected function getDefaultParameters(): array
106106
{
107107
return [
108-
'foo' => ('wiz'.\dirname(__DIR__, 1)),
108+
'foo' => ('file://'.\dirname(__DIR__, 1)),
109109
'bar' => __DIR__,
110110
'baz' => (__DIR__.'/PhpDumperTest.php'),
111111
'buz' => \dirname(__DIR__, 2),

0 commit comments

Comments
 (0)