|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ntentan\nibii; |
|
4
|
|
|
|
|
5
|
|
|
class Operations |
|
6
|
|
|
{ |
|
7
|
|
|
|
|
8
|
|
|
private $wrapper; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* |
|
12
|
|
|
* @var \ntentan\nibii\DriverAdapter |
|
13
|
|
|
*/ |
|
14
|
|
|
private $adapter; |
|
15
|
|
|
private $queryOperations; |
|
16
|
|
|
private $dataOperations; |
|
17
|
|
|
private $queryOperationMethods = [ |
|
18
|
|
|
'fetch', 'fetchFirst', 'filter', 'query', 'fields', |
|
19
|
|
|
'cover', 'limit', 'offset', 'filterBy', 'sortBy', |
|
20
|
|
|
'delete', 'count', 'update', 'with' |
|
21
|
|
|
]; |
|
22
|
|
|
private $dataOperationMethods = [ |
|
23
|
|
|
'save', 'validate' |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
34 |
|
public function __construct(RecordWrapper $wrapper, $table) |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
34 |
|
$this->wrapper = $wrapper; |
|
29
|
34 |
|
$this->adapter = $wrapper->getAdapter(); |
|
30
|
34 |
|
$driver = ORMContext::getInstance()->getDbContext()->getDriver(); |
|
31
|
34 |
|
$this->dataOperations = new DataOperations($wrapper, $driver); |
|
32
|
34 |
|
$this->queryOperations = new QueryOperations($wrapper, $this->dataOperations, $driver); |
|
33
|
34 |
|
} |
|
34
|
|
|
|
|
35
|
34 |
|
public function perform($name, $arguments) |
|
36
|
|
|
{ |
|
37
|
|
|
//@todo Think of using a hash here in future |
|
38
|
34 |
|
if (array_search($name, $this->queryOperationMethods) !== false) { |
|
39
|
30 |
|
return call_user_func_array([$this->queryOperations, "do$name"], $arguments); |
|
40
|
18 |
|
} else if (array_search($name, $this->dataOperationMethods) !== false) { |
|
41
|
10 |
|
return call_user_func_array([$this->dataOperations, "do$name"], $arguments); |
|
42
|
10 |
|
} else if ($this->queryOperations->initDynamicMethod($name)) { |
|
43
|
10 |
|
return $this->queryOperations->runDynamicMethod($arguments); |
|
44
|
|
|
} else { |
|
45
|
|
|
throw new NibiiException("Method {$name} not found"); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getData() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->dataOperations->getData(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
10 |
|
public function getInvalidFields() |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
10 |
|
return $this->dataOperations->getInvalidFields(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.