8000 Merge branch '4.4' into 5.2 · symfony/symfony@e3b0c88 · GitHub
[go: up one dir, main page]

Skip to content

Commit e3b0c88

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: install compatible versions of mongodb/mongodb only fix resolving parent/self/static type annotations [Console] fix QuestionHelper::getHiddenResponse() not working with space in project directory name [WebLink] Escape double quotes in attributes values
2 parents b148f89 + 1a5aec1 commit e3b0c88

File tree

12 files changed

+126
-14
lines changed

12 files changed

+126
-14
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ install:
255255
fi
256256
phpenv global $PHP
257257
rm vendor/composer/package-versions-deprecated -Rf
258-
([[ $deps ]] && cd src/Symfony/Component/HttpFoundation; cp composer.json composer.bak; composer require --dev --no-update mongodb/mongodb ^1.9.0)
258+
([[ $deps ]] && cd src/Symfony/Component/HttpFoundation; cp composer.json composer.bak; composer require --dev --no-update mongodb/mongodb)
259259
tfold 'composer update' $COMPOSER_UP
260260
tfold 'phpunit install' ./phpunit install
261261
if [[ $deps = high ]]; then

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ private function getHiddenResponse(OutputInterface $output, $inputStream, bool $
411411
$exe = $tmpExe;
412412
}
413413

414-
$sExec = shell_exec($exe);
414+
$sExec = shell_exec('"'.$exe.'"');
415415
$value = $trimmable ? rtrim($sExec) : $sExec;
416416
$output->writeln('');
417417

src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,31 @@ public function getTypes(string $class, string $property, array $context = []):
142142
break;
143143
}
144144

145+
$parentClass = null;
145146
$types = [];
146147
/** @var DocBlock\Tags\Var_|DocBlock\Tags\Return_|DocBlock\Tags\Param $tag */
147148
foreach ($docBlock->getTagsByName($tag) as $tag) {
148149
if ($tag && !$tag instanceof InvalidTag && null !== $tag->getType()) {
149-
$types = array_merge($types, $this->phpDocTypeHelper->getTypes($tag->getType()));
150+
foreach ($this->phpDocTypeHelper->getTypes($tag->getType()) as $type) {
151+
switch ($type->getClassName()) {
152+
case 'self':
153+
case 'static':
154+
$resolvedClass = $class;
155+
break;
156+
157+
case 'parent':
158+
if (false !== $resolvedClass = $parentClass ?? $parentClass = get_parent_class($class)) {
159+
break;
160+
}
161+
// no break
162+
163+
default:
164+
$types[] = $type;
165+
continue 2;
166+
}
167+
168+
$types[] = new Type(Type::BUILTIN_TYPE_OBJECT, $type->isNullable(), $resolvedClass, $type->isCollection(), $type->getCollectionKeyType(), $type->getCollectionValueType());
169+
}
150170
}
151171
}
152172

src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use PHPUnit\Framework\TestCase;
1818
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
1919
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
20+
use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy;
2021
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsedInTrait;
2122
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsingTrait;
2223
use Symfony\Component\PropertyInfo\Type;
@@ -136,6 +137,7 @@ public function typesProvider()
136137
null,
137138
null,
138139
],
140+
['self', [new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)], null, null],
139141
];
140142
}
141143

@@ -342,6 +344,38 @@ public function propertiesDefinedByTraitsProvider(): array
342344
];
343345
}
344346

347+
/**
348+
* @dataProvider propertiesStaticTypeProvider
349+
*/
350+
public function testPropertiesStaticType(string $class, string $property, Type $type)
351+
{
352+
$this->assertEquals([$type], $this->extractor->getTypes($class, $property));
353+
}
354+
355+
public function propertiesStaticTypeProvider(): array
356+
{
357+
return [
358+
[ParentDummy::class, 'propertyTypeStatic', new Type(Type::BUILTIN_TYPE_OBJECT, false, ParentDummy::class)],
359+
[Dummy::class, 'propertyTypeStatic', new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)],
360+
];
361+
}
362+
363+
/**
364+
* @dataProvider propertiesParentTypeProvider
365+
*/
366+
public function testPropertiesParentType(string $class, string $property, ?array $types)
367+
{
368+
$this->assertEquals($types, $this->extractor->getTypes($class, $property));
369+
}
370+
371+
public function propertiesParentTypeProvider(): array
372+
{
373+
return [
374+
[ParentDummy::class, 'parentAnnotationNoParent', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'parent')]],
375+
[Dummy::class, 'parentAnnotation', [new Type(Type::BUILTIN_TYPE_OBJECT, false, ParentDummy::class)]],
376+
];
377+
}
378+
345379
protected function isPhpDocumentorV5()
346380
{
347381
if (class_exists(InvalidTag::class)) {

src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php71DummyExtended;
2525
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php71DummyExtended2;
2626
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php74Dummy;
27+
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php7Dummy;
28+
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php7ParentDummy;
2729
use Symfony\Component\PropertyInfo\Type;
2830

2931
/**
@@ -66,12 +68,15 @@ public function testGetProperties()
6668
'arrayWithKeys',
6769
'arrayWithKeysAndComplexValue',
6870
'arrayOfMixed',
71+
'parentAnnotation',
6972
'foo',
7073
'foo2',
7174
'foo3',
7275
'foo4',
7376
'foo5',
7477
'files',
78+
'propertyTypeStatic',
79+
'parentAnnotationNoParent',
7580
'a',
7681
'DOB',
7782
'Id',
@@ -118,12 +123,15 @@ public function testGetPropertiesWithCustomPrefixes()
118123
'arrayWithKeys',
119124
'arrayWithKeysAndComplexValue',
120125
'arrayOfMixed',
126+
'parentAnnotation',
121127
'foo',
122128
'foo2',
123129
'foo3',
124130
'foo4',
125131
'foo5',
126132
'files',
133+
'propertyTypeStatic',
134+
'parentAnnotationNoParent',
127135
'date',
128136
'c',
129137
'd',
@@ -159,12 +167,15 @@ public function testGetPropertiesWithNoPrefixes()
159167
'arrayWithKeys',
160168
'arrayWithKeysAndComplexValue',
161169
'arrayOfMixed',
170+
'parentAnnotation',
162171
'foo',
163172
'foo2',
164173
'foo3',
165174
'foo4',
166175
'foo5',
167176
'files',
177+
'propertyTypeStatic',
178+
'parentAnnotationNoParent',
168179
],
169180
$noPrefixExtractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy')
170181
);
@@ -200,20 +211,21 @@ public function typesProvider()
200211
/**
201212
* @dataProvider php7TypesProvider
202213
*/
203-
public function testExtractPhp7Type($property, array $type = null)
214+
public function testExtractPhp7Type(string $class, string $property, array $type = null)
204215
{
205-
$this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php7Dummy', $property, []));
216+
$this->assertEquals($type, $this->extractor->getTypes($class, $property, []));
206217
}
207218

208219
public function php7TypesProvider()
209220
{
210221
return [
211-
['foo', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)]],
212-
['bar', [new Type(Type::BUILTIN_TYPE_INT)]],
213-
['baz', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]],
214-
['buz', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Component\PropertyInfo\Tests\Fixtures\Php7Dummy')]],
215-
['biz', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'stdClass')]],
216-
['donotexist', null],
222+
[Php7Dummy::class, 'foo', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)]],
223+
[Php7Dummy::class, 'bar', [new Type(Type::BUILTIN_TYPE_INT)]],
224+
[Php7Dummy::class, 'baz', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]],
225+
[Php7Dummy::class, 'buz', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Component\PropertyInfo\Tests\Fixtures\Php7Dummy')]],
226+
[Php7Dummy::class, 'biz', [new Type(Type::BUILTIN_TYPE_OBJECT, false, Php7ParentDummy::class)]],
227+
[Php7Dummy::class, 'donotexist', null],
228+
[Php7ParentDummy::class, 'parent', [new Type(Type::BUILTIN_TYPE_OBJECT, false, \stdClass::class)]],
217229
];
218230
}
219231

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ class Dummy extends ParentDummy
145145
*/
146146
public $arrayOfMixed;
147147

148+
/**
149+
* @var parent
150+
*/
151+
public $parentAnnotation;
152+
148153
public static function getStatic()
149154
{
150155
}

src/Symfony/Component/PropertyInfo/Tests/Fixtures/ParentDummy.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ class ParentDummy
4848
*/
4949
public $files;
5050

51+
/**
52+
* @var static
53+
*/
54+
public $propertyTypeStatic;
55+
56+
/**
57+
* @var parent
58+
*/
59+
public $parentAnnotationNoParent;
60+
5161
/**
5262
* @return bool|null
5363
*/

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php7Dummy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* @author Kévin Dunglas <dunglas@gmail.com>
1616
*/
17-
class Php7Dummy extends \stdClass
17+
class Php7Dummy extends Php7ParentDummy
1818
{
1919
public function getFoo(): array
2020
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
13+
14+
class Php7ParentDummy extends \stdClass
15+
{
16+
public function getParent(): parent
17+
{
18+
}
19+
}

src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ private function getPhpTypeAndClass(string $docType): array
172172
return [$docType, null];
173173
}
174174

175+
if (\in_array($docType, ['parent', 'self', 'static'], true)) {
176+
return ['object', $docType];
177+
}
178+
175179
return ['object', substr($docType, 1)]; // substr to strip the namespace's `\`-prefix
176180
}
177181
}

src/Symfony/Component/WebLink/HttpHeaderSerializer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public function serialize(iterable $links): ?string
3939
foreach ($link->getAttributes() as $key => $value) {
4040
if (\is_array($value)) {
4141
foreach ($value as $v) {
42-
$attributesParts[] = sprintf('%s="%s"', $key, $v);
42+
$attributesParts[] = sprintf('%s="%s"', $key, preg_replace('/(?<!\\\\)"/', '\"', $v));
4343
}
4444

4545
continue;
4646
}
4747

4848
if (!\is_bool($value)) {
49-
$attributesParts[] = sprintf('%s="%s"', $key, $value);
49+
$attributesParts[] = sprintf('%s="%s"', $key, preg_replace('/(?<!\\\\)"/', '\"', $value));
5050

5151
continue;
5252
}

src/Symfony/Component/WebLink/Tests/HttpHeaderSerializerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,12 @@ public function testSerializeEmpty()
4444
{
4545
$this->assertNull($this->serializer->serialize([]));
4646
}
47+
48+
public function testSerializeDoubleQuotesInAttributeValue()
49+
{
50+
$this->assertSame('</foo>; rel="alternate"; title="\"escape me\" \"already escaped\" \"\"\""', $this->serializer->serialize([
51+
(new Link('alternate', '/foo'))
52+
->withAttribute('title', '"escape me" \"already escaped\" ""\"'),
53+
]));
54+
}
4755
}

0 commit comments

Comments
 (0)
0