|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Facile\MongoDbBundle\Capsule; |
|
6
|
|
|
|
|
7
|
|
|
use MongoDB\Database as MongoDatabase; |
|
8
|
|
|
use MongoDB\Driver\Manager; |
|
9
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class Database. |
|
13
|
|
|
* |
|
14
|
|
|
* @internal |
|
15
|
|
|
*/ |
|
16
|
|
|
final class Database extends MongoDatabase |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var EventDispatcherInterface */ |
|
19
|
|
|
private $eventDispatcher; |
|
20
|
|
|
|
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
private $clientName; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string */ |
|
25
|
|
|
private $databaseName; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Database constructor. |
|
29
|
|
|
* |
|
30
|
|
|
* @param Manager $manager |
|
31
|
|
|
* @param string $clientName |
|
32
|
|
|
* @param string $databaseName |
|
33
|
6 |
|
* @param array $options |
|
34
|
|
|
* @param EventDispatcherInterface $eventDispatcher |
|
35
|
|
|
* |
|
36
|
|
|
* @internal param DataCollectorLoggerInterface $logger |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct( |
|
39
|
|
|
Manager $manager, |
|
40
|
6 |
|
string $clientName, |
|
41
|
6 |
|
string $databaseName, |
|
42
|
6 |
|
array $options = [], |
|
43
|
6 |
|
EventDispatcherInterface $eventDispatcher |
|
44
|
6 |
|
) { |
|
45
|
|
|
parent::__construct($manager, $databaseName, $options); |
|
46
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
47
|
|
|
$this->clientName = $clientName; |
|
48
|
|
|
$this->databaseName = $databaseName; |
|
49
|
1 |
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
1 |
|
*/ |
|
54
|
1 |
|
public function selectCollection($collectionName, array $options = []) |
|
55
|
1 |
|
{ |
|
56
|
1 |
|
$debug = $this->__debugInfo(); |
|
57
|
|
|
$options += [ |
|
58
|
|
|
'readConcern' => $debug['readConcern'], |
|
59
|
1 |
|
'readPreference' => $debug['readPreference'], |
|
60
|
1 |
|
'typeMap' => $debug['typeMap'], |
|
61
|
1 |
|
'writeConcern' => $debug['writeConcern'], |
|
62
|
1 |
|
]; |
|
63
|
1 |
|
|
|
64
|
1 |
|
return new Collection( |
|
65
|
1 |
|
$debug['manager'], |
|
66
|
|
|
$this->clientName, |
|
67
|
|
|
$this->databaseName, |
|
68
|
|
|
$collectionName, |
|
69
|
|
|
$options, |
|
70
|
|
|
$this->eventDispatcher |
|
71
|
|
|
); |
|
72
|
1 |
|
} |
|
73
|
|
|
|
|
74
|
1 |
|
/** |
|
75
|
|
|
* {@inheritdoc} |
|
76
|
1 |
|
*/ |
|
77
|
1 |
|
public function withOptions(array $options = []) |
|
78
|
1 |
|
{ |
|
79
|
1 |
|
$debug = $this->__debugInfo(); |
|
80
|
|
|
$options += [ |
|
81
|
|
|
'readConcern' => $debug['readConcern'], |
|
82
|
1 |
|
'readPreference' => $debug['readPreference'], |
|
83
|
|
|
'typeMap' => $debug['typeMap'], |
|
84
|
|
|
'writeConcern' => $debug['writeConcern'], |
|
85
|
|
|
]; |
|
86
|
|
|
|
|
87
|
|
|
return new self($debug['manager'], $this->clientName, $debug['databaseName'], $options, $this->eventDispatcher); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|