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\Command; |
14
|
|
|
|
15
|
|
|
use BenGorFile\FileBundle\DependencyInjection\Compiler\Application\ApplicationBuilder; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Base command builder. |
20
|
|
|
* |
21
|
|
|
* @author Beñat Espiña <[email protected]> |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
abstract class CommandBuilder implements ApplicationBuilder |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Configuration array. |
27
|
|
|
* |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected $configuration; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The container builder. |
34
|
|
|
* |
35
|
|
|
* @var ContainerBuilder |
36
|
|
|
*/ |
37
|
|
|
protected $container; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The persistence driver. |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $persistence; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Constructor. |
48
|
|
|
* |
49
|
|
|
* @param ContainerBuilder $container The container builder |
50
|
|
|
* @param string $persistence The persistence driver |
51
|
|
|
* @param array $configuration The configuration tree |
52
|
|
|
*/ |
53
|
|
|
public function __construct(ContainerBuilder $container, $persistence, array $configuration = []) |
54
|
|
|
{ |
55
|
|
|
$this->container = $container; |
56
|
|
|
$this->persistence = $persistence; |
57
|
|
|
$this->configuration = $configuration; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
public function build($file) |
64
|
|
|
{ |
65
|
|
|
$this->register($file); |
66
|
|
|
|
67
|
|
|
$this->container->setAlias( |
68
|
|
|
$this->aliasDefinitionName($file), |
69
|
|
|
$this->definitionName($file) |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
return $this->container; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Gets the command definition name. |
77
|
|
|
* |
78
|
|
|
* @param string $file The file name |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
abstract protected function definitionName($file); |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Gets the command definition name alias. |
86
|
|
|
* |
87
|
|
|
* @param string $file The file name |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
abstract protected function aliasDefinitionName($file); |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Registers the command into container. |
95
|
|
|
* |
96
|
|
|
* @param string $file The file name |
97
|
|
|
*/ |
98
|
|
|
abstract protected function register($file); |
99
|
|
|
} |
100
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.