1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ================================== |
5
|
|
|
* Responsible PHP API |
6
|
|
|
* ================================== |
7
|
|
|
* |
8
|
|
|
* @link Git https://github.com/vince-scarpa/responsibleAPI.git |
9
|
|
|
* |
10
|
|
|
* @api Responible API |
11
|
|
|
* @package responsible\core\endpoints |
12
|
|
|
* |
13
|
|
|
* @author Vince scarpa <[email protected]> |
14
|
|
|
* |
15
|
|
|
*/ |
16
|
|
|
namespace responsible\core\endpoints; |
17
|
|
|
|
18
|
|
|
use responsible\core\endpoints; |
19
|
|
|
use responsible\core\exception; |
20
|
|
|
use responsible\core\headers; |
21
|
|
|
use responsible\responsible; |
22
|
|
|
|
23
|
|
|
class system extends map |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* [$settings] |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
private $settings = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* [$RESPONSE Set the internal system response] |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
protected $RESPONSE; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* [__construct Silence..] |
39
|
|
|
*/ |
40
|
|
|
public function __construct() |
41
|
|
|
{} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* [settings Inherited settings] |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
public function settings(array $settings) |
48
|
|
|
{ |
49
|
|
|
$this->settings = $settings; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* [headerMethods] |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function headerMethods() |
57
|
|
|
{ |
58
|
|
|
$headers = new headers\header; |
59
|
|
|
$headers->setAllowedMethods( |
60
|
|
|
['GET', 'POST', 'PATCH'] |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* [tokenAccess_token Empty function, not handled in this class. See header for method] |
66
|
|
|
* @see [header->accessCredentialsHeaders()] |
67
|
|
|
* @return void |
68
|
|
|
*/ |
69
|
|
|
public function tokenAccessToken() |
70
|
|
|
{} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* [run Get the system response] |
74
|
|
|
* @return object|null |
75
|
|
|
*/ |
76
|
|
|
public function run() |
77
|
|
|
{ |
78
|
|
|
/** |
79
|
|
|
* Method exists |
80
|
|
|
*/ |
81
|
|
|
if (isset($this->settings['model']['method'])) { |
82
|
|
|
$method = $this->settings['model']['method']; |
83
|
|
|
if (method_exists($this, $method)) { |
84
|
|
|
return call_user_func(array($this, $method)); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Method doesn't exists throw an application error |
90
|
|
|
*/ |
91
|
|
|
(new exception\errorException) |
92
|
|
|
->message('The requested method `' . $this->settings['model']['method'] . '` dosen\'t exist. Please read the documentation on supported request types.') |
93
|
|
|
->error('APPLICATION_ERROR'); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|