8000 Merge branch '3.4' into 4.3 · symfony/symfony@73ea89b · GitHub
[go: up one dir, main page]

Skip to content

Commit 73ea89b

Browse files
Merge branch '3.4' into 4.3
* 3.4: [Config][ReflectionClassResource] Handle parameters with undefined constant as their default values fix dumping number-like string parameters [Console] Fix autocomplete multibyte input support [Config] don't break on virtual stack frames in ClassExistenceResource
2 parents bbda69d + 9eafff5 commit 73ea89b

File tree

10 files changed

+127
-18
lines changed

10 files changed

+127
-18
lines changed

src/Symfony/Component/Config/Resource/ClassExistenceResource.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,17 @@ public static function throwOnRequiredClass($class, \Exception $previous = null)
183183
}
184184

185185
$props = [
186-
'file' => $trace[$i]['file'],
187-
'line' => $trace[$i]['line'],
186+
'file' => isset($trace[$i]['file']) ? $trace[$i]['file'] : null,
187+
'line' => isset($trace[$i]['line']) ? $trace[$i]['line'] : null,
188188
'trace' => \array_slice($trace, 1 + $i),
189189
];
190190

191191
foreach ($props as $p => $v) {
192-
$r = new \ReflectionProperty('Exception', $p);
193-
$r->setAccessible(true);
194-
$r->setValue($e, $v);
192+
if (null !== $v) {
193+
$r = new \ReflectionProperty('Exception', $p);
194+
$r->setAccessible(true);
195+
$r->setValue($e, $v);
196+
}
195197
}
196198
}
197199

src/Symfony/Component/Config/Resource/ReflectionClassResource.php

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,56 @@ private function generateSignature(\ReflectionClass $class)
141141
}
142142

143143
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $m) {
144-
yield preg_replace('/^ @@.*/m', '', $m);
145-
146144
$defaults = [];
145+
$parametersWithUndefinedConstants = [];
147146
foreach ($m->getParameters() as $p) {
148-
$defaults[$p->name] = $p->isDefaultValueAvailable() ? $p->getDefaultValue() : null;
147+
if (!$p->isDefaultValueAvailable()) {
148+
$defaults[$p->name] = null;
149+
150+
continue;
151+
}
152+
153+
if (!$p->isDefaultValueConstant() || \defined($p->getDefaultValueConstantName())) {
154+
$defaults[$p->name] = $p->getDefaultValue();
155+
156+
continue;
157+
}
158+
159+
$defaults[$p->name] = $p->getDefaultValueConstantName();
160+
$parametersWithUndefinedConstants[$p->name] = true;
149161
}
162+
163+
if (!$parametersWithUndefinedConstants) {
164+
yield preg_replace('/^ @@.*/m', '', $m);
165+
} else {
166+
$stack = [
167+
$m->getDocComment(),
168+
$m->getName(),
169+
$m->isAbstract(),
170+
$m->isFinal(),
171+
$m->isStatic(),
172+
$m->isPublic(),
173+
$m->isPrivate(),
174+
$m->isProtected(),
175+
$m->returnsReference(),
176+
$m->hasReturnType() ? $m->getReturnType()->getName() : '',
177+
];
178+
179+
foreach ($m->getParameters() as $p) {
180+
if (!isset($parametersWithUndefinedConstants[$p->name])) {
181+
$stack[] = (string) $p;
182+
} else {
183+
$stack[] = $p->isOptional();
184+
$stack[] = $p->hasType() ? $p->getType()->getName() : '';
185+
$stack[] = $p->isPassedByReference();
186+
$stack[] = $p->isVariadic();
187+
$stack[] = $p->getName();
188+
}
189+
}
190+
191+
yield implode(',', $stack);
192+
}
193+
150194
yield print_r($defaults, true);
151195
}
152196

src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ public function testIsFreshForDeletedResources()
6464
/**
6565
* @dataProvider provideHashedSignature
6666
*/
67-
public function testHashedSignature($changeExpected, $changedLine, $changedCode)
67+
public function testHashedSignature($changeExpected, $changedLine, $changedCode, $setContext = null)
6868
{
69+
if ($setContext) {
70+
$setContext();
71+
}
72+
6973
$code = <<<'EOPHP'
7074
/* 0*/
7175
/* 1*/ class %s extends ErrorException
@@ -83,7 +87,9 @@ public function testHashedSignature($changeExpected, $changedLine, $changedCode)
8387
/*13*/ protected function prot($a = []) {}
8488
/*14*/
8589
/*15*/ private function priv() {}
86-
/*16*/ }
90+
/*16*/
91+
/*17*/ public function ccc($bar = A_CONSTANT_THAT_FOR_SURE_WILL_NEVER_BE_DEFINED_CCCCCC) {}
92+
/*18*/ }
8793
EOPHP;
8894

