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