Skip to content

Commit 427d086

Browse files
Merge branch '5.0'
* 5.0: [DI] auto-register singly implemented interfaces by default [DI] fix overriding existing services with aliases for singly-implemented interfaces remove service when base class is missing do not depend on the QueryBuilder from the ORM [Security/Http] call auth listeners/guards eagerly when they "support" the request [Messenger] add tests to FailedMessagesShowCommand Fix the translation commands when a template contains a syntax error [Security] Fix clearing remember-me cookie after deauthentication [Validator] Update Slovenian translations [HttpClient] remove conflict rule with HttpKernel that prevents using the component in Symfony 3.4 [Config][ReflectionClassResource] Handle parameters with undefined constant as their default values Fix compatibility with Monolog 2 fix dumping number-like string parameters Fix CI [Console] Fix autocomplete multibyte input support [Config] don't break on virtual stack frames in ClassExistenceResource more robust initialization from request Changing the multipart form-data behavior to use the form name as an array, which makes it recognizable as an array by PHP on the $_POST globals once it is coming from the HttpClient component
2 parents d4994b4 + 100594f commit 427d086

File tree

10 files changed

+64
-7
lines changed

10 files changed

+64
-7
lines changed

Dumper/XmlDumper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ private function convertParameters(array $parameters, string $type, \DOMElement
316316
if (\in_array($value, ['null', 'true', 'false'], true)) {
317317
$element->setAttribute('type', 'string');
318318
}
319+
320+
if (\is_string($value) && (is_numeric($value) || preg_match('/^0b[01]*$/', $value) || preg_match('/^0x[0-9a-f]++$/i', $value))) {
321+
$element->setAttribute('type', 'string');
322+
}
323+
319324
$text = $this->document->createTextNode(self::phpToXml($value));
320325
$element->appendChild($text);
321326
}

Loader/FileLoader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ abstract class FileLoader extends BaseFileLoader
3636
protected $instanceof = [];
3737
protected $interfaces = [];
3838
protected $singlyImplemented = [];
39+
protected $autoRegisterAliasesForSinglyImplementedInterfaces = true;
3940

4041
public function __construct(ContainerBuilder $container, FileLocatorInterface $locator)
4142
{
@@ -114,12 +115,16 @@ public function registerClasses(Definition $prototype, $namespace, $resource, $e
114115
}
115116
}
116117
}
118+
119+
if ($this->autoRegisterAliasesForSinglyImplementedInterfaces) {
120+
$this->registerAliasesForSinglyImplementedInterfaces();
121+
}
117122
}
118123

119124
public function registerAliasesForSinglyImplementedInterfaces()
120125
{
121126
foreach ($this->interfaces as $interface) {
122-
if (!empty($this->singlyImplemented[$interface]) && !$this->container->hasAlias($interface)) {
127+
if (!empty($this->singlyImplemented[$interface]) && !$this->container->has($interface)) {
123128
$this->container->setAlias($interface, $this->singlyImplemented[$interface])->setPublic(false);
124129
}
125130
}

Loader/PhpFileLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
class PhpFileLoader extends FileLoader
2525
{
26+
protected $autoRegisterAliasesForSinglyImplementedInterfaces = false;
27+
2628
/**
2729
* {@inheritdoc}
2830
*/

Loader/XmlFileLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class XmlFileLoader extends FileLoader
3636
{
3737
const NS = 'http://symfony.com/schema/dic/services';
3838

39+
protected $autoRegisterAliasesForSinglyImplementedInterfaces = false;
40+
3941
/**
4042
* {@inheritdoc}
4143
*/

Loader/YamlFileLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class YamlFileLoader extends FileLoader
110110
private $anonymousServicesCount;
111111
private $anonymousServicesSuffix;
112112

113+
protected $autoRegisterAliasesForSinglyImplementedInterfaces = false;
114+
113115
/**
114116
* {@inheritdoc}
115117
*/

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;

Tests/Fixtures/php/services8.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ protected function getDefaultParameters(): array
108108
],
109109
'binary' => 'ðððð',
110110
'binary-control-char' => 'This is a Bell char ',
111+
'null string' => 'null',
112+
'string of digits' => '123',
113+
'string of digits prefixed with minus character' => '-123',
114+
'true string' => 'true',
115+
'false string' => 'false',
116+
'binary number string' => '0b0110',
117+
'numeric string' => '-1.2E2',
118+
'hexadecimal number string' => '0xFF',
119+
'float string' => '10100.1',
120+
'positive float string' => '+10100.1',
121+
'negative float string' => '-10100.1',
111122
];
112123
}
113124
}

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"/>

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:

Tests/Loader/FileLoaderTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function testRegisterClasses()
8989
$container = new ContainerBuilder();
9090
$container->setParameter('sub_dir', 'Sub');
9191
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));
92+
$loader->autoRegisterAliasesForSinglyImplementedInterfaces = false;
9293

9394
$loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\\', 'Prototype/%sub_dir%/*');
9495
$loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\\', 'Prototype/%sub_dir%/*'); // loading twice should not be an issue
@@ -121,7 +122,6 @@ public function testRegisterClassesWithExclude()
121122
// load everything, except OtherDir/AnotherSub & Foo.php
122123
'Prototype/{%other_dir%/AnotherSub,Foo.php}'
123124
);
124-
$loader->registerAliasesForSinglyImplementedInterfaces();
125125

126126
$this->assertTrue($container->has(Bar::class));
127127
$this->assertTrue($container->has(Baz::class));
@@ -151,7 +151,6 @@ public function testRegisterClassesWithExcludeAsArray()
151151
'Prototype/OtherDir/AnotherSub/DeeperBaz.php',
152152
]
153153
);
154-
$loader->registerAliasesForSinglyImplementedInterfaces();
155154

156155
$this->assertTrue($container->has(Foo::class));
157156
$this->assertTrue($container->has(Baz::class));
@@ -167,7 +166,6 @@ public function testNestedRegisterClasses()
167166
$prototype = new Definition();
168167
$prototype->setPublic(true)->setPrivate(true);
169168
$loader->registerClasses($prototype, 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\\', 'Prototype/*');
170-
$loader->registerAliasesForSinglyImplementedInterfaces();
171169

172170
$this->assertTrue($container->has(Bar::class));
173171
$this->assertTrue($container->has(Baz::class));
@@ -199,7 +197,6 @@ public function testMissingParentClass()
199197
'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\\',
200198
'Prototype/%bad_classes_dir%/*'
201199
);
202-
$loader->registerAliasesForSinglyImplementedInterfaces();
203200

204201
$this->assertTrue($container->has(MissingParent::class));
205202

@@ -218,7 +215,6 @@ public function testRegisterClassesWithBadPrefix()
218215

219216
// the Sub is missing from namespace prefix
220217
$loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\\', 'Prototype/Sub/*');
221-
$loader->registerAliasesForSinglyImplementedInterfaces();
222218
}
223219

224220
public function testRegisterClassesWithIncompatibleExclude()
@@ -234,12 +230,13 @@ public function testRegisterClassesWithIncompatibleExclude()
234230
'Prototype/*',
235231
'yaml/*'
236232
);
237-
$loader->registerAliasesForSinglyImplementedInterfaces();
238233
}
239234
}
240235

241236
class TestFileLoader extends FileLoader
242237
{
238+
public $autoRegisterAliasesForSinglyImplementedInterfaces = true;
239+
243240
public function load($resource, string $type = null)
244241
{
245242
return $resource;

0 commit comments

Comments
 (0)