|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Saltwater\RedBean\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Saltwater\Server as S; |
|
6
|
|
|
use Saltwater\Utils as U; |
|
7
|
|
|
use Saltwater\Salt\Service; |
|
8
|
|
|
|
|
9
|
|
|
class Rest extends Service |
|
10
|
|
|
{ |
|
11
|
|
|
public function isCallable($method) |
|
12
|
|
|
{ |
|
13
|
|
|
if (parent::isCallable($method)) { |
|
14
|
|
|
return true; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
$class = U::explodeClass($this); |
|
18
|
|
|
|
|
19
|
|
|
return strpos($method, array_pop($class)) !== false; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param object $call |
|
24
|
|
|
* @param mixed $data |
|
25
|
|
|
* |
|
26
|
|
|
* @return array|int|\RedBean_OODBBean |
|
27
|
|
|
*/ |
|
28
|
|
|
public function call($call, $data = null) |
|
29
|
|
|
{ |
|
30
|
|
|
if (parent::isCallable($call->function)) { |
|
|
|
|
|
|
31
|
|
|
return parent::call($call, $data); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
return $this->restCall($call, $data); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param object $call |
|
39
|
|
|
* @param mixed $data |
|
40
|
|
|
* |
|
41
|
|
|
* @return array|int|\RedBean_OODBBean |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function restCall($call, $data = null) |
|
44
|
|
|
{ |
|
45
|
|
|
$path = $call->method; |
|
46
|
|
|
|
|
47
|
|
|
if (is_numeric($call->path)) { |
|
48
|
|
|
$path .= '/' . $call->path; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $this->callPath($call->http, $path, $data); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param string $http |
|
56
|
|
|
* @param string $path |
|
57
|
|
|
* @param mixed $data |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function callPath($http, $path, $data = null) |
|
60
|
|
|
{ |
|
61
|
|
|
$rest = $this->restHandler(); |
|
62
|
|
|
|
|
63
|
|
|
return $rest->handleRESTRequest($http, $path, $data); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
protected function restHandler() |
|
67
|
|
|
{ |
|
68
|
|
|
return new \RedBean_Plugin_BeanCan(S::$n->db($this->module)); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.