8000 Merge branch '6.4' into 7.0 · symfony/symfony@a57c20b · GitHub
[go: up one dir, main page]

Skip to content

Commit a57c20b

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: [Serializer] Fix merge [VarExporter] add `#[Ignore]` to proxy-related methods to prevent them from being serialized
2 parents ce5447b + 2083154 commit a57c20b

8 files changed

+73
-24
lines changed

src/Symfony/Component/Serializer/Tests/Fixtures/SamePropertyAsMethodWithMethodSerializedNameDummy.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,25 @@ public function __construct($freeTrial, $hasSubscribe, $getReady, $isActive)
2828
$this->isActive = $isActive;
2929
}
3030

31-
/**
32-
* @SerializedName("free_trial_method")
33-
*/
31+
#[SerializedName('free_trial_method')]
3432
public function getFreeTrial()
3533
{
3634
return $this->freeTrial;
3735
}
3836

39-
/**
40-
* @SerializedName("has_subscribe_method")
41-
*/
37+
#[SerializedName('has_subscribe_method')]
4238
public function hasSubscribe()
4339
{
4440
return $this->hasSubscribe;
4541
}
4642

47-
/**
48-
* @SerializedName("get_ready_method")
49-
*/
43+
#[SerializedName('get_ready_method')]
5044
public function getReady()
5145
{
5246
return $this->getReady;
5347
}
5448

