Skip to content

Commit 1a030ec

Browse files
authored
Merge pull request #859 from schmittjoh/php-attributes-support
Add support for php8 attributes
2 parents 4a403d8 + 97d5002 commit 1a030ec

File tree

6 files changed

+20
-10
lines changed

6 files changed

+20
-10
lines changed

DependencyInjection/JMSSerializerExtension.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
88
use JMS\Serializer\Exception\RuntimeException;
99
use JMS\Serializer\Handler\SubscribingHandlerInterface;
10+
use JMS\Serializer\Metadata\Driver\AttributeDriver\AttributeReader;
1011
use JMS\Serializer\Metadata\Driver\DocBlockDriver;
1112
use JMS\Serializer\Metadata\Driver\TypedPropertiesDriver;
1213
use Symfony\Component\Config\FileLocator;
@@ -113,8 +114,7 @@ public function loadInternal(array $config, ContainerBuilder $container)
113114
if ($config['metadata']['infer_types_from_doc_block'] && class_exists(DocBlockDriver::class)) {
114115
$container->getDefinition('jms_serializer.metadata.doc_block_driver')
115116
->setDecoratedService('jms_serializer.metadata_driver')
116-
->setPublic(false)
117-
;
117+
->setPublic(false);
118118
}
119119

120120
if (PHP_VERSION_ID >= 70400 && class_exists(TypedPropertiesDriver::class)) {
@@ -123,6 +123,14 @@ public function loadInternal(array $config, ContainerBuilder $container)
123123
->setPublic(false);
124124
}
125125

126+
if (PHP_VERSION_ID >= 80000 && class_exists(AttributeReader::class)) {
127+
$container->register('jms_serializer.metadata.annotation_and_attributes_reader', AttributeReader::class)
128+
->setArgument(0, new Reference('annotation_reader'));
129+
130+
$container->findDefinition('jms_serializer.metadata.annotation_driver')
131+
->setArgument(0, new Reference('jms_serializer.metadata.annotation_and_attributes_reader'));
132+
}
133+
126134
$container
127135
->getDefinition('jms_serializer.metadata_factory')
128136
->replaceArgument(2, $config['metadata']['debug'])

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ public function testCacheServicesRemovedWhenMetadataCachingIsDisabled(): void
5959
{
6060
$container = $this->getContainer([
6161
[
62-
'metadata' => [
63-
'cache' => 'none',
64-
],
65-
]
62+
'metadata' => ['cache' => 'none'],
63+
],
6664
]);
6765

6866
self::assertFalse($container->has('jms_serializer.metadata.cache'));

Tests/DependencyInjection/Fixture/IncludeInterfaces/AnInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace JMS\SerializerBundle\Tests\DependencyInjection\Fixture\IncludeInterfaces;
46

57
use JMS\Serializer\Annotation\Discriminator;

Tests/DependencyInjection/Fixture/IncludeInterfaces/AnInterfaceImplementation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace JMS\SerializerBundle\Tests\DependencyInjection\Fixture\IncludeInterfaces;
46

57
use JMS\Serializer\Annotation\Type;

Tests/DependencyInjection/Fixture/IncludeInterfaces/AnObject.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace JMS\SerializerBundle\Tests\DependencyInjection\Fixture\IncludeInterfaces;
46

57
use JMS\Serializer\Annotation\Type;

Tests/DependencyInjection/JMSSerializerExtensionTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,8 @@ public function testIncludeInterfaces()
650650
{
651651
$container = $this->getContainerForConfig([
652652
[
653-
'metadata' => [
654-
'include_interfaces' => true,
655-
],
656-
]
653+
'metadata' => ['include_interfaces' => true],
654+
],
657655
]);
658656
$serializer = $container->get('jms_serializer');
659657

0 commit comments

Comments
 (0)