Skip to content

Commit 5af84c0

Browse files
Merge branch '7.3' into 7.4
* 7.3: [FrameworkBundle] Don't use Email::VALIDATION_MODES in Configuration [ObjectMapper] initialize lazy objects
2 parents d573b58 + e62ab4e commit 5af84c0

File tree

6 files changed

+83
-3
lines changed

6 files changed

+83
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
use Symfony\Component\Translation\Translator;
4949
use Symfony\Component\TypeInfo\Type;
5050
use Symfony\Component\Uid\Factory\UuidFactory;
51-
use Symfony\Component\Validator\Constraints\Email;
5251
use Symfony\Component\Validator\Validation;
5352
use Symfony\Component\Webhook\Controller\WebhookController;
5453
use Symfony\Component\WebLink\HttpHeaderSerializer;
@@ -1096,7 +1095,7 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e
10961095
->validate()->castToArray()->end()
10971096
->end()
10981097
->scalarNode('translation_domain')->defaultValue('validators')->end()
1099-
->enumNode('email_validation_mode')->values(array_merge(class_exists(Email::class) ? Email::VALIDATION_MODES : ['html5-allow-no-tld', 'html5', 'strict'], ['loose']))->defaultValue('html5')->end()
1098+
->enumNode('email_validation_mode')->values(['html5', 'html5-allow-no-tld', 'strict', 'loose'])->defaultValue('html5')->end()
11001099
->arrayNode('mapping')
11011100
->addDefaultsIfNotSet()
11021101
->fixXmlConfig('path')

src/Symfony/Component/ObjectMapper/ObjectMapper.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\ObjectMapper\Metadata\ReflectionObjectMapperMetadataFactory;
2121
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException as PropertyAccessorNoSuchPropertyException;
2222
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
23+
use Symfony\Component\VarExporter\LazyObjectInterface;
2324

2425
/**
2526
* Object to object mapper.
@@ -316,6 +317,12 @@ private function getSourceReflectionClass(object $source, \ReflectionClass $targ
316317
throw new MappingException($e->getMessage(), $e->getCode(), $e);
317318
}
318319

320+
if ($source instanceof LazyObjectInterface) {
321+
$source->initializeLazyObject();
322+
} elseif (\PHP_VERSION_ID >= 80400 && $refl->isUninitializedLazyObject($source)) {
323+
$refl->initializeLazyObject($source);
324+
}
325+
319326
if ($metadata) {
320327
return $refl;
321328
}
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\ObjectMapper\Tests\Fixtures;
13+
14+
use Symfony\Component\VarExporter\LazyGhostTrait;
15+
use Symfony\Component\VarExporter\LazyObjectInterface;
16+
17+
class LazyFoo extends \stdClass implements LazyObjectInterface
18+
{
19+
use LazyGhostTrait;
20+
21+
public string $name = 'foo';
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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\ObjectMapper\Tests\Fixtures;
13+
14+
class MyProxy
15+
{
16+
public string $name;
17+
}

src/Symfony/Component/ObjectMapper/Tests/ObjectMapperTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use Symfony\Component\ObjectMapper\Tests\Fixtures\InstanceCallback\B as InstanceCallbackB;
4242
use Symfony\Component\ObjectMapper\Tests\Fixtures\InstanceCallbackWithArguments\A as InstanceCallbackWithArgumentsA;
4343
use Symfony\Component\ObjectMapper\Tests\Fixtures\InstanceCallbackWithArguments\B as InstanceCallbackWithArgumentsB;
44+
use Symfony\Component\ObjectMapper\Tests\Fixtures\LazyFoo;
4445
use Symfony\Component\ObjectMapper\Tests\Fixtures\MapStruct\AToBMapper;
4546
use Symfony\Component\ObjectMapper\Tests\Fixtures\MapStruct\MapStructMapperMetadataFactory;
4647
use Symfony\Component\ObjectMapper\Tests\Fixtures\MapStruct\Source;
@@ -52,6 +53,7 @@
5253
use Symfony\Component\ObjectMapper\Tests\Fixtures\MultipleTargetProperty\C as MultipleTargetPropertyC;
5354
use Symfony\Component\ObjectMapper\Tests\Fixtures\MultipleTargets\A as MultipleTargetsA;
5455
use Symfony\Component\ObjectMapper\Tests\Fixtures\MultipleTargets\C as MultipleTargetsC;
56+
use Symfony\Component\ObjectMapper\Tests\Fixtures\MyProxy;
5557
use Symfony\Component\ObjectMapper\Tests\Fixtures\PromotedConstructor\Source as PromotedConstructorSource;
5658
use Symfony\Component\ObjectMapper\Tests\Fixtures\PromotedConstructor\Target as PromotedConstructorTarget;
5759
use Symfony\Component\ObjectMapper\Tests\Fixtures\Recursion\AB;
@@ -369,6 +371,38 @@ public static function objectMapperProvider(): iterable
369371
yield [new ObjectMapper(new ReflectionObjectMapperMetadataFactory(), PropertyAccess::createPropertyAccessor())];
370372
}
371373

374+
public function testMapInitializesLazyObject()
375+
{
376+
$lazy = new LazyFoo();
377+
$mapper = new ObjectMapper();
378+
$mapper->map($lazy, \stdClass::class);
379+
$this->assertTrue($lazy->isLazyObjectInitialized());
380+
}
381+
382+
/**
383+
* @requires PHP 8.4
384+
*/
385+
public function testMapInitializesNativePhp84LazyObject()
386+
{
387+
$initialized = false;
388+
$initializer = function () use (&$initialized) {
389+
$initialized = true;
390+
391+
$p = new MyProxy();
392+
$p->name = 'test';
393+
394+
return $p;
395+
};
396+
397+
$r = new \ReflectionClass(MyProxy::class);
398+
$lazyObj = $r->newLazyProxy($initializer);
399+
$this->assertFalse($initialized);
400+
$mapper = new ObjectMapper();
401+
$d = $mapper->map($lazyObj, MyProxy::class);
402+
$this->assertSame('test', $d->name);
403+
$this->assertTrue($initialized);
404+
}
405+
372406
public function testDecorateObjectMapper()
373407
{
374408
$mapper = new ObjectMapper();

src/Symfony/Component/ObjectMapper/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"psr/container": "^2.0"
2121
},
2222
"require-dev": {
23-
"symfony/property-access": "^7.2|^8.0"
23+
"symfony/property-access": "^7.2|^8.0",
24+
"symfony/var-exporter": "^7.2|^8.0"
2425
},
2526
"autoload": {
2627
"psr-4": {

0 commit comments

Comments
 (0)