Completed
Push — develop ( 72ba3e...de019a )
by Marco
25s queued 12s
created

Configuration   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Test Coverage

Coverage 96.97%

Importance

Changes 0
Metric Value
wmc 13
eloc 20
dl 0
loc 137
ccs 32
cts 33
cp 0.9697
rs 10
c 0
b 0
f 0

11 Methods

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