1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Phuria SQL Builder package. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2016 Beniamin Jonatan Šimko |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Phuria\SQLBuilder\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Phuria\SQLBuilder\Parameter\ParameterManager; |
15
|
|
|
use Phuria\SQLBuilder\QueryCompiler\QueryCompiler; |
16
|
|
|
use Phuria\SQLBuilder\ReferenceManager; |
17
|
|
|
use Phuria\SQLBuilder\TableFactory\TableFactory; |
18
|
|
|
use Phuria\SQLBuilder\TableRegistry; |
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
20
|
|
|
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Beniamin Jonatan Šimko <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class InternalContainer implements ContainerInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
private $services = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
private $parameters = []; |
36
|
|
|
|
37
|
37 |
|
public function __construct() |
38
|
|
|
{ |
39
|
37 |
|
$this->parameters['phuria.sql_builder.parameter_manager.class'] = ParameterManager::class; |
40
|
37 |
|
$this->parameters['phuria.sql_builder.reference_manager.class'] = ReferenceManager::class; |
41
|
|
|
|
42
|
37 |
|
$this->services['phuria.sql_builder.table_registry'] = new TableRegistry(); |
43
|
37 |
|
$this->services['phuria.sql_builder.table_factory'] = new TableFactory(); |
44
|
37 |
|
$this->services['phuria.sql_builder.query_compiler'] = new QueryCompiler(); |
45
|
37 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @inheritdoc |
49
|
|
|
*/ |
50
|
|
|
public function set($id, $service) |
51
|
|
|
{ |
52
|
|
|
$this->services[$id] = $service; |
53
|
|
|
|
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @inheritdoc |
59
|
|
|
*/ |
60
|
37 |
|
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) |
61
|
|
|
{ |
62
|
37 |
|
if ($this->has($id)) { |
63
|
37 |
|
return $this->services[$id]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) { |
67
|
|
|
throw new ServiceNotFoundException($id); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return null; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @inheritdoc |
75
|
|
|
*/ |
76
|
37 |
|
public function has($id) |
77
|
|
|
{ |
78
|
37 |
|
return array_key_exists($id, $this->services); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @inheritdoc |
83
|
|
|
*/ |
84
|
|
|
public function initialized($id) |
85
|
|
|
{ |
86
|
|
|
return true; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @inheritdoc |
91
|
|
|
*/ |
92
|
37 |
|
public function getParameter($name) |
93
|
|
|
{ |
94
|
37 |
|
return $this->parameters[$name]; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @inheritdoc |
99
|
|
|
*/ |
100
|
|
|
public function hasParameter($name) |
101
|
|
|
{ |
102
|
|
|
return array_key_exists($name, $this->parameters); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @inheritdoc |
107
|
|
|
*/ |
108
|
|
|
public function setParameter($name, $value) |
109
|
|
|
{ |
110
|
|
|
$this->parameters[$name] = $value; |
111
|
|
|
|
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
} |