1 | <?php declare(strict_types=1); |
||||
2 | /** |
||||
3 | * This file is part of the daikon-cqrs/boot project. |
||||
4 | * |
||||
5 | * For the full copyright and license information, please view the LICENSE |
||||
6 | * file that was distributed with this source code. |
||||
7 | */ |
||||
8 | |||||
9 | namespace Daikon\Boot\Service\Provisioner; |
||||
10 | |||||
11 | use Auryn\Injector; |
||||
12 | use Daikon\Boot\Middleware\Action\SerializerInterface; |
||||
13 | use Daikon\Boot\Service\ServiceDefinitionInterface; |
||||
14 | use Daikon\Config\ConfigProviderInterface; |
||||
15 | use Daikon\ValueObject\ValueObjectInterface; |
||||
16 | use Doctrine\Common\Annotations\SimpleAnnotationReader; |
||||
17 | use JMS\Serializer\GraphNavigatorInterface; |
||||
18 | use JMS\Serializer\Handler\HandlerRegistry; |
||||
19 | use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy; |
||||
20 | use JMS\Serializer\SerializerBuilder; |
||||
21 | |||||
22 | class JMSSerializerServiceProvisioner implements ProvisionerInterface |
||||
23 | { |
||||
24 | public function provision( |
||||
25 | Injector $injector, |
||||
26 | ConfigProviderInterface $configProvider, |
||||
27 | ServiceDefinitionInterface $serviceDefinition |
||||
28 | ): void { |
||||
29 | $className = $serviceDefinition->getServiceClass(); |
||||
30 | $settings = $serviceDefinition->getSettings(); |
||||
31 | |||||
32 | $injector |
||||
33 | ->alias(SerializerInterface::class, $className) |
||||
34 | ->share($className) |
||||
35 | ->delegate($className, $this->factory($className, $configProvider, $settings)); |
||||
36 | } |
||||
37 | |||||
38 | private function factory( |
||||
39 | string $className, |
||||
40 | ConfigProviderInterface $configProvider, |
||||
41 | array $settings |
||||
42 | ): callable { |
||||
43 | return function () use ($className, $configProvider, $settings): SerializerInterface { |
||||
44 | return new $className(SerializerBuilder::create() |
||||
45 | ->setPropertyNamingStrategy(new IdenticalPropertyNamingStrategy) |
||||
46 | ->setAnnotationReader(new SimpleAnnotationReader) |
||||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||||
47 | ->setMetadataDirs((array)($settings['metadata_dirs'] ?? [])) |
||||
48 | ->configureHandlers(function (HandlerRegistry $registry): void { |
||||
49 | $registry->registerHandler( |
||||
50 | GraphNavigatorInterface::DIRECTION_SERIALIZATION, |
||||
51 | 'ValueObject', |
||||
52 | 'json', |
||||
53 | /** |
||||
54 | * @param mixed $visitor |
||||
55 | * @return mixed |
||||
56 | */ |
||||
57 | fn($visitor, ValueObjectInterface $valueObject, array $type) => $valueObject->toNative() |
||||
0 ignored issues
–
show
The parameter
$type is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
58 | ); |
||||
59 | }) |
||||
60 | ->setCacheDir($configProvider->get('app.cache_dir')) |
||||
61 | ->setDebug($configProvider->get('app.debug')) |
||||
62 | ->build()); |
||||
63 | }; |
||||
64 | } |
||||
65 | } |
||||
66 |