8995
static $expectedSignature, $generateSignature;
@@ -98,7 +104,9 @@ public function testHashedSignature($changeExpected, $changedLine, $changedCode)
98104
}
99105

100106
$code = explode("\n", $code);
101-
$code[$changedLine] = $changedCode;
107+
if (null !== $changedCode) {
108+
$code[$changedLine] = $changedCode;
109+
}
102110
eval(sprintf(implode("\n", $code), $class = 'Foo'.str_replace('.', '_', uniqid('', true))));
103111
$signature = implode("\n", iterator_to_array($generateSignature(new \ReflectionClass($class))));
104112

@@ -142,6 +150,10 @@ public function provideHashedSignature()
142150
yield [0, 7, 'protected int $prot;'];
143151
yield [0, 9, 'private string $priv;'];
144152
}
153+
154+
yield [1, 17, 'public function ccc($bar = 187) {}'];
155+
yield [1, 17, 'public function ccc($bar = ANOTHER_ONE_THAT_WILL_NEVER_BE_DEFINED_CCCCCCCCC) {}'];
156+
yield [1, 17, null, static function () { \define('A_CONSTANT_THAT_FOR_SURE_WILL_NEVER_BE_DEFINED_CCCCCC', 'foo'); }];
145157
}
146158

147159
public function testEventSubscriber()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
226226
} elseif ("\177" === $c) { // Backspace Character
227227
if (0 === $numMatches && 0 !== $i) {
228228
--$i;
229-
$fullChoice = substr($fullChoice, 0, -1);
229+
$fullChoice = self::substr($fullChoice, 0, -1);
230230
// Move cursor backwards
231231
$output->write("\033[1D");
232232
}
@@ -240,7 +240,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
240240
}
241241

