Completed
Push — master ( 707688...6da863 )
by Mike
04:47 queued 02:08
created

lib/Doctrine/ODM/CouchDB/Configuration.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\ODM\CouchDB;
21
22
use Doctrine\Common\Cache\Cache;
23
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
24
25
use Doctrine\CouchDB\HTTP\Client;
26
use Doctrine\CouchDB\HTTP\SocketClient;
27
use Doctrine\CouchDB\HTTP\LoggingClient;
28
29
use Doctrine\ODM\CouchDB\Mapping\MetadataResolver\MetadataResolver;
30
use Doctrine\ODM\CouchDB\Mapping\MetadataResolver\DoctrineResolver;
31
use Doctrine\ODM\CouchDB\Migrations\DocumentMigration;
32
33
/**
34
 * Configuration class
35
 *
36
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
37
 * @link        www.doctrine-project.com
38
 * @since       1.0
39
 * @author      Benjamin Eberlei <[email protected]>
40
 * @author      Lukas Kahwe Smith <[email protected]>
41
 */
42
class Configuration
43
{
44
    /**
45
     * Array of attributes for this configuration instance.
46
     *
47
     * @var array $attributes
48
     */
49
    private $attributes = array(
50
        'designDocuments' => array(
51
            'doctrine_associations' => array(
52
                'className' => 'Doctrine\ODM\CouchDB\View\DoctrineAssociations',
53
                'options' => array(),
54
            ),
55
            'doctrine_repositories' => array(
56
                'className' => 'Doctrine\ODM\CouchDB\View\DoctrineRepository',
57
                'options' => array(),
58
            ),
59
        ),
60
        'writeDoctrineMetadata' => true,
61
        'validateDoctrineMetadata' => true,
62
        'UUIDGenerationBufferSize' => 20,
63
        'proxyNamespace' => 'MyCouchDBProxyNS',
64
        'allOrNothingFlush' => true,
65
        'luceneHandlerName' => false,
66
        'metadataResolver' => null,
67
        'autoGenerateProxyClasses' => false,
68
    );
69
70
    /**
71
     * Sets the default UUID Generator buffer size
72
     *
73
     * @param integer $UUIDGenerationBufferSize
74
     */
75
    public function setUUIDGenerationBufferSize($UUIDGenerationBufferSize)
76
    {
77
        $this->attributes['UUIDGenerationBufferSize'] = $UUIDGenerationBufferSize;
78
    }
79
80
    /**
81
     * Gets the default UUID Generator buffer size
82
     *
83
     * @return integer
84
     */
85
    public function getUUIDGenerationBufferSize()
86
    {
87
        return $this->attributes['UUIDGenerationBufferSize'];
88
    }
89
    /**
90
     * Sets if all CouchDB document metadata should be validated on read
91
     *
92
     * @param boolean $validateDoctrineMetadata
93
     */
94
    public function setValidateDoctrineMetadata($validateDoctrineMetadata)
95
    {
96
        $this->attributes['validateDoctrineMetadata'] = $validateDoctrineMetadata;
97
    }
98
99
    /**
100
     * Gets if all CouchDB document metadata should be validated on read
101
     *
102
     * @return boolean
103
     */
104
    public function getValidateDoctrineMetadata()
105
    {
106
        return $this->attributes['validateDoctrineMetadata'];
107
    }
108
109
    /**
110
     * Adds a namespace under a certain alias.
111
     *
112
     * @param string $alias
113
     * @param string $namespace
114
     */
115
    public function addDocumentNamespace($alias, $namespace)
116
    {
117
        $this->attributes['documentNamespaces'][$alias] = $namespace;
118
    }
119
120
    /**
121
     * Resolves a registered namespace alias to the full namespace.
122
     *
123
     * @param string $documentNamespaceAlias
124
     * @return string
125
     * @throws CouchDBException
126
     */
127
    public function getDocumentNamespace($documentNamespaceAlias)
128
    {
129
        if ( ! isset($this->attributes['documentNamespaces'][$documentNamespaceAlias])) {
130
            throw CouchDBException::unknownDocumentNamespace($documentNamespaceAlias);
131
        }
132
133
        return trim($this->attributes['documentNamespaces'][$documentNamespaceAlias], '\\');
134
    }
135
136
    /**
137
     * Set the document alias map
138
     *
139
     * @param array $documentNamespaces
140
     * @return void
141
     */
142
    public function setDocumentNamespaces(array $documentNamespaces)
143
    {
144
        $this->attributes['documentNamespaces'] = $documentNamespaces;
145
    }
146
147
    /**
148
     * Sets the cache driver implementation that is used for metadata caching.
149
     *
150
     * @param MappingDriver $driverImpl
151
     * @todo Force parameter to be a Closure to ensure lazy evaluation
152
     *       (as soon as a metadata cache is in effect, the driver never needs to initialize).
153
     */
154
    public function setMetadataDriverImpl(MappingDriver $driverImpl)
155
    {
156
        $this->attributes['metadataDriverImpl'] = $driverImpl;
157
    }
158
159
    /**
160
     * Add a new default annotation driver with a correctly configured annotation reader.
161
     *
162
     * @param array $paths
163
     * @return Mapping\Driver\AnnotationDriver
164
     */
165
    public function newDefaultAnnotationDriver($paths = array())
166
    {
167
        $reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader();
168
        $reader->addNamespace('Doctrine\ODM\CouchDB\Mapping\Annotations');
169
170
        return new \Doctrine\ODM\CouchDB\Mapping\Driver\AnnotationDriver($reader, (array) $paths);
0 ignored issues
show
$reader is of type object<Doctrine\Common\A...SimpleAnnotationReader>, but the function expects a object<Doctrine\Common\A...tions\AnnotationReader>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
171
    }
172
173
    public function setMetadataResolverImpl(MetadataResolver $resolver)
174
    {
175
        $this->attributes['metadataResolver'] = $resolver;
176
    }
177
178
    public function getMetadataResolverImpl()
179
    {
180
        if (!$this->attributes['metadataResolver']) {
181
            return new DoctrineResolver();
182
        }
183
        return $this->attributes['metadataResolver'];
184
    }
185
186
    /**
187
     * Gets the cache driver implementation that is used for the mapping metadata.
188
     *
189
     * @return MappingDriver
190
     */
191
    public function getMetadataDriverImpl()
192
    {
193
        if (!isset($this->attributes['metadataDriverImpl'])) {
194
            $this->attributes['metadataDriverImpl'] = $this->newDefaultAnnotationDriver();
195
        }
196
        return $this->attributes['metadataDriverImpl'];
197
    }
198
199
    /**
200
     * Gets the cache driver implementation that is used for metadata caching.
201
     *
202
     * @return \Doctrine\Common\Cache\Cache
203
     */
204
    public function getMetadataCacheImpl()
205
    {
206
        return isset($this->attributes['metadataCacheImpl']) ?
207
                $this->attributes['metadataCacheImpl'] : null;
208
    }
209
210
    /**
211
     * Sets the cache driver implementation that is used for metadata caching.
212
     *
213
     * @param \Doctrine\Common\Cache\Cache $cacheImpl
214
     */
215
    public function setMetadataCacheImpl(Cache $cacheImpl)
216
    {
217
        $this->attributes['metadataCacheImpl'] = $cacheImpl;
218
    }
219
220
    /**
221
     * Sets the directory where Doctrine generates any necessary proxy class files.
222
     *
223
     * @param string $dir
224
     */
225
    public function setProxyDir($dir)
226
    {
227
        $this->attributes['proxyDir'] = $dir;
228
    }
229
230
    /**
231
     * Gets the directory where Doctrine generates any necessary proxy class files.
232
     *
233
     * @return string
234
     */
235
    public function getProxyDir()
236
    {
237
        if (!isset($this->attributes['proxyDir'])) {
238
            $this->attributes['proxyDir'] = \sys_get_temp_dir();
239
        }
240
241
        return $this->attributes['proxyDir'];
242
    }
243
244
    /**
245
     * Sets the namespace for Doctrine proxy class files.
246
     *
247
     * @param string $namespace
248
     */
249
    public function setProxyNamespace($namespace)
250
    {
251
        $this->attributes['proxyNamespace'] = $namespace;
252
    }
253
254
    /**
255
     * Gets the namespace for Doctrine proxy class files.
256
     *
257
     * @return string
258
     */
259
    public function getProxyNamespace()
260
    {
261
        return $this->attributes['proxyNamespace'];
262
    }
263
264
    public function setAutoGenerateProxyClasses($bool)
265
    {
266
        $this->attributes['autoGenerateProxyClasses'] = $bool;
267
    }
268
269
    public function getAutoGenerateProxyClasses()
270
    {
271
        return $this->attributes['autoGenerateProxyClasses'];
272
    }
273
274
    /**
275
     * @param string $name
276
     * @param string $className
277
     * @param array $options
278
     */
279
    public function addDesignDocument($name, $className, $options)
280
    {
281
        $this->attributes['designDocuments'][$name] = array(
282
            'className' => $className,
283
            'options' => $options,
284
        );
285
    }
286
287
    /**
288
     * @return array
289
     */
290
    public function getDesignDocumentNames()
291
    {
292
        return array_keys($this->attributes['designDocuments']);
293
    }
294
295
    /**
296
     * @param  string $name
297
     * @return array
298
     */
299
    public function getDesignDocument($name)
300
    {
301
        if (isset($this->attributes['designDocuments'][$name])) {
302
            return $this->attributes['designDocuments'][$name];
303
        }
304
        return null;
305
    }
306
307
    /**
308
     * @param bool $allOrNothing
309
     */
310
    public function setAllOrNothingFlush($allOrNothing)
311
    {
312
        $this->attributes['allOrNothingFlush'] = (bool)$allOrNothing;
313
    }
314
315
    /**
316
     * @return bool
317
     */
318
    public function getAllOrNothingFlush()
319
    {
320
        return $this->attributes['allOrNothingFlush'];
321
    }
322
323
    public function setLuceneHandlerName($handlerName = '_fti')
324
    {
325
        $this->attributes['luceneHandlerName'] = $handlerName;
326
    }
327
328
    public function getLuceneHandlerName()
329
    {
330
        if (!$this->attributes['luceneHandlerName']) {
331
            throw CouchDBException::luceneNotConfigured();
332
        }
333
334
        return $this->attributes['luceneHandlerName'];
335
    }
336
337
    /**
338
     * @return \Doctrine\ODM\CouchDB\Migrations\NullMigration;
0 ignored issues
show
The doc-type \Doctrine\ODM\CouchDB\Migrations\NullMigration; could not be parsed: Expected "|" or "end of type", but got ";" at position 46. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
339
     */
340
    public function getMigrations()
341
    {
342
        if (!isset($this->attributes['migrations'])) {
343
            $this->attributes['migrations'] = new Migrations\NullMigration();
344
        }
345
346
        return $this->attributes['migrations'];
347
    }
348
349
    /**
350
     * @param DocumentMigration $migration
351
     */
352
    public function setMigrations(DocumentMigration $migration)
353
    {
354
        $this->attributes['migrations'] = $migration;
355
    }
356
}
357