1 | <?php |
||
29 | abstract class AbstractResource implements ResourceInterface |
||
30 | { |
||
31 | /** |
||
32 | * Concrete HTTP client. |
||
33 | * |
||
34 | * @var ClientInterface |
||
35 | */ |
||
36 | protected $client; |
||
37 | |||
38 | /** |
||
39 | * Access Token. |
||
40 | * |
||
41 | * Access Token must be added to request Headers. |
||
42 | * 'Authorization: Bearer Access-Token' |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $accessToken = ''; |
||
47 | |||
48 | /** |
||
49 | * Response Transformer. |
||
50 | * |
||
51 | * Transform PSR Response or JSON string from HTTP Client to another format: Array, Object, ... |
||
52 | * |
||
53 | * @var ResponseTransformerInterface |
||
54 | */ |
||
55 | protected $responseTransformer; |
||
56 | |||
57 | /** |
||
58 | * Api Exception transformer. |
||
59 | * |
||
60 | * Transform Exceptions throw by HTTP Client to another Exceptions. |
||
61 | * |
||
62 | * @see \Zibios\WrikePhpLibrary\Exception\Api\ApiException |
||
63 | * |
||
64 | * @var ApiExceptionTransformerInterface |
||
65 | */ |
||
66 | protected $apiExceptionTransformer; |
||
67 | |||
68 | /** |
||
69 | * Helper for request path calculations. |
||
70 | * |
||
71 | * @var RequestPathProcessor |
||
72 | */ |
||
73 | protected $requestPathProcessor; |
||
74 | |||
75 | /** |
||
76 | * Resource constructor. |
||
77 | * |
||
78 | * @param ClientInterface $client |
||
79 | * @param ResponseTransformerInterface $responseTransformer |
||
80 | * @param ApiExceptionTransformerInterface $apiExceptionTransformer |
||
81 | * @param string $accessToken |
||
82 | */ |
||
83 | 131 | public function __construct( |
|
98 | |||
99 | /** |
||
100 | * Return connection array ResourceMethod => RequestPathFormat. |
||
101 | * |
||
102 | * @see \Zibios\WrikePhpLibrary\Enum\Api\ResourceMethodEnum |
||
103 | * @see \Zibios\WrikePhpLibrary\Enum\Api\RequestPathFormatEnum |
||
104 | * |
||
105 | * @return array |
||
106 | */ |
||
107 | abstract protected function getResourceMethodConfiguration(): array; |
||
108 | |||
109 | /** |
||
110 | * @param string $requestMethod |
||
111 | * @param string $resourceMethod |
||
112 | * @param array $params |
||
113 | * @param string|array|null $id |
||
114 | * |
||
115 | * @throws \Zibios\WrikePhpLibrary\Exception\Api\ApiException |
||
116 | * @throws \LogicException |
||
117 | * @throws \InvalidArgumentException |
||
118 | * @throws \Throwable |
||
119 | * |
||
120 | * @return mixed |
||
121 | */ |
||
122 | 80 | protected function executeRequest(string $requestMethod, string $resourceMethod, array $params, $id) |
|
153 | } |
||
154 |