1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\DBAL; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Cache\Cache; |
8
|
|
|
use Doctrine\DBAL\Logging\NullLogger; |
9
|
|
|
use Doctrine\DBAL\Logging\SQLLogger; |
10
|
|
|
use Doctrine\DBAL\Schema\AbstractAsset; |
11
|
|
|
use function preg_match; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Configuration container for the Doctrine DBAL. |
15
|
|
|
* |
16
|
|
|
* @internal When adding a new configuration option just write a getter/setter |
17
|
|
|
* pair and add the option to the _attributes array with a proper default value. |
18
|
|
|
*/ |
19
|
|
|
class Configuration |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* The attributes that are contained in the configuration. |
23
|
|
|
* Values are default values. |
24
|
|
|
* |
25
|
|
|
* @var mixed[] |
26
|
|
|
*/ |
27
|
|
|
protected $_attributes = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Sets the SQL logger to use. |
31
|
|
|
*/ |
32
|
9073 |
|
public function setSQLLogger(?SQLLogger $logger) : void |
33
|
|
|
{ |
34
|
9073 |
|
$this->_attributes['sqlLogger'] = $logger; |
35
|
9073 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Gets the SQL logger that is used. |
39
|
|
|
*/ |
40
|
9193 |
|
public function getSQLLogger() : SQLLogger |
41
|
|
|
{ |
42
|
9193 |
|
return $this->_attributes['sqlLogger'] ?? $this->_attributes['sqlLogger'] = new NullLogger(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Gets the cache driver implementation that is used for query result caching. |
47
|
|
|
* |
48
|
|
|
* @return Cache|null |
49
|
|
|
*/ |
50
|
3704 |
|
public function getResultCacheImpl() |
51
|
|
|
{ |
52
|
3704 |
|
return $this->_attributes['resultCacheImpl'] ?? null; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Sets the cache driver implementation that is used for query result caching. |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
3704 |
|
public function setResultCacheImpl(Cache $cacheImpl) |
61
|
|
|
{ |
62
|
3704 |
|
$this->_attributes['resultCacheImpl'] = $cacheImpl; |
63
|
3704 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Sets the filter schema assets expression. |
67
|
|
|
* |
68
|
|
|
* Only include tables/sequences matching the filter expression regexp in |
69
|
|
|
* schema instances generated for the active connection when calling |
70
|
|
|
* {AbstractSchemaManager#createSchema()}. |
71
|
|
|
* |
72
|
|
|
* @deprecated Use Configuration::setSchemaAssetsFilter() instead |
73
|
|
|
* |
74
|
|
|
* @param string $filterExpression |
75
|
|
|
* |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
|
|
public function setFilterSchemaAssetsExpression($filterExpression) |
79
|
|
|
{ |
80
|
|
|
$this->_attributes['filterSchemaAssetsExpression'] = $filterExpression; |
81
|
|
|
if ($filterExpression) { |
82
|
|
|
$this->_attributes['filterSchemaAssetsExpressionCallable'] = $this->buildSchemaAssetsFilterFromExpression($filterExpression); |
83
|
|
|
} else { |
84
|
|
|
$this->_attributes['filterSchemaAssetsExpressionCallable'] = null; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param string $filterExpression |
90
|
|
|
*/ |
91
|
|
|
private function buildSchemaAssetsFilterFromExpression($filterExpression) : callable |
92
|
|
|
{ |
93
|
|
|
return static function ($assetName) use ($filterExpression) { |
94
|
|
|
if ($assetName instanceof AbstractAsset) { |
95
|
|
|
$assetName = $assetName->getName(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return preg_match($filterExpression, $assetName); |
99
|
|
|
}; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Sets the callable to use to filter schema assets. |
104
|
|
|
*/ |
105
|
1254 |
|
public function setSchemaAssetsFilter(?callable $callable = null) : ?callable |
106
|
|
|
{ |
107
|
1254 |
|
$this->_attributes['filterSchemaAssetsExpression'] = null; |
108
|
|
|
|
109
|
1254 |
|
return $this->_attributes['filterSchemaAssetsExpressionCallable'] = $callable; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Returns the callable to use to filter schema assets. |
114
|
|
|
*/ |
115
|
4245 |
|
public function getSchemaAssetsFilter() : ?callable |
116
|
|
|
{ |
117
|
4245 |
|
return $this->_attributes['filterSchemaAssetsExpressionCallable'] ?? null; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Sets the default auto-commit mode for connections. |
122
|
|
|
* |
123
|
|
|
* If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual |
124
|
|
|
* transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either |
125
|
|
|
* the method commit or the method rollback. By default, new connections are in auto-commit mode. |
126
|
|
|
* |
127
|
|
|
* @see getAutoCommit |
128
|
|
|
* |
129
|
|
|
* @param bool $autoCommit True to enable auto-commit mode; false to disable it. |
130
|
|
|
*/ |
131
|
9505 |
|
public function setAutoCommit($autoCommit) |
132
|
|
|
{ |
133
|
9505 |
|
$this->_attributes['autoCommit'] = (bool) $autoCommit; |
134
|
9505 |
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Returns the default auto-commit mode for connections. |
138
|
|
|
* |
139
|
|
|
* @see setAutoCommit |
140
|
|
|
* |
141
|
|
|
* @return bool True if auto-commit mode is enabled by default for connections, false otherwise. |
142
|
|
|
*/ |
143
|
9529 |
|
public function getAutoCommit() |
144
|
|
|
{ |
145
|
9529 |
|
return $this->_attributes['autoCommit'] ?? true; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|