Skip to content

Commit 9c27c32

Browse files
Merge branch '6.3' into 6.4
* 6.3: Fix support to denormalize plain object types [Routing] Restore aliases removal in RouteCollection::remove() remove duplicated service definition
2 parents 1a824c1 + c7ad175 commit 9c27c32

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
55
<services>
6-
<service id="monolog.logger" parent="monolog.logger_prototype">
7-
<argument index="0">app</argument>
8-
</service>
9-
106
<service id="logger" alias="monolog.logger" />
117

128
<service id="monolog.logger" parent="monolog.logger_prototype">

src/Symfony/Component/Routing/RouteCollection.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,21 @@ public function get(string $name): ?Route
147147
*/
148148
public function remove(string|array $name)
149149
{
150-
$names = (array) $name;
151-
foreach ($names as $n) {
152-
unset($this->routes[$n], $this->priorities[$n]);
150+
$routes = [];
151+
foreach ((array) $name as $n) {
152+
if (isset($this->routes[$n])) {
153+
$routes[] = $n;
154+
}
155+
156+
unset($this->routes[$n], $this->priorities[$n], $this->aliases[$n]);
157+
}
158+
159+
if (!$routes) {
160+
return;
153161
}
154162

155163
foreach ($this->aliases as $k => $alias) {
156-
if (\in_array($alias->getId(), $names, true)) {
164+
if (\in_array($alias->getId(), $routes, true)) {
157165
unset($this->aliases[$k]);
158166
}
159167
}

src/Symfony/Component/Routing/Tests/RouteCollectionTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,22 @@ public function testGet()
219219
public function testRemove()
220220
{
221221
$collection = new RouteCollection();
222-
$collection->add('foo', $foo = new Route('/foo'));
222+
$collection->add('foo', new Route('/foo'));
223223

224224
$collection1 = new RouteCollection();
225225
$collection1->add('bar', $bar = new Route('/bar'));
226226
$collection->addCollection($collection1);
227227
$collection->add('last', $last = new Route('/last'));
228-
$collection->addAlias('ccc_my_custom_alias', 'foo');
228+
$collection->addAlias('alias_removed_when_removing_route_foo', 'foo');
229+
$collection->addAlias('alias_directly_removed', 'bar');
229230

230231
$collection->remove('foo');
231232
$this->assertSame(['bar' => $bar, 'last' => $last], $collection->all(), '->remove() can remove a single route');
233+
$collection->remove('alias_directly_removed');
234+
$this->assertNull($collection->getAlias('alias_directly_removed'));
232235
$collection->remove(['bar', 'last']);
233236
$this->assertSame([], $collection->all(), '->remove() accepts an array and can remove multiple routes at once');
234-
$this->assertNull($collection->getAlias('ccc_my_custom_alias'));
237+
$this->assertNull($collection->getAlias('alias_removed_when_removing_route_foo'));
235238
}
236239

237240
public function testSetHost()

src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ private function validateAndDenormalize(array $types, string $currentClass, stri
547547

548548
$expectedTypes[Type::BUILTIN_TYPE_OBJECT === $builtinType && $class ? $class : $builtinType] = true;
549549

550-
if (Type::BUILTIN_TYPE_OBJECT === $builtinType) {
550+
if (Type::BUILTIN_TYPE_OBJECT === $builtinType && null !== $class) {
551551
if (!$this->serializer instanceof DenormalizerInterface) {
552552
throw new LogicException(sprintf('Cannot denormalize attribute "%s" for class "%s" because injected serializer is not a denormalizer.', $attribute, $class));
553553
}

src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ public function testDenormalizeWithExtraAttributesAndNoGroupsWithMetadataFactory
121121
);
122122
}
123123

124+
public function testDenormalizePlainObject()
125+
{
126+
$extractor = new PhpDocExtractor();
127+
$normalizer = new ObjectNormalizer(null, null, null, $extractor);
128+
$dummy = $normalizer->denormalize(['plainObject' => (object) ['foo' => 'bar']], DummyWithPlainObject::class);
129+
130+
$this->assertInstanceOf(DummyWithPlainObject::class, $dummy);
131+
$this->assertInstanceOf(\stdClass::class, $dummy->plainObject);
132+
$this->assertSame('bar', $dummy->plainObject->foo);
133+
}
134+
124135
public function testDenormalizeWithDuplicateNestedAttributes()
125136
{
126137
$this->expectException(LogicException::class);
@@ -1104,6 +1115,12 @@ protected function setAttributeValue(object $object, string $attribute, $value,
11041115
}
11051116
}
11061117

1118+
class DummyWithPlainObject
1119+
{
1120+
/** @var object */
1121+
public $plainObject;
1122+
}
1123+
11071124
class ObjectWithBasicProperties
11081125
{
11091126
/** @var bool */

0 commit comments

Comments
 (0)