|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* The MIT License |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright 2014-2018 James Ekow Abaka Ainooson |
|
7
|
|
|
* |
|
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
9
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
10
|
|
|
* in the Software without restriction, including without limitation the rights |
|
11
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
12
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
13
|
|
|
* furnished to do so, subject to the following conditions: |
|
14
|
|
|
* |
|
15
|
|
|
* The above copyright notice and this permission notice shall be included in |
|
16
|
|
|
* all copies or substantial portions of the Software. |
|
17
|
|
|
* |
|
18
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
19
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
21
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
22
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
23
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
24
|
|
|
* THE SOFTWARE. |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace ntentan\nibii; |
|
28
|
|
|
|
|
29
|
|
|
use ntentan\nibii\exceptions\NibiiException; |
|
30
|
|
|
|
|
31
|
|
|
class Operations |
|
32
|
|
|
{ |
|
33
|
|
|
private $wrapper; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var \ntentan\nibii\DriverAdapter |
|
37
|
|
|
*/ |
|
38
|
|
|
private $adapter; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var QueryOperations |
|
42
|
|
|
*/ |
|
43
|
|
|
private $queryOperations; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var DataOperations |
|
47
|
|
|
*/ |
|
48
|
|
|
private $dataOperations; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var array |
|
52
|
|
|
*/ |
|
53
|
|
|
private $queryOperationMethods = [ |
|
54
|
|
|
'fetch', 'fetchFirst', 'filter', 'query', 'fields', |
|
55
|
|
|
'cover', 'limit', 'offset', 'filterBy', 'sortBy', |
|
56
|
|
|
'delete', 'count', 'update', 'with', |
|
57
|
|
|
]; |
|
58
|
|
|
private $dataOperationMethods = [ |
|
59
|
|
|
'save', 'validate', |
|
60
|
|
|
]; |
|
61
|
|
|
|
|
62
|
34 |
|
public function __construct(RecordWrapper $wrapper, $table) |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
34 |
|
$this->wrapper = $wrapper; |
|
65
|
34 |
|
$this->adapter = $wrapper->getAdapter(); |
|
66
|
34 |
|
$driver = ORMContext::getInstance()->getDbContext()->getDriver(); |
|
67
|
34 |
|
$this->dataOperations = new DataOperations($wrapper, $driver); |
|
68
|
34 |
|
$this->queryOperations = new QueryOperations($wrapper, $this->dataOperations, $driver); |
|
69
|
34 |
|
} |
|
70
|
|
|
|
|
71
|
34 |
|
public function perform($name, $arguments) |
|
72
|
|
|
{ |
|
73
|
|
|
//@todo Think of using a hash here in future |
|
74
|
34 |
|
if (array_search($name, $this->queryOperationMethods) !== false) { |
|
75
|
30 |
|
return call_user_func_array([$this->queryOperations, "do$name"], $arguments); |
|
76
|
18 |
|
} elseif (array_search($name, $this->dataOperationMethods) !== false) { |
|
77
|
10 |
|
return call_user_func_array([$this->dataOperations, "do$name"], $arguments); |
|
78
|
10 |
|
} elseif ($this->queryOperations->initDynamicMethod($name)) { |
|
79
|
10 |
|
return $this->queryOperations->runDynamicMethod($arguments); |
|
80
|
|
|
} else { |
|
81
|
|
|
throw new NibiiException("Method {$name} not found"); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getData() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->dataOperations->getData(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
10 |
|
public function getInvalidFields() |
|
91
|
|
|
{ |
|
92
|
10 |
|
return $this->dataOperations->getInvalidFields(); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.