1 | <?php |
||
12 | abstract class ServerResource implements ArrayAccess |
||
13 | { |
||
14 | use ArrayAccessTrait; |
||
15 | |||
16 | /** |
||
17 | * Associated server. |
||
18 | * |
||
19 | * @var \Laravel\Forge\Server |
||
20 | */ |
||
21 | protected $server; |
||
22 | |||
23 | /** |
||
24 | * Resource data. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $data = []; |
||
29 | |||
30 | /** |
||
31 | * Create new resource instance. |
||
32 | * |
||
33 | * @param \Laravel\Forge\Server $server |
||
34 | * @param array $data = [] |
||
35 | */ |
||
36 | public function __construct(Server $server, array $data = []) |
||
41 | |||
42 | /** |
||
43 | * Resource type. |
||
44 | * |
||
45 | * @return string |
||
46 | */ |
||
47 | abstract public static function resourceType(); |
||
48 | |||
49 | /** |
||
50 | * Resource path (relative to Server URL). |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | abstract public function resourcePath(); |
||
55 | |||
56 | /** |
||
57 | * Create new resource instance from HTTP response. |
||
58 | * |
||
59 | * @param \Psr\Http\Message\ResponseInterface $response |
||
60 | * @param \Laravel\Forge\Server $server |
||
61 | */ |
||
62 | public static function createFromResponse(ResponseInterface $response, Server $server) |
||
73 | |||
74 | /** |
||
75 | * Associated server. |
||
76 | * |
||
77 | * @return \Laravel\Forge\Server |
||
78 | */ |
||
79 | public function getServer() |
||
83 | |||
84 | /** |
||
85 | * HTTP Client from API provider. |
||
86 | * |
||
87 | * @return \GuzzleHttp\ClientInterface |
||
88 | */ |
||
89 | public function getHttpClient(): ClientInterface |
||
93 | |||
94 | /** |
||
95 | * Get resource data. |
||
96 | * |
||
97 | * @param string|int $key |
||
98 | * @param mixed $default = null |
||
99 | * |
||
100 | * @return mixed|null |
||
101 | */ |
||
102 | public function getData($key, $default = null) |
||
106 | |||
107 | /** |
||
108 | * Resource API URL. |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | public function apiUrl($path = '') |
||
120 | |||
121 | /** |
||
122 | * Resource ID. |
||
123 | * |
||
124 | * @return int |
||
125 | */ |
||
126 | public function id(): int |
||
130 | |||
131 | /** |
||
132 | * Update resource data. |
||
133 | * |
||
134 | * @return bool |
||
135 | */ |
||
136 | public function update(array $payload): bool |
||
153 | |||
154 | /** |
||
155 | * Delete current resource. |
||
156 | * |
||
157 | * @return bool |
||
158 | */ |
||
159 | public function delete() |
||
165 | } |
||
166 |