Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit809a413

Browse files
committed
[FrameworkBundle] Object Mapper component bindings
1 parent21b4dd7 commit809a413

File tree

10 files changed

+167
-1
lines changed

10 files changed

+167
-1
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class UnusedTagsPass implements CompilerPassInterface
106106
'validator.group_provider',
107107
'validator.initializer',
108108
'workflow',
109+
'object_mapper.transform_callable',
110+
'object_mapper.condition_callable',
109111
];
110112

111113
publicfunctionprocess(ContainerBuilder$container):void

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@
144144
useSymfony\Component\Notifier\Recipient\Recipient;
145145
useSymfony\Component\Notifier\TexterInterface;
146146
useSymfony\Component\Notifier\Transport\TransportFactoryInterfaceasNotifierTransportFactoryInterface;
147+
useSymfony\Component\ObjectMapper\ConditionCallableInterface;
148+
useSymfony\Component\ObjectMapper\ObjectMapperInterface;
149+
useSymfony\Component\ObjectMapper\TransformCallableInterface;
147150
useSymfony\Component\Process\Messenger\RunProcessMessageHandler;
148151
useSymfony\Component\PropertyAccess\PropertyAccessor;
149152
useSymfony\Component\PropertyInfo\Extractor\ConstructorArgumentTypeExtractorInterface;
@@ -863,6 +866,14 @@ private function registerFormConfiguration(array $config, ContainerBuilder $cont
863866
if (!ContainerBuilder::willBeAvailable('symfony/translation', Translator::class, ['symfony/framework-bundle','symfony/form'])) {
864867
$container->removeDefinition('form.type_extension.upload.validator');
865868
}
869+
870+
if (ContainerBuilder::willBeAvailable('symfony/object-mapper', ObjectMapperInterface::class, ['symfony/framework-bundle'])) {
871+
$loader->load('object_mapper.php');
872+
$container->registerForAutoconfiguration(TransformCallableInterface::class)
873+
->addTag('object_mapper.transform_callable');
874+
$container->registerForAutoconfiguration(ConditionCallableInterface::class)
875+
->addTag('object_mapper.condition_callable');
876+
}
866877
}
867878

868879
privatefunctionregisterHttpCacheConfiguration(array$config,ContainerBuilder$container,bool$httpMethodOverride):void
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
namespaceSymfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
useSymfony\Component\ObjectMapper\Metadata\ObjectMapperMetadataFactoryInterface;
15+
useSymfony\Component\ObjectMapper\Metadata\ReflectionObjectMapperMetadataFactory;
16+
useSymfony\Component\ObjectMapper\ObjectMapper;
17+
useSymfony\Component\ObjectMapper\ObjectMapperInterface;
18+
19+
returnstaticfunction (ContainerConfigurator$container) {
20+
$container->services()
21+
->set('object_mapper.metadata_factory', ReflectionObjectMapperMetadataFactory::class)
22+
->alias(ObjectMapperMetadataFactoryInterface::class,'object_mapper.metadata_factory')
23+
24+
->set('object_mapper', ObjectMapper::class)
25+
->args([
26+
service('object_mapper.metadata_factory'),
27+
service('property_accessor')->ignoreOnInvalid(),
28+
tagged_locator('object_mapper.transform_callable'),
29+
tagged_locator('object_mapper.condition_callable'),
30+
])
31+
->alias(ObjectMapperInterface::class,'object_mapper')
32+
;
33+
};
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+
namespaceSymfony\Bundle\FrameworkBundle\Tests\Fixtures\ObjectMapper;
13+
14+
finalclass ObjectMapped
15+
{
16+
publicstring$a;
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
namespaceSymfony\Bundle\FrameworkBundle\Tests\Fixtures\ObjectMapper;
13+
14+
useSymfony\Component\ObjectMapper\Attribute\Map;
15+
16+
#[Map(target: ObjectMapped::class)]
17+
finalclass ObjectToBeMapped
18+
{
19+
#[Map(transform: TransformCallable::class)]
20+
publicstring$a ='nottransformed';
21+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
namespaceSymfony\Bundle\FrameworkBundle\Tests\Fixtures\ObjectMapper;
13+
14+
useSymfony\Component\ObjectMapper\TransformCallableInterface;
15+
16+
/**
17+
* @implements TransformCallableInterface<ObjectToBeMapped>
18+
*/
19+
finalclass TransformCallableimplements TransformCallableInterface
20+
{
21+
publicfunction__invoke(mixed$value,object$object):mixed
22+
{
23+
return'transformed';
24+
}
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
namespaceSymfony\Bundle\FrameworkBundle\Tests\Functional;
13+
14+
useSymfony\Bundle\FrameworkBundle\Tests\Fixtures\ObjectMapper\ObjectMapped;
15+
useSymfony\Bundle\FrameworkBundle\Tests\Fixtures\ObjectMapper\ObjectToBeMapped;
16+
17+
/**
18+
* @author Kévin Dunglas <dunglas@gmail.com>
19+
*/
20+
class ObjectMapperTestextends AbstractWebTestCase
21+
{
22+
publicfunctiontestObjectMapper()
23+
{
24+
static::bootKernel(['test_case' =>'ObjectMapper']);
25+
26+
/** @var Symfony\Component\ObjectMapper\ObjectMapperInterface<ObjectMapped> */
27+
$objectMapper =static::getContainer()->get('object_mapper.alias');
28+
$mapped =$objectMapper->map(newObjectToBeMapped());
29+
$this->assertSame($mapped->a,'transformed');
30+
}
31+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
useSymfony\Bundle\FrameworkBundle\FrameworkBundle;
13+
14+
return [
15+
newFrameworkBundle(),
16+
];
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
imports:
2+
-{ resource: ../config/default.yml }
3+
4+
services:
5+
object_mapper.alias:
6+
alias:object_mapper
7+
public:true
8+
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\ObjectMapper\TransformCallable:
9+
autoconfigure:true

‎src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"symfony/scheduler":"^6.4.4|^7.0.4",
6060
"symfony/security-bundle":"^6.4|^7.0",
6161
"symfony/semaphore":"^6.4|^7.0",
62-
"symfony/serializer":"^7.1",
62+
"symfony/serializer":"^6.4|^7.0",
63+
"symfony/object-mapper":"^7.3",
6364
"symfony/stopwatch":"^6.4|^7.0",
6465
"symfony/string":"^6.4|^7.0",
6566
"symfony/translation":"^7.3",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp