Skip to content

Commit

Permalink
Merge pull request #27 from spiral-packages/feauture/symfony7-0-support
Browse files Browse the repository at this point in the history
Adds support for Symfony 7.x
  • Loading branch information
msmakouz committed Mar 18, 2024
2 parents 21f1888 + b9e13f2 commit a81c894
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
"spiral/config": "^3.7",
"doctrine/annotations": "^1.12 || ^2.0",
"spiral/serializer": "^3.7",
"symfony/serializer": "^5.4 || ^6.0",
"symfony/property-access": "^5.4 || ^6.0"
"symfony/serializer": "^5.4 || ^6.0 || ^7.0",
"symfony/property-access": "^5.4 || ^6.0 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^10.2",
"spiral/testing": "^2.3",
"spiral/testing": "^2.7",
"symfony/yaml": "^5.4 || ^6.0 || ^7.0",
"symfony/yaml": "^5.4 || ^6.0",
"vimeo/psalm": "^5.12",
"ramsey/uuid": "^4.7"
Expand Down
15 changes: 14 additions & 1 deletion src/Config/SerializerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\Common\Annotations\AnnotationReader;
use Symfony\Component\Messenger\Transport\Serialization\Normalizer\FlattenExceptionNormalizer;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
use Symfony\Component\Serializer\Mapping\Loader\LoaderInterface;
use Spiral\Core\InjectableConfig;

Expand Down Expand Up @@ -37,6 +38,18 @@ public function getNormalizers(): array

public function getMetadataLoader(): LoaderInterface
{
return $this->config['metadataLoader'] ?? new AnnotationLoader(new AnnotationReader());
if (!empty($this->config['metadataLoader'])) {
return $this->config['metadataLoader'];
}

if (\class_exists(AttributeLoader::class)) {
return new AttributeLoader();
}

if (\class_exists(AnnotationLoader::class)) {
return new AnnotationLoader(new AnnotationReader());
}

throw new \LogicException('No metadata loader found');
}
}
17 changes: 12 additions & 5 deletions tests/src/Unit/Bootloader/SerializerBootloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
use Symfony\Component\Serializer\Mapping\Loader\LoaderInterface;
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
use Symfony\Component\Serializer\Normalizer\UidNormalizer;
Expand All @@ -36,8 +37,8 @@ public function testConfigureEncoders(): void
'encoders' => [
JsonEncoder::class,
new CsvEncoder(),
new Autowire(XmlEncoder::class)
]
new Autowire(XmlEncoder::class),
],
]));

$this->assertCount(3, $registry->all());
Expand All @@ -49,7 +50,13 @@ public function testConfigureEncoders(): void
public function testConfigureNormalizers(): void
{
$container = new Container();
$container->bind(LoaderInterface::class, new AnnotationLoader(new AnnotationReader()));

if (\class_exists(AttributeLoader::class)) {
$container->bind(LoaderInterface::class, new AttributeLoader());
} elseif (\class_exists(AnnotationLoader::class)) {
$container->bind(LoaderInterface::class, new AnnotationLoader(new AnnotationReader()));
}

$container->bind(EnvironmentInterface::class, new Environment());

$bootloader = new SerializerBootloader($container);
Expand All @@ -61,8 +68,8 @@ public function testConfigureNormalizers(): void
'normalizers' => [
UnwrappingDenormalizer::class,
new UidNormalizer(),
new Autowire(JsonSerializableNormalizer::class)
]
new Autowire(JsonSerializableNormalizer::class),
],
]), $container);

$this->assertCount(3, $registry->all());
Expand Down

0 comments on commit a81c894

Please sign in to comment.