Completed
Push — master ( cc3868...bfc8bb )
by Marco
21s queued 15s
created

Configuration::setSQLLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 1
crap 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
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 9910
    public function setSQLLogger(?SQLLogger $logger) : void
31
    {
32 9910
        $this->_attributes['sqlLogger'] = $logger;
33 9910
    }
34
35
    /**
36
     * Gets the SQL logger that is used.
37
     */
38 9932
    public function getSQLLogger() : SQLLogger
39
    {
40 9932
        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 260
    public function getResultCacheImpl() : ?Cache
47
    {
48 260
        return $this->_attributes['resultCacheImpl'] ?? null;
49
    }
50
51
    /**
52
     * Sets the cache driver implementation that is used for query result caching.
53
     */
54 312
    public function setResultCacheImpl(Cache $cacheImpl) : void
55
    {
56 312
        $this->_attributes['resultCacheImpl'] = $cacheImpl;
57 312
    }
58
59
    /**
60
     * Sets the callable to use to filter schema assets.
61
     */
62 380
    public function setSchemaAssetsFilter(?callable $callable = null) : ?callable
63
    {
64 380
        $this->_attributes['filterSchemaAssetsExpression'] = null;
65
66 380
        return $this->_attributes['filterSchemaAssetsExpressionCallable'] = $callable;
67
    }
68
69
    /**
70
     * Returns the callable to use to filter schema assets.
71
     */
72 425
    public function getSchemaAssetsFilter() : ?callable
73
    {
74 425
        return $this->_attributes['filterSchemaAssetsExpressionCallable'] ?? null;
75
    }
76
77
    /**
78
     * Sets the default auto-commit mode for connections.
79
     *
80
     * If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual
81
     * transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either
82
     * the method commit or the method rollback. By default, new connections are in auto-commit mode.
83
     *
84
     * @see getAutoCommit
85
     *
86
     * @param bool $autoCommit True to enable auto-commit mode; false to disable it.
87
     */
88 26
    public function setAutoCommit(bool $autoCommit) : void
89
    {
90 26
        $this->_attributes['autoCommit'] = $autoCommit;
91 26
    }
92
93
    /**
94
     * Returns the default auto-commit mode for connections.
95
     *
96
     * @see    setAutoCommit
97
     *
98
     * @return bool True if auto-commit mode is enabled by default for connections, false otherwise.
99
     */
100 3003
    public function getAutoCommit() : bool
101
    {
102 3003
        return $this->_attributes['autoCommit'] ?? true;
103
    }
104
}
105