Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Doctrine\DBAL;
4
 
5
use Doctrine\Common\Cache\Cache;
6
use Doctrine\Common\Cache\Psr6\CacheAdapter;
7
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
8
use Doctrine\DBAL\Driver\Middleware;
9
use Doctrine\DBAL\Logging\SQLLogger;
10
use Doctrine\Deprecations\Deprecation;
11
use Psr\Cache\CacheItemPoolInterface;
12
 
13
use function func_num_args;
14
 
15
/**
16
 * Configuration container for the Doctrine DBAL.
17
 */
18
class Configuration
19
{
20
    /** @var Middleware[] */
21
    private array $middlewares = [];
22
 
23
    /**
24
     * The SQL logger in use. If null, SQL logging is disabled.
25
     *
26
     * @var SQLLogger|null
27
     */
28
    protected $sqlLogger;
29
 
30
    /**
31
     * The cache driver implementation that is used for query result caching.
32
     */
33
    private ?CacheItemPoolInterface $resultCache = null;
34
 
35
    /**
36
     * The cache driver implementation that is used for query result caching.
37
     *
38
     * @deprecated Use {@see $resultCache} instead.
39
     *
40
     * @var Cache|null
41
     */
42
    protected $resultCacheImpl;
43
 
44
    /**
45
     * The callable to use to filter schema assets.
46
     *
47
     * @var callable|null
48
     */
49
    protected $schemaAssetsFilter;
50
 
51
    /**
52
     * The default auto-commit mode for connections.
53
     *
54
     * @var bool
55
     */
56
    protected $autoCommit = true;
57
 
58
    public function __construct()
59
    {
60
        $this->schemaAssetsFilter = static function (): bool {
61
            return true;
62
        };
63
    }
64
 
65
    /**
66
     * Sets the SQL logger to use. Defaults to NULL which means SQL logging is disabled.
67
     *
68
     * @deprecated Use {@see setMiddlewares()} and {@see \Doctrine\DBAL\Logging\Middleware} instead.
69
     */
70
    public function setSQLLogger(?SQLLogger $logger = null): void
71
    {
72
        Deprecation::trigger(
73
            'doctrine/dbal',
74
            'https://github.com/doctrine/dbal/pull/4967',
75
            '%s is deprecated, use setMiddlewares() and Logging\\Middleware instead.',
76
            __METHOD__,
77
        );
78
 
79
        $this->sqlLogger = $logger;
80
    }
81
 
82
    /**
83
     * Gets the SQL logger that is used.
84
     *
85
     * @deprecated
86
     */
87
    public function getSQLLogger(): ?SQLLogger
88
    {
89
        Deprecation::triggerIfCalledFromOutside(
90
            'doctrine/dbal',
91
            'https://github.com/doctrine/dbal/pull/4967',
92
            '%s is deprecated.',
93
            __METHOD__,
94
        );
95
 
96
        return $this->sqlLogger;
97
    }
98
 
99
    /**
100
     * Gets the cache driver implementation that is used for query result caching.
101
     */
102
    public function getResultCache(): ?CacheItemPoolInterface
103
    {
104
        return $this->resultCache;
105
    }
106
 
107
    /**
108
     * Gets the cache driver implementation that is used for query result caching.
109
     *
110
     * @deprecated Use {@see getResultCache()} instead.
111
     */
112
    public function getResultCacheImpl(): ?Cache
113
    {
114
        Deprecation::trigger(
115
            'doctrine/dbal',
116
            'https://github.com/doctrine/dbal/pull/4620',
117
            '%s is deprecated, call getResultCache() instead.',
118
            __METHOD__,
119
        );
120
 
121
        return $this->resultCacheImpl;
122
    }
123
 
124
    /**
125
     * Sets the cache driver implementation that is used for query result caching.
126
     */
127
    public function setResultCache(CacheItemPoolInterface $cache): void
128
    {
129
        $this->resultCacheImpl = DoctrineProvider::wrap($cache);
130
        $this->resultCache     = $cache;
131
    }
132
 
133
    /**
134
     * Sets the cache driver implementation that is used for query result caching.
135
     *
136
     * @deprecated Use {@see setResultCache()} instead.
137
     */
138
    public function setResultCacheImpl(Cache $cacheImpl): void
139
    {
140
        Deprecation::trigger(
141
            'doctrine/dbal',
142
            'https://github.com/doctrine/dbal/pull/4620',
143
            '%s is deprecated, call setResultCache() instead.',
144
            __METHOD__,
145
        );
146
 
147
        $this->resultCacheImpl = $cacheImpl;
148
        $this->resultCache     = CacheAdapter::wrap($cacheImpl);
149
    }
150
 
151
    /**
152
     * Sets the callable to use to filter schema assets.
153
     */
154
    public function setSchemaAssetsFilter(?callable $callable = null): void
155
    {
156
        if (func_num_args() < 1) {
157
            Deprecation::trigger(
158
                'doctrine/dbal',
159
                'https://github.com/doctrine/dbal/pull/5483',
160
                'Not passing an argument to %s is deprecated.',
161
                __METHOD__,
162
            );
163
        } elseif ($callable === null) {
164
            Deprecation::trigger(
165
                'doctrine/dbal',
166
                'https://github.com/doctrine/dbal/pull/5483',
167
                'Using NULL as a schema asset filter is deprecated.'
168
                    . ' Use a callable that always returns true instead.',
169
            );
170
        }
171
 
172
        $this->schemaAssetsFilter = $callable;
173
    }
174
 
175
    /**
176
     * Returns the callable to use to filter schema assets.
177
     */
178
    public function getSchemaAssetsFilter(): ?callable
179
    {
180
        return $this->schemaAssetsFilter;
181
    }
182
 
183
    /**
184
     * Sets the default auto-commit mode for connections.
185
     *
186
     * If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual
187
     * transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either
188
     * the method commit or the method rollback. By default, new connections are in auto-commit mode.
189
     *
190
     * @see   getAutoCommit
191
     *
192
     * @param bool $autoCommit True to enable auto-commit mode; false to disable it
193
     */
194
    public function setAutoCommit(bool $autoCommit): void
195
    {
196
        $this->autoCommit = $autoCommit;
197
    }
198
 
199
    /**
200
     * Returns the default auto-commit mode for connections.
201
     *
202
     * @see    setAutoCommit
203
     *
204
     * @return bool True if auto-commit mode is enabled by default for connections, false otherwise.
205
     */
206
    public function getAutoCommit(): bool
207
    {
208
        return $this->autoCommit;
209
    }
210
 
211
    /**
212
     * @param Middleware[] $middlewares
213
     *
214
     * @return $this
215
     */
216
    public function setMiddlewares(array $middlewares): self
217
    {
218
        $this->middlewares = $middlewares;
219
 
220
        return $this;
221
    }
222
 
223
    /** @return Middleware[] */
224
    public function getMiddlewares(): array
225
    {
226
        return $this->middlewares;
227
    }
228
}