55-
/**
56-
* @SerializedName("is_active_method")
57-
*/
49+
#[SerializedName('is_active_method')]
5850
public function isActive()
5951
{
6052
return $this->isActive;

src/Symfony/Component/Serializer/Tests/Fixtures/SamePropertyAsMethodWithPropertySerializedNameDummy.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,16 @@
1515

1616
class SamePropertyAsMethodWithPropertySerializedNameDummy
1717
{
18-
/**
19-
* @SerializedName("free_trial_property")
20-
*/
18+
#[SerializedName('free_trial_property')]
2119
private $freeTrial;
2220

23-
/**
24-
* @SerializedName("has_subscribe_property")
25-
*/
21+
#[SerializedName('has_subscribe_property')]
2622
private $hasSubscribe;
2723

28-
/**
29-
* @SerializedName("get_ready_property")
30-
*/
24+
#[SerializedName('get_ready_property')]
3125
private $getReady;
3226

33-
/**
34-
* @SerializedName("is_active_property")
35-
*/
27+
#[SerializedName('is_active_property')]
3628
private $isActive;
3729

3830
public function __construct($freeTrial, $hasSubscribe, $getReady, $isActive)

src/Symfony/Component/VarExporter/Internal/LazyObjectTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111

1212
namespace Symfony\Component\VarExporter\Internal;
1313

14+
use Symfony\Component\Serializer\Attribute\Ignore;
15+
1416
if (\PHP_VERSION_ID >= 80300) {
1517
/**
1618
* @internal
1719
*/
1820
trait LazyObjectTrait
1921
{
22+
#[Ignore]
2023
private readonly LazyObjectState $lazyObjectState;
2124
}
2225
} else {
@@ -25,6 +28,7 @@ trait LazyObjectTrait
2528
*/
2629
trait LazyObjectTrait
2730
{
31+
#[Ignore]
2832
private LazyObjectState $lazyObjectState;
2933
}
3034
}

src/Symfony/Component/VarExporter/LazyGhostTrait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\VarExporter;
1313

14+
use Symfony\Component\Serializer\Attribute\Ignore;
1415
use Symfony\Component\VarExporter\Internal\Hydrator;
1516
use Symfony\Component\VarExporter\Internal\LazyObjectRegistry as Registry;
1617
use Symfony\Component\VarExporter\Internal\LazyObjectState;
@@ -55,6 +56,7 @@ public static function createLazyGhost(\Closure $initializer, ?array $skippedPro
5556
*
5657
* @param $partial Whether partially initialized objects should be considered as initialized
5758
*/
59+
#[Ignore]
5860
public function isLazyObjectInitialized(bool $partial = false): bool
5961
{
6062
if (!$state = $this->lazyObjectState ?? null) {
@@ -331,6 +333,7 @@ public function __destruct()
331333
}
332334
}
333335

336+
#[Ignore]
334337
private function setLazyObjectAsInitialized(bool $initialized): void
335338
{
336339
if ($state = $this->lazyObjectState ?? null) {

src/Symfony/Component/VarExporter/LazyProxyTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\VarExporter;
1313

14+
use Symfony\Component\Serializer\Attribute\Ignore;
1415
use Symfony\Component\VarExporter\Hydrator as PublicHydrator;
1516
use Symfony\Component\VarExporter\Internal\Hydrator;
1617
use Symfony\Component\VarExporter\Internal\LazyObjectRegistry as Registry;
@@ -50,6 +51,7 @@ public static function createLazyProxy(\Closure $initializer, ?object $instance
5051
*
5152
* @param $partial Whether partially initialized objects should be considered as initialized
5253
*/
54+
#[Ignore]
5355
public function isLazyObjectInitialized(bool $partial = false): bool
5456
{
5557
return !isset($this->lazyObjectState) || isset($this->lazyObjectState->realInstance) || Registry::$noInitializerState === $this->lazyObjectState->initializer;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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\VarExporter\Tests\Fixtures;
13+
14+
class SimpleObject
15+
{
16+
public function getMethod(): string
17+
{
18+
return 'method';
19+
}
20+
21+
public string $property = 'property';
22+
}

src/Symfony/Component/VarExporter/Tests/LazyGhostTraitTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
namespace Symfony\Component\VarExporter\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
16+
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
17+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
1518
use Symfony\Component\VarExporter\ProxyHelper;
1619
use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\ChildMagicClass;
1720
use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\ChildStdClass;
@@ -21,6 +24,7 @@
2124
use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\MagicClass;
2225
use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\ReadOnlyClass;
2326
use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\TestClass;
27+
use Symfony\Component\VarExporter\Tests\Fixtures\SimpleObject;
2428

2529
class LazyGhostTraitTest extends TestCase
2630
{
@@ -263,6 +267,19 @@ public function testAccessingUninializedPropertyWithLazyGhost()
263267
$object->property;
264268
}
265269

270+
public function testNormalization()
271+
{
272+
$object = $this->createLazyGhost(SimpleObject::class, function ($instance) {});
273+
274+
$loader = new AttributeLoader();
275+
$metadataFactory = new ClassMetadataFactory($loader);
276+
$serializer = new ObjectNormalizer($metadataFactory);
277+
278+
$output = $serializer->normalize($object);
279+
280+
$this->assertSame(['property' => 'property', 'method' => 'method'], $output);
281+
}
282+
266283
/**
267284
* @template T
268285
*

src/Symfony/Component/VarExporter/Tests/LazyProxyTraitTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
namespace Symfony\Component\VarExporter\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
16+
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
17+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
1518
use Symfony\Component\VarExporter\Exception\LogicException;
1619
use Symfony\Component\VarExporter\LazyProxyTrait;
1720
use Symfony\Component\VarExporter\ProxyHelper;
@@ -22,6 +25,7 @@
2225
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\TestOverwritePropClass;
2326
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\TestUnserializeClass;
2427
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\TestWakeupClass;
28+
use Symfony\Component\VarExporter\Tests\Fixtures\SimpleObject;
2529

2630
class LazyProxyTraitTest extends TestCase
2731
{
@@ -278,6 +282,19 @@ public function __construct()
278282
$this->assertSame(['foo' => 123], (array) $obj->getDep());
279283
}
280284

285+
public function testNormalization()
286+
{
287+
$object = $this->createLazyProxy(SimpleObject::class, fn () => new SimpleObject());
288+
289+
$loader = new AttributeLoader();
290+
$metadataFactory = new ClassMetadataFactory($loader);
291+
$serializer = new ObjectNormalizer($metadataFactory);
292+
293+
$output = $serializer->normalize($object);
294+
295+
$this->assertSame(['property' => 'property', 'method' => 'method'], $output);
296+
}
297+
281298
/**
282299
* @template T
283300
*

0 commit comments

Comments
 (0)
0