1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ntentan\nibii; |
4
|
|
|
|
5
|
|
|
class Operations |
6
|
|
|
{ |
7
|
|
|
private $wrapper; |
8
|
|
|
/** |
9
|
|
|
* |
10
|
|
|
* @var \ntentan\nibii\DriverAdapter |
11
|
|
|
*/ |
12
|
|
|
private $adapter; |
13
|
|
|
private $queryOperations; |
14
|
|
|
private $dataOperations; |
15
|
|
|
|
16
|
|
|
private $queryOperationMethods = [ |
17
|
|
|
'fetch', 'fetchFirst', 'filter', 'query', 'fields', |
18
|
|
|
'cover', 'limit', 'offset', 'filterBy', 'sortBy', |
19
|
|
|
'delete', 'count', 'update' |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
private $dataOperationMethods = [ |
23
|
|
|
'save' |
24
|
|
|
]; |
25
|
|
|
|
26
|
34 |
|
public function __construct($wrapper, $adapter) |
27
|
|
|
{ |
28
|
34 |
|
$this->wrapper = $wrapper; |
29
|
34 |
|
$this->adapter = $adapter; |
30
|
34 |
|
$this->dataOperations = new DataOperations($wrapper, $adapter); |
31
|
34 |
|
$this->queryOperations = new QueryOperations($wrapper, $adapter, $this->dataOperations); |
32
|
34 |
|
} |
33
|
|
|
|
34
|
34 |
|
public function perform($name, $arguments) |
35
|
|
|
{ |
36
|
34 |
|
if (array_search($name, $this->queryOperationMethods) !== false) { |
37
|
24 |
|
return call_user_func_array([$this->queryOperations, "do$name"], $arguments); |
38
|
18 |
|
} else if (array_search($name, $this->dataOperationMethods) !== false){ |
39
|
10 |
|
return call_user_func_array([$this->dataOperations, "do$name"], $arguments); |
40
|
10 |
|
} else if($this->queryOperations->initDynamicMethod($name)) { |
41
|
10 |
|
return $this->queryOperations->runDynamicMethod($arguments); |
42
|
|
|
} else { |
43
|
|
|
throw new NibiiException("Method {$name} not found"); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getData() |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
return $this->dataOperations->getData(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getInvalidFields() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
return $this->dataOperations->getInvalidFields(); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.