Configuration.php 3.29 KB
Newer Older
1
<?php
2

3 4
namespace Doctrine\DBAL;

5
use Doctrine\Common\Cache\Cache;
6
use Doctrine\DBAL\Driver\Middleware;
7
use Doctrine\DBAL\Logging\SQLLogger;
8 9

/**
10
 * Configuration container for the Doctrine DBAL.
11
 *
12
 * @internal
13
 */
14
class Configuration
15
{
16 17 18
    /** @var Middleware[] */
    private $middlewares = [];

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 29
    /**
     * Sets the SQL logger to use. Defaults to NULL which means SQL logging is disabled.
     *
Benjamin Morel's avatar
Benjamin Morel committed
30
     * @return void
31
     */
32
    public function setSQLLogger(?SQLLogger $logger = null)
33 34 35
    {
        $this->_attributes['sqlLogger'] = $logger;
    }
36

37 38
    /**
     * Gets the SQL logger that is used.
39
     *
40
     * @return SQLLogger|null
41
     */
42
    public function getSQLLogger()
43
    {
44
        return $this->_attributes['sqlLogger'] ?? null;
45
    }
46 47 48 49

    /**
     * Gets the cache driver implementation that is used for query result caching.
     *
50
     * @return Cache|null
51 52 53
     */
    public function getResultCacheImpl()
    {
54
        return $this->_attributes['resultCacheImpl'] ?? null;
55 56 57 58 59
    }

    /**
     * Sets the cache driver implementation that is used for query result caching.
     *
Benjamin Morel's avatar
Benjamin Morel committed
60
     * @return void
61 62 63 64 65
     */
    public function setResultCacheImpl(Cache $cacheImpl)
    {
        $this->_attributes['resultCacheImpl'] = $cacheImpl;
    }
66

67 68 69
    /**
     * Sets the callable to use to filter schema assets.
     */
70
    public function setSchemaAssetsFilter(?callable $callable = null): ?callable
71
    {
72 73
        $this->_attributes['filterSchemaAssetsExpression'] = null;

74 75 76 77 78 79
        return $this->_attributes['filterSchemaAssetsExpressionCallable'] = $callable;
    }

    /**
     * Returns the callable to use to filter schema assets.
     */
80
    public function getSchemaAssetsFilter(): ?callable
81 82 83 84
    {
        return $this->_attributes['filterSchemaAssetsExpressionCallable'] ?? null;
    }

85 86 87 88 89 90 91 92
    /**
     * Sets the default auto-commit mode for connections.
     *
     * If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual
     * transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either
     * the method commit or the method rollback. By default, new connections are in auto-commit mode.
     *
     * @see   getAutoCommit
93 94
     *
     * @param bool $autoCommit True to enable auto-commit mode; false to disable it.
95 96
     *
     * @return void
97 98 99
     */
    public function setAutoCommit($autoCommit)
    {
100
        $this->_attributes['autoCommit'] = (bool) $autoCommit;
101 102 103 104 105 106
    }

    /**
     * Returns the default auto-commit mode for connections.
     *
     * @see    setAutoCommit
107 108
     *
     * @return bool True if auto-commit mode is enabled by default for connections, false otherwise.
109 110 111
     */
    public function getAutoCommit()
    {
112
        return $this->_attributes['autoCommit'] ?? true;
113
    }
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

    /**
     * @param Middleware[] $middlewares
     *
     * @return $this
     */
    public function setMiddlewares(array $middlewares): self
    {
        $this->middlewares = $middlewares;

        return $this;
    }

    /**
     * @return Middleware[]
     */
    public function getMiddlewares(): array
    {
        return $this->middlewares;
    }
134
}