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
|
|
|
|
17
|
|
|
namespace responsible\core\endpoints; |
18
|
|
|
|
19
|
|
|
use responsible\core\endpoints; |
20
|
|
|
use responsible\core\exception; |
21
|
|
|
use responsible\core\headers; |
22
|
|
|
use responsible\responsible; |
23
|
|
|
|
24
|
|
|
class system extends map |
25
|
|
|
{ |
26
|
|
|
public $responsible = null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* [$settings] |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
private $settings = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* [$RESPONSE Set the internal system response] |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected $RESPONSE; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* [__construct Silence..] |
42
|
|
|
*/ |
43
|
|
|
public function __construct() |
44
|
|
|
{ |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* [settings Inherited settings] |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
|
|
public function settings(array $settings) |
52
|
|
|
{ |
53
|
|
|
$this->settings = $settings; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* [headerMethods] |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
public function headerMethods() |
61
|
|
|
{ |
62
|
|
|
$headers = new headers\header(); |
63
|
|
|
$headers->setAllowedMethods( |
64
|
|
|
['GET', 'POST', 'PATCH'] |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* [tokenAccess_token Empty function, not handled in this class. See header for method] |
70
|
|
|
* @see [header->accessCredentialsHeaders()] |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
|
|
public function tokenAccessToken() |
74
|
|
|
{ |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* [run Get the system response] |
79
|
|
|
* @return mixed |
80
|
|
|
*/ |
81
|
|
|
public function run() |
82
|
|
|
{ |
83
|
|
|
/** |
84
|
|
|
* Method exists |
85
|
|
|
*/ |
86
|
|
|
if (isset($this->settings['model']['method'])) { |
87
|
|
|
$method = $this->settings['model']['method']; |
88
|
|
|
if (method_exists($this, $method)) { |
89
|
|
|
return call_user_func(array($this, $method)); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Method doesn't exists throw an application error |
95
|
|
|
*/ |
96
|
|
|
(new exception\errorException()) |
97
|
|
|
->message('The requested method `' . $this->settings['model']['method'] . '` dosen\'t exist. Please read the documentation on supported request types.') |
98
|
|
|
->error('APPLICATION_ERROR'); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|