1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helpers; |
4
|
|
|
|
5
|
|
|
use Helpers\Repository\DomainRepository; |
6
|
|
|
use Hexarchium\CoreDomain\Factory\UseCase\CreateDomainUseCaseFactory; |
7
|
|
|
use Hexarchium\CoreDomain\Factory\UseCase\CreateModelUseCaseFactory; |
8
|
|
|
use Hexarchium\CoreDomain\Factory\UseCase\CreateUseCaseUseCaseFactory; |
9
|
|
|
use Hexarchium\CoreDomain\Model\Domain\Repository\DomainRepositoryInterface; |
10
|
|
|
use Interop\Container\ContainerInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Copyright |
14
|
|
|
*/ |
15
|
|
|
class Container extends \ArrayObject implements ContainerInterface |
16
|
|
|
{ |
17
|
|
|
static public function factory() |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
$container = new Container(); |
20
|
|
|
$container->initializeRepository(); |
21
|
|
|
$container->initializeFactory(); |
22
|
|
|
$container->initializeUseCase(); |
23
|
|
|
|
24
|
|
|
return $container; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function initializeRepository() |
28
|
|
|
{ |
29
|
|
|
$this->set( |
30
|
|
|
DomainRepositoryInterface::class, |
31
|
|
|
new DomainRepository() |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $name |
37
|
|
|
* @param mixed $value |
38
|
|
|
*/ |
39
|
|
|
protected function set($name, $value) |
40
|
|
|
{ |
41
|
|
|
$this->offsetSet($name, $value); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function initializeFactory() |
45
|
|
|
{ |
46
|
|
|
$this->set( |
47
|
|
|
CreateDomainUseCaseFactory::class, |
48
|
|
|
new CreateDomainUseCaseFactory() |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$this->set( |
52
|
|
|
CreateModelUseCaseFactory::class, |
53
|
|
|
new CreateModelUseCaseFactory() |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
$this->set( |
57
|
|
|
CreateUseCaseUseCaseFactory::class, |
58
|
|
|
new CreateUseCaseUseCaseFactory() |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function initializeUseCase() |
63
|
|
|
{ |
64
|
|
|
$this->set( |
65
|
|
|
\Hexarchium\CoreDomain\UseCase\CreateDomain\UseCase::class, |
66
|
|
|
$this->get(CreateDomainUseCaseFactory::class)->factory( |
67
|
|
|
$this->get(DomainRepositoryInterface::class) |
68
|
|
|
) |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$this->set( |
72
|
|
|
\Hexarchium\CoreDomain\UseCase\CreateModel\UseCase::class, |
73
|
|
|
$this->get(CreateModelUseCaseFactory::class)->factory( |
74
|
|
|
$this->get(DomainRepositoryInterface::class) |
75
|
|
|
) |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
$this->set( |
79
|
|
|
\Hexarchium\CoreDomain\UseCase\CreateUseCase\UseCase::class, |
80
|
|
|
$this->get(CreateUseCaseUseCaseFactory::class)->factory( |
81
|
|
|
$this->get(DomainRepositoryInterface::class) |
82
|
|
|
) |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function get($id) |
87
|
|
|
{ |
88
|
|
|
if (!$this->has($id)) { |
89
|
|
|
throw new \Exception(sprintf("Given service '%s' don't exist", $id)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $this->offsetGet($id); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function has($id) |
96
|
|
|
{ |
97
|
|
|
return $this->offsetExists($id); |
98
|
|
|
} |
99
|
|
|
} |