1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bdf\Prime; |
4
|
|
|
|
5
|
|
|
use Bdf\Prime\Connection\ConnectionConfig; |
6
|
|
|
use Bdf\Prime\Types\TypesRegistry; |
7
|
|
|
use Bdf\Prime\Types\TypesRegistryInterface; |
8
|
|
|
use Doctrine\DBAL\Configuration as BaseConfiguration; |
9
|
|
|
use Psr\SimpleCache\CacheInterface; |
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Configuration |
13
|
|
|
*/ |
14
|
|
|
class Configuration extends BaseConfiguration |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Set configuration |
18
|
|
|
* |
19
|
|
|
* @param array $options |
20
|
|
|
*/ |
21
|
188 |
|
public function __construct(array $options = []) |
|
|
|
|
22
|
|
|
{ |
23
|
188 |
|
$this->_attributes = $options + [ |
|
|
|
|
24
|
188 |
|
'sqlLogger' => isset($options['logger']) ? $options['logger'] : null, |
|
|
|
|
25
|
|
|
'resultCache' => null, |
26
|
|
|
'metadataCache' => null, |
27
|
|
|
'dbConfig' => null, |
28
|
|
|
]; |
29
|
|
|
|
30
|
188 |
|
unset($this->_attributes['logger']); |
31
|
188 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Cache de resultat des requetes |
35
|
|
|
* |
36
|
|
|
* @param \Bdf\Prime\Cache\CacheInterface $cache |
37
|
|
|
*/ |
38
|
1 |
|
public function setResultCache($cache) |
|
|
|
|
39
|
|
|
{ |
40
|
1 |
|
$this->_attributes['resultCache'] = $cache; |
41
|
1 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return \Bdf\Prime\Cache\CacheInterface |
45
|
|
|
*/ |
46
|
110 |
|
public function getResultCache() |
47
|
|
|
{ |
48
|
110 |
|
return $this->_attributes['resultCache']; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Cache de metadata |
53
|
|
|
* |
54
|
|
|
* @param CacheInterface $cache |
55
|
|
|
*/ |
56
|
1 |
|
public function setMetadataCache($cache) |
|
|
|
|
57
|
|
|
{ |
58
|
1 |
|
$this->_attributes['metadataCache'] = $cache; |
59
|
1 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return CacheInterface |
63
|
|
|
*/ |
64
|
109 |
|
public function getMetadataCache() |
65
|
|
|
{ |
66
|
109 |
|
return $this->_attributes['metadataCache']; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Set db config. |
71
|
|
|
* |
72
|
|
|
* Contains profil info to connect database |
|
|
|
|
73
|
|
|
* |
74
|
|
|
* @param callable|ConnectionConfig|array $config Config object or config file |
75
|
|
|
* |
76
|
|
|
* @deprecated Since 1.1. Use ConnectionRegistry to declare your connections. |
|
|
|
|
77
|
|
|
*/ |
78
|
2 |
|
public function setDbConfig($config) |
79
|
|
|
{ |
80
|
2 |
|
@trigger_error(__METHOD__.' is deprecated since 1.1 and will be removed in 1.2. Use ConnectionRegistry to declare your connections.', E_USER_DEPRECATED); |
|
|
|
|
81
|
|
|
|
82
|
2 |
|
$this->_attributes['dbConfig'] = $config; |
83
|
2 |
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get the db config object |
87
|
|
|
* |
88
|
|
|
* @return ConnectionConfig |
89
|
|
|
* |
90
|
|
|
* @deprecated Since 1.1. Use ConnectionRegistry to declare your connections. |
|
|
|
|
91
|
|
|
*/ |
92
|
7 |
|
public function getDbConfig() |
93
|
|
|
{ |
94
|
7 |
|
@trigger_error(__METHOD__.' is deprecated since 1.1 and will be removed in 1.2. Use ConnectionRegistry to declare your connections.', E_USER_DEPRECATED); |
|
|
|
|
95
|
|
|
|
96
|
7 |
|
if ($this->_attributes['dbConfig'] instanceof ConnectionConfig) { |
97
|
3 |
|
return $this->_attributes['dbConfig']; |
98
|
|
|
} |
99
|
|
|
|
100
|
6 |
|
if (is_callable($this->_attributes['dbConfig'])) { |
101
|
|
|
$this->_attributes['dbConfig'] = $this->_attributes['dbConfig']($this); |
102
|
|
|
} |
103
|
|
|
|
104
|
6 |
|
if (! $this->_attributes['dbConfig'] instanceof ConnectionConfig) { |
|
|
|
|
105
|
6 |
|
$this->_attributes['dbConfig'] = new ConnectionConfig((array) $this->_attributes['dbConfig']); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
6 |
|
return $this->_attributes['dbConfig']; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Set common type registry |
113
|
|
|
* |
114
|
|
|
* @param TypesRegistryInterface $types |
115
|
|
|
*/ |
116
|
128 |
|
public function setTypes(TypesRegistryInterface $types) |
117
|
|
|
{ |
118
|
128 |
|
$this->_attributes['types'] = $types; |
119
|
128 |
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Get common types registry |
123
|
|
|
* |
124
|
|
|
* @return TypesRegistryInterface |
125
|
|
|
*/ |
126
|
180 |
|
public function getTypes() |
127
|
|
|
{ |
128
|
180 |
|
if (!isset($this->_attributes['types'])) { |
129
|
128 |
|
$this->setTypes(new TypesRegistry()); |
130
|
|
|
} |
131
|
|
|
|
132
|
180 |
|
return $this->_attributes['types']; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|