Subversion-Projekte lars-tiefland.laravel_shop

Revision

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