|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ByJG\AnyDataset\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use ByJG\AnyDataset\ConnectionManagement; |
|
6
|
|
|
use ByJG\AnyDataset\Database\MongoDBDriver; |
|
7
|
|
|
use ByJG\AnyDataset\Database\NoSQLDriverInterface; |
|
8
|
|
|
use ByJG\AnyDataset\Exception\NotImplementedException; |
|
9
|
|
|
use InvalidArgumentException; |
|
10
|
|
|
|
|
11
|
|
|
class NoSqlDataset implements NoSQLDriverInterface |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Enter description here... |
|
16
|
|
|
* |
|
17
|
|
|
* @var ConnectionManagement |
|
18
|
|
|
*/ |
|
19
|
|
|
private $_connectionManagement; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* |
|
23
|
|
|
* @var NoSQLDriverInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
private $_dbDriver = null; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $dbname |
|
30
|
|
|
* @param string $collection |
|
31
|
|
|
* @throws InvalidArgumentException |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct($dbname, $collection) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->_connectionManagement = new ConnectionManagement($dbname); |
|
36
|
|
|
|
|
37
|
|
|
if ($this->_connectionManagement->getDriver() == "mongodb") { |
|
38
|
|
|
$this->_dbDriver = new MongoDBDriver($this->_connectionManagement, $collection); |
|
39
|
|
|
} else { |
|
40
|
|
|
throw new InvalidArgumentException("There is no '{$this->_connectionManagement->getDriver()}' NoSQL database"); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return ConnectionManagement |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getConnectionManagement() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->_connectionManagement; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return MongoDBDriver|NoSQLDriverInterface |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getDbDriver() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->_dbDriver; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testConnection() |
|
61
|
|
|
{ |
|
62
|
|
|
return true; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* |
|
67
|
|
|
* @return mixed |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getCollection() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->getDbDriver()->getCollection(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* |
|
76
|
|
|
* @param mixed $filter |
|
77
|
|
|
* @param null $fields |
|
78
|
|
|
* @return IteratorInterface $filter |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getIterator($filter = null, $fields = null) |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->getDbDriver()->getIterator($filter, $fields); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* |
|
87
|
|
|
* @param void $document |
|
88
|
|
|
*/ |
|
89
|
|
|
public function insert($document) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->getDbDriver()->insert($document); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* |
|
96
|
|
|
* @param mixed $collection |
|
97
|
|
|
* @return bool |
|
98
|
|
|
*/ |
|
99
|
|
|
public function setCollection($collection) |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->getDbDriver()->setCollection($collection); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* |
|
106
|
|
|
* @param mixed $document |
|
107
|
|
|
* @param mixed $filter |
|
108
|
|
|
* @param mixed $options |
|
109
|
|
|
* @return bool |
|
110
|
|
|
*/ |
|
111
|
|
|
public function update($document, $filter = null, $options = null) |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->getDbDriver()->update($document, $filter, $options); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @access public |
|
118
|
|
|
* @return string |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getDBConnection() |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->getDbDriver()->getDbConnection(); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @param $name |
|
127
|
|
|
* @param $value |
|
128
|
|
|
* @throws NotImplementedException |
|
129
|
|
|
*/ |
|
130
|
|
|
public function setDriverAttribute($name, $value) |
|
|
|
|
|
|
131
|
|
|
{ |
|
132
|
|
|
throw new NotImplementedException('Method not implemented'); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @param $name |
|
137
|
|
|
* @throws NotImplementedException |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getDriverAttribute($name) |
|
|
|
|
|
|
140
|
|
|
{ |
|
141
|
|
|
throw new NotImplementedException('Method not implemented'); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.