Completed
Push — master ( 1a9812...b70610 )
by Sergei
19s queued 14s
created

Configuration   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Test Coverage

Coverage 64.52%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 12
eloc 19
c 2
b 0
f 0
dl 0
loc 116
rs 10
ccs 20
cts 31
cp 0.6452

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getSQLLogger() 0 3 1
A getResultCacheImpl() 0 3 1
A setResultCacheImpl() 0 3 1
A buildSchemaAssetsFilterFromExpression() 0 8 2
A getSchemaAssetsFilter() 0 3 1
A setAutoCommit() 0 3 1
A setSchemaAssetsFilter() 0 5 1
A getAutoCommit() 0 3 1
A setFilterSchemaAssetsExpression() 0 7 2
A setSQLLogger() 0 3 1
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 10312
    public function setSQLLogger(?SQLLogger $logger) : void
33
    {
34 10312
        $this->_attributes['sqlLogger'] = $logger;
35 10312
    }
36
37
    /**
38
     * Gets the SQL logger that is used.
39
     */
40 10302
    public function getSQLLogger() : SQLLogger
41
    {
42 10302
        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 270
    public function getResultCacheImpl() : ?Cache
49
    {
50 270
        return $this->_attributes['resultCacheImpl'] ?? null;
51
    }
52
53
    /**
54
     * Sets the cache driver implementation that is used for query result caching.
55
     */
56 324
    public function setResultCacheImpl(Cache $cacheImpl) : void
57
    {
58 324
        $this->_attributes['resultCacheImpl'] = $cacheImpl;
59 324
    }
60
61
    /**
62
     * Sets the filter schema assets expression.
63
     *
64
     * Only include tables/sequences matching the filter expression regexp in
65
     * schema instances generated for the active connection when calling
66
     * {AbstractSchemaManager#createSchema()}.
67
     *
68
     * @deprecated Use Configuration::setSchemaAssetsFilter() instead
69
     */
70
    public function setFilterSchemaAssetsExpression(?string $filterExpression) : void
71
    {
72
        $this->_attributes['filterSchemaAssetsExpression'] = $filterExpression;
73
        if ($filterExpression) {
74
            $this->_attributes['filterSchemaAssetsExpressionCallable'] = $this->buildSchemaAssetsFilterFromExpression($filterExpression);
75
        } else {
76
            $this->_attributes['filterSchemaAssetsExpressionCallable'] = null;
77
        }
78
    }
79
80
    private function buildSchemaAssetsFilterFromExpression(string $filterExpression) : callable
81
    {
82
        return static function ($assetName) use ($filterExpression) : bool {
83
            if ($assetName instanceof AbstractAsset) {
84
                $assetName = $assetName->getName();
85
            }
86
87
            return preg_match($filterExpression, $assetName) > 0;
88
        };
89
    }
90
91
    /**
92
     * Sets the callable to use to filter schema assets.
93
     */
94 380
    public function setSchemaAssetsFilter(?callable $callable = null) : ?callable
95
    {
96 380
        $this->_attributes['filterSchemaAssetsExpression'] = null;
97
98 380
        return $this->_attributes['filterSchemaAssetsExpressionCallable'] = $callable;
99
    }
100
101
    /**
102
     * Returns the callable to use to filter schema assets.
103
     */
104 439
    public function getSchemaAssetsFilter() : ?callable
105
    {
106 439
        return $this->_attributes['filterSchemaAssetsExpressionCallable'] ?? null;
107
    }
108
109
    /**
110
     * Sets the default auto-commit mode for connections.
111
     *
112
     * If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual
113
     * transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either
114
     * the method commit or the method rollback. By default, new connections are in auto-commit mode.
115
     *
116
     * @see getAutoCommit
117
     *
118
     * @param bool $autoCommit True to enable auto-commit mode; false to disable it.
119
     */
120 27
    public function setAutoCommit(bool $autoCommit) : void
121
    {
122 27
        $this->_attributes['autoCommit'] = $autoCommit;
123 27
    }
124
125
    /**
126
     * Returns the default auto-commit mode for connections.
127
     *
128
     * @see    setAutoCommit
129
     *
130
     * @return bool True if auto-commit mode is enabled by default for connections, false otherwise.
131
     */
132 3137
    public function getAutoCommit() : bool
133
    {
134 3137
        return $this->_attributes['autoCommit'] ?? true;
135
    }
136
}
137