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) |
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() |
|
|
|
|
58
|
|
|
); |
59
|
|
|
}) |
60
|
|
|
->setCacheDir($configProvider->get('app.cache_dir')) |
61
|
|
|
->setDebug($configProvider->get('app.debug')) |
62
|
|
|
->build()); |
63
|
|
|
}; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths