1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Cli\Loaders\ContainerParameterLoader |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-cli |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Cli\Loaders; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Loaders\LoaderInterface; |
24
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Generic loader implementation for container parameters. |
28
|
|
|
* |
29
|
|
|
* @author Tim Wagner <[email protected]> |
30
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
32
|
|
|
* @link https://github.com/techdivision/import-cli |
33
|
|
|
* @link http://www.techdivision.com |
34
|
|
|
*/ |
35
|
|
|
class ContainerParameterLoader implements LoaderInterface |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The container instance. |
40
|
|
|
* |
41
|
|
|
* @var \Symfony\Component\DependencyInjection\ContainerInterface |
42
|
|
|
*/ |
43
|
|
|
protected $container; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The parameter name to load the value with. |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $parameterName; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Initializes the loader with the container and the parameter name to load the value for. |
54
|
|
|
* |
55
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container The container instance |
56
|
|
|
* @param string $parameterName The container parameter name to return the value for |
57
|
|
|
*/ |
58
|
|
|
public function __construct(ContainerInterface $container, string $parameterName) |
59
|
|
|
{ |
60
|
|
|
$this->container = $container; |
61
|
|
|
$this->parameterName = $parameterName; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Return's the container instance. |
66
|
|
|
* |
67
|
|
|
* @return \Symfony\Component\DependencyInjection\ContainerInterface The container instance |
68
|
|
|
*/ |
69
|
|
|
protected function getContainer() : ContainerInterface |
70
|
|
|
{ |
71
|
|
|
return $this->container; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Return's the parameter name to load the value for. |
76
|
|
|
* |
77
|
|
|
* @return string The parameter name |
78
|
|
|
*/ |
79
|
|
|
protected function getParameterName() : string |
80
|
|
|
{ |
81
|
|
|
return $this->parameterName; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Loads and returns the parameter value from the container configuration. |
86
|
|
|
* |
87
|
|
|
* @return mixed The parameter value from the container configuration |
88
|
|
|
* @see \Symfony\Component\DependencyInjection\ContainerInterface::getParameter() |
89
|
|
|
*/ |
90
|
|
|
public function load() |
91
|
|
|
{ |
92
|
|
|
return $this->getContainer()->getParameter($this->getParameterName()); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|