|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace JMS\Serializer\Builder; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Annotations\Reader; |
|
8
|
|
|
use JMS\Serializer\Metadata\Driver\AnnotationDriver; |
|
9
|
|
|
use JMS\Serializer\Metadata\Driver\AttributeDriver; |
|
10
|
|
|
use JMS\Serializer\Naming\PropertyNamingStrategyInterface; |
|
11
|
|
|
use JMS\Serializer\Type\ParserInterface; |
|
12
|
|
|
use Metadata\Driver\DriverInterface; |
|
13
|
|
|
|
|
14
|
|
|
class AttributeDriverFactory implements DriverFactoryInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var DriverFactoryInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $driverFactoryToDecorate; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var PropertyNamingStrategyInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $propertyNamingStrategy; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var ParserInterface|null |
|
28
|
|
|
*/ |
|
29
|
|
|
private $typeParser; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct( |
|
32
|
|
|
DriverFactoryInterface $driverFactoryToDecorate, |
|
33
|
|
|
PropertyNamingStrategyInterface $propertyNamingStrategy, |
|
34
|
|
|
?ParserInterface $typeParser = null, |
|
35
|
|
|
) { |
|
36
|
|
|
$this->driverFactoryToDecorate = $driverFactoryToDecorate; |
|
37
|
|
|
$this->propertyNamingStrategy = $propertyNamingStrategy; |
|
38
|
|
|
$this->typeParser = $typeParser; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function createDriver(array $metadataDirs, Reader $annotationReader): DriverInterface |
|
42
|
|
|
{ |
|
43
|
|
|
$decoratedDriver = $this->driverFactoryToDecorate->createDriver($metadataDirs, $annotationReader); |
|
44
|
|
|
|
|
45
|
|
|
$attributeAnnotationDriver = new AnnotationDriver(new AttributeDriver\AttributeReader(), $this->propertyNamingStrategy, $this->typeParser); |
|
46
|
|
|
|
|
47
|
|
|
return new AttributeDriver($attributeAnnotationDriver, $decoratedDriver); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|