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