|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Facile\MongoDbBundle\Capsule; |
|
4
|
|
|
|
|
5
|
|
|
use MongoDB\Database as MongoDatabase; |
|
6
|
|
|
use MongoDB\Driver\Manager; |
|
7
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class Database. |
|
11
|
|
|
* @internal |
|
12
|
|
|
*/ |
|
13
|
|
|
final class Database extends MongoDatabase |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var EventDispatcherInterface */ |
|
16
|
|
|
private $eventDispatcher; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Database constructor. |
|
20
|
|
|
* |
|
21
|
|
|
* @param Manager $manager |
|
22
|
|
|
* @param string $databaseName |
|
23
|
|
|
* @param array $options |
|
24
|
|
|
* @param EventDispatcherInterface $eventDispatcher |
|
25
|
|
|
* |
|
26
|
|
|
* @internal param DataCollectorLoggerInterface $logger |
|
27
|
|
|
*/ |
|
28
|
6 |
|
public function __construct(Manager $manager, $databaseName, array $options = [], EventDispatcherInterface $eventDispatcher) |
|
29
|
|
|
{ |
|
30
|
6 |
|
parent::__construct($manager, $databaseName, $options); |
|
31
|
6 |
|
$this->eventDispatcher = $eventDispatcher; |
|
32
|
6 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritdoc} |
|
36
|
|
|
*/ |
|
37
|
1 |
View Code Duplication |
public function selectCollection($collectionName, array $options = []) |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
1 |
|
$debug = $this->__debugInfo(); |
|
40
|
|
|
$options += [ |
|
41
|
1 |
|
'readConcern' => $debug['readConcern'], |
|
42
|
1 |
|
'readPreference' => $debug['readPreference'], |
|
43
|
1 |
|
'typeMap' => $debug['typeMap'], |
|
44
|
1 |
|
'writeConcern' => $debug['writeConcern'], |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
1 |
|
return new Collection($debug['manager'], $debug['databaseName'], $collectionName, $options, $this->eventDispatcher); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
1 |
View Code Duplication |
public function withOptions(array $options = []) |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
1 |
|
$debug = $this->__debugInfo(); |
|
56
|
|
|
$options += [ |
|
57
|
1 |
|
'readConcern' => $debug['readConcern'], |
|
58
|
1 |
|
'readPreference' => $debug['readPreference'], |
|
59
|
1 |
|
'typeMap' => $debug['typeMap'], |
|
60
|
1 |
|
'writeConcern' => $debug['writeConcern'], |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
1 |
|
return new self($debug['manager'], $debug['databaseName'], $options, $this->eventDispatcher); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.