1 | <?php |
||
20 | abstract class TransifexObject |
||
21 | { |
||
22 | /** |
||
23 | * Options for the Transifex object. |
||
24 | * |
||
25 | * @var array|\ArrayAccess |
||
26 | */ |
||
27 | protected $options; |
||
28 | |||
29 | /** |
||
30 | * The HTTP client object to use in sending HTTP requests. |
||
31 | * |
||
32 | * @var Http |
||
33 | */ |
||
34 | protected $client; |
||
35 | |||
36 | /** |
||
37 | * @param array|\ArrayAccess $options Transifex options array. |
||
38 | * @param Http $client The HTTP client object. |
||
39 | */ |
||
40 | 1 | public function __construct($options = [], Http $client = null) |
|
41 | { |
||
42 | 1 | if (!is_array($options) && !($options instanceof \ArrayAccess)) { |
|
43 | throw new \InvalidArgumentException( |
||
44 | 'The options param must be an array or implement the ArrayAccess interface.' |
||
45 | ); |
||
46 | } |
||
47 | |||
48 | 1 | $this->options = $options; |
|
49 | 1 | $this->client = isset($client) ? $client : new Http($this->options); |
|
50 | 1 | } |
|
51 | |||
52 | /** |
||
53 | * Method to build and return a full request URL for the request. |
||
54 | * |
||
55 | * This method will add appropriate pagination details if necessary and also prepend the API URL |
||
56 | * to have a complete URL for the request. |
||
57 | * |
||
58 | * @param string $path URL to inflect |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | 1 | protected function fetchUrl($path) |
|
69 | |||
70 | /** |
||
71 | * Process the response and return it. |
||
72 | * |
||
73 | * @param Response $response The response. |
||
74 | * @param int $expectedCode The expected response code. |
||
75 | * |
||
76 | * @return Response |
||
77 | * |
||
78 | * @throws UnexpectedResponseException |
||
79 | */ |
||
80 | 68 | protected function processResponse(Response $response, $expectedCode = 200) |
|
95 | |||
96 | /** |
||
97 | * Method to update an API endpoint with resource content. |
||
98 | * |
||
99 | * @param string $path API path |
||
100 | * @param string $content The content of the resource. This can either be a string of data or a file path. |
||
101 | * @param string $type The type of content in the $content variable. This should be either string or file. |
||
102 | * |
||
103 | * @return Response |
||
104 | * |
||
105 | * @throws \InvalidArgumentException |
||
106 | */ |
||
107 | 7 | protected function updateResource($path, $content, $type) |
|
127 | } |
||
128 |