|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2018 Gerrit Addiks. |
|
4
|
|
|
* This package (including this file) was released under the terms of the GPL-3.0. |
|
5
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
|
6
|
|
|
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
|
7
|
|
|
* |
|
8
|
|
|
* @license GPL-3.0 |
|
9
|
|
|
* |
|
10
|
|
|
* @author Gerrit Addiks <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Addiks\SymfonyGenerics\Arguments\ArgumentFactory; |
|
14
|
|
|
|
|
15
|
|
|
use Addiks\SymfonyGenerics\Arguments\ArgumentFactory\ArgumentFactory; |
|
16
|
|
|
use Psr\Container\ContainerInterface; |
|
17
|
|
|
use Webmozart\Assert\Assert; |
|
18
|
|
|
use Addiks\SymfonyGenerics\Arguments\Argument; |
|
19
|
|
|
|
|
20
|
|
|
final class ArgumentFactoryLazyLoadProxy implements ArgumentFactory |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var ContainerInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
private $container; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
private $serviceId; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var ArgumentFactory|null |
|
35
|
|
|
*/ |
|
36
|
|
|
private $loadedArgumentFactory; |
|
37
|
|
|
|
|
38
|
|
|
public function __construct( |
|
39
|
|
|
ContainerInterface $container, |
|
40
|
|
|
string $serviceId |
|
41
|
|
|
) { |
|
42
|
|
|
$this->container = $container; |
|
43
|
|
|
$this->serviceId = $serviceId; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function understandsString(string $source): bool |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->loadInnerArgumentFactory()->understandsString($source); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function understandsArray(array $source): bool |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->loadInnerArgumentFactory()->understandsArray($source); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function createArgumentFromString(string $source): Argument |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->loadInnerArgumentFactory()->createArgumentFromString($source); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function createArgumentFromArray(array $source): Argument |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->loadInnerArgumentFactory()->createArgumentFromArray($source); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
private function loadInnerArgumentFactory(): ArgumentFactory |
|
67
|
|
|
{ |
|
68
|
|
|
if (is_null($this->loadedArgumentFactory)) { |
|
69
|
|
|
$this->loadedArgumentFactory = $this->container->get($this->serviceId); |
|
70
|
|
|
|
|
71
|
|
|
Assert::isInstanceOf($this->loadedArgumentFactory, ArgumentFactory::class, sprintf( |
|
72
|
|
|
"Expected service '%s' to be instance of '%s'!", |
|
73
|
|
|
$this->serviceId, |
|
74
|
|
|
ArgumentFactory::class |
|
75
|
|
|
)); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $this->loadedArgumentFactory; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|