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