242242
// Pop the last character off the end of our string
243-
$ret = substr($ret, 0, $i);
243+
$ret = self::substr($ret, 0, $i);
244244
} elseif ("\033" === $c) {
245245
// Did we read an escape sequence?
246246
$c .= fread($inputStream, 2);
@@ -266,7 +266,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
266266
$remainingCharacters = substr($ret, \strlen(trim($this->mostRecentlyEnteredValue($fullChoice))));
267267
$output->write($remainingCharacters);
268268
$fullChoice .= $remainingCharacters;
269-
$i = \strlen($fullChoice);
269+
$i = self::strlen($fullChoice);
270270

271271
$matches = array_filter(
272272
$autocomplete($ret),

src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,20 @@ public function testAskWithAutocomplete()
175175
// Acm<NEWLINE>
176176
// Ac<BACKSPACE><BACKSPACE>s<TAB>Test<NEWLINE>
177177
// <NEWLINE>
178-
// <UP ARROW><UP ARROW><NEWLINE>
179-
// <UP ARROW><UP ARROW><UP ARROW><UP ARROW><UP ARROW><TAB>Test<NEWLINE>
178+
// <UP ARROW><UP ARROW><UP ARROW><NEWLINE>
179+
// <UP ARROW><UP ARROW><UP ARROW><UP ARROW><UP ARROW><UP ARROW><UP ARROW><TAB>Test<NEWLINE>
180180
// <DOWN ARROW><NEWLINE>
181181
// S<BACKSPACE><BACKSPACE><DOWN ARROW><DOWN ARROW><NEWLINE>
182182
// F00<BACKSPACE><BACKSPACE>oo<TAB><NEWLINE>
183-
$inputStream = $this->getInputStream("Acm\nAc\177\177s\tTest\n\n\033[A\033[A\n\033[A\033[A\033[A\033[A\033[A\tTest\n\033[B\nS\177\177\033[B\033[B\nF00\177\177oo\t\n");
183+
// F⭐<TAB><BACKSPACE><BACKSPACE>⭐<TAB><NEWLINE>
184+
$inputStream = $this->getInputStream("Acm\nAc\177\177s\tTest\n\n\033[A\033[A\033[A\n\033[A\033[A\033[A\033[A\033[A\033[A\033[A\tTest\n\033[B\nS\177\177\033[B\033[B\nF00\177\177oo\t\nF⭐\t\177\177\t\n");
184185

185186
$dialog = new QuestionHelper();
186187
$helperSet = new HelperSet([new FormatterHelper()]);
187188
$dialog->setHelperSet($helperSet);
188189

189190
$question = new Question('Please select a bundle', 'FrameworkBundle');
190-
$question->setAutocompleterValues(['AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle']);
191+
$question->setAutocompleterValues(['AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle', 'F⭐Y']);
191192

192193
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
193194
$this->assertEquals('AsseticBundleTest', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
@@ -197,6 +198,7 @@ public function testAskWithAutocomplete()
197198
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
198199
$this->assertEquals('AsseticBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
199200
$this->assertEquals('FooBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
201+
$this->assertEquals('F⭐Y', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
200202
}
201203

202204
public function testAskWithAutocompleteCallback()

src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ private function convertParameters(array $parameters, $type, \DOMElement $parent
324324
if (\in_array($value, ['null', 'true', 'false'], true)) {
325325
$element->setAttribute('type', 'string');
326326
}
327+
328+
if (\is_string($value) && (is_numeric($value) || preg_match('/^0b[01]*$/', $value) || preg_match('/^0x[0-9a-f]++$/i', $value))) {
329+
$element->setAttribute('type', 'string');
330+
}
331+
327332
$text = $this->document->createTextNode(self::phpToXml($value));
328333
$element->appendChild($text);
329334
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container8.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
'values' => [true, false, null, 0, 1000.3, 'true', 'false', 'null'],
1212
'binary' => "\xf0\xf0\xf0\xf0",
1313
'binary-control-char' => "This is a Bell char \x07",
14+
'null string' => 'null',
15+
'string of digits' => '123',
16+
'string of digits prefixed with minus character' => '-123',
17+
'true string' => 'true',
18+
'false string' => 'false',
19+
'binary number string' => '0b0110',
20+
'numeric string' => '-1.2E2',
21+
'hexadecimal number string' => '0xFF',
22+
'float string' => '10100.1',
23+
'positive float string' => '+10100.1',
24+
'negative float string' => '-10100.1',
1425
]));
1526

1627
return $container;

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ protected function getDefaultParameters()
126126
],
127127
'binary' => 'ðððð',
128128
'binary-control-char' => 'This is a Bell char ',
129+
'null string' => 'null',
130+
'string of digits' => '123',
131+
'string of digits prefixed with minus character' => '-123',
132+
'true string' => 'true',
133+
'false string' => 'false',
134+
'binary number string' => '0b0110',
135+
'numeric string' => '-1.2E2',
136+
'hexadecimal number string' => '0xFF',
137+
'float string' => '10100.1',
138+
'positive float string' => '+10100.1',
139+
'negative float string' => '-10100.1',
129140
];
130141
}
131142
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services8.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020
</parameter>
2121
<parameter key="binary" type="binary">8PDw8A==</parameter>
2222
<parameter key="binary-control-char" type="binary">VGhpcyBpcyBhIEJlbGwgY2hhciAH</parameter>
23+
<parameter key="null string" type="string">null</parameter>
24+
<parameter key="string of digits" type="string">123</parameter>
25+
<parameter key="string of digits prefixed with minus character" type="string">-123</parameter>
26+
<parameter key="true string" type="string">true</parameter>
27+
<parameter key="false string" type="string">false</parameter>
28+
<parameter key="binary number string" type="string">0b0110</parameter>
29+
<parameter key="numeric string" type="string">-1.2E2</parameter>
30+
<parameter key="hexadecimal number string" type="string">0xFF</parameter>
31+
<parameter key="float string" type="string">10100.1</parameter>
32+
<parameter key="positive float string" type="string">+10100.1</parameter>
33+
<parameter key="negative float string" type="string">-10100.1</parameter>
2334
</parameters>
2435
<services>
2536
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true"/>

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services8.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ parameters:
66
values: [true, false, null, 0, 1000.3, 'true', 'false', 'null']
77
binary: !!binary 8PDw8A==
88
binary-control-char: !!binary VGhpcyBpcyBhIEJlbGwgY2hhciAH
9+
null string: 'null'
10+
string of digits: '123'
11+
string of digits prefixed with minus character: '-123'
12+
true string: 'true'
13+
false string: 'false'
14+
binary number string: '0b0110'
15+
numeric string: '-1.2E2'
16+
hexadecimal number string: '0xFF'
17+
float string: '10100.1'
18+
positive float string: '+10100.1'
19+
negative float string: '-10100.1'
920

1021
services:
1122
service_container:

0 commit comments

Comments
 (0)
0