|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the BenGorFile package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
|
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace BenGorFile\FileBundle\DependencyInjection\Compiler\Application\DataTransformer; |
|
14
|
|
|
|
|
15
|
|
|
use BenGorFile\FileBundle\DependencyInjection\Compiler\Application\ApplicationBuilder; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* File DTO data transformer builder. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Beñat Espiña <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class FileDTODataTransformerBuilder implements ApplicationBuilder |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Configuration array. |
|
29
|
|
|
* |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $configuration; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* The container builder. |
|
36
|
|
|
* |
|
37
|
|
|
* @var ContainerBuilder |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $container; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* The FQCN or the service id of file data transformer. |
|
43
|
|
|
* |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $dataTransformer; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Constructor. |
|
50
|
|
|
* |
|
51
|
|
|
* @param ContainerBuilder $container The container builder |
|
52
|
|
|
* @param string $dataTransformer The FQCN or the service id of file data transformer |
|
53
|
|
|
* @param array $configuration The configuration tree |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct(ContainerBuilder $container, $dataTransformer, array $configuration = []) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->container = $container; |
|
58
|
|
|
$this->dataTransformer = $dataTransformer; |
|
59
|
|
|
$this->configuration = $configuration; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
*/ |
|
65
|
|
|
public function build($file) |
|
66
|
|
|
{ |
|
67
|
|
|
$dataTransformer = class_exists($this->dataTransformer) |
|
68
|
|
|
? new Definition($this->dataTransformer) |
|
69
|
|
|
: new Reference($this->dataTransformer); |
|
70
|
|
|
|
|
71
|
|
|
$this->container->setDefinition( |
|
72
|
|
|
'bengor.file.application.data_transformer.' . $file . '_dto', |
|
73
|
|
|
$dataTransformer |
|
|
|
|
|
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
$this->container->setAlias( |
|
77
|
|
|
'bengor_file.' . $file . '.dto_data_transformer', |
|
78
|
|
|
'bengor.file.application.data_transformer.' . $file . '_dto' |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
return $this->container; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.