1 | <?php |
||
10 | class Client implements RequestableInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var Guzzle |
||
14 | */ |
||
15 | protected $client; |
||
16 | |||
17 | /** |
||
18 | * @var RequestInterface |
||
19 | */ |
||
20 | protected $request; |
||
21 | |||
22 | /** |
||
23 | * @var ResponseInterface |
||
24 | */ |
||
25 | protected $response; |
||
26 | |||
27 | /** |
||
28 | * API Key |
||
29 | * |
||
30 | * The custom API key provided by Teamwork |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $key; |
||
35 | |||
36 | /** |
||
37 | * URL |
||
38 | * |
||
39 | * The URL that is set to query the Teamwork API. |
||
40 | * This is the account URL used to access the project |
||
41 | * management system. This is passed in on construct. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $url; |
||
46 | |||
47 | /** |
||
48 | * Currently this package doesn't support XML |
||
49 | * but overtime this would be part of that support |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $dataFormat = 'json'; |
||
54 | |||
55 | /** |
||
56 | * @param Guzzle $client |
||
57 | * @param $key |
||
58 | * @param $url |
||
59 | */ |
||
60 | public function __construct(Guzzle $client, $key, $url) |
||
66 | |||
67 | /** |
||
68 | * Get |
||
69 | * |
||
70 | * @param $endpoint |
||
71 | * |
||
72 | * @return Client |
||
73 | */ |
||
74 | public function get($endpoint, $query = null) |
||
80 | |||
81 | /** |
||
82 | * Post |
||
83 | * |
||
84 | * @param $endpoint |
||
85 | * @param $data |
||
86 | * |
||
87 | * @return Client |
||
88 | */ |
||
89 | public function post($endpoint, $data) |
||
93 | |||
94 | /** |
||
95 | * Put |
||
96 | * |
||
97 | * @param $endpoint |
||
98 | * @param $data |
||
99 | * |
||
100 | * @return Client |
||
101 | */ |
||
102 | public function put($endpoint, $data = []) |
||
106 | |||
107 | /** |
||
108 | * Delete |
||
109 | * |
||
110 | * @param $endpoint |
||
111 | * |
||
112 | * @return Client |
||
113 | * @internal param $data |
||
114 | * |
||
115 | */ |
||
116 | public function delete($endpoint) |
||
120 | |||
121 | /** |
||
122 | * Build Request |
||
123 | * |
||
124 | * build up request including authentication, body, |
||
125 | * and string queries if necessary. This is where the bulk |
||
126 | * of the data is build up to connect to Teamwork with. |
||
127 | * |
||
128 | * @param $endpoint |
||
129 | * @param string $action |
||
130 | * @param array $params |
||
131 | * @throws |
||
132 | * |
||
133 | * @return $this |
||
134 | */ |
||
135 | public function buildRequest($endpoint, $action, $params = [], $query = null) |
||
157 | |||
158 | /** |
||
159 | * Response |
||
160 | * |
||
161 | * this send the request from the built response and |
||
162 | * returns the response as a JSON stdClass. |
||
163 | */ |
||
164 | public function response($fullResponse = false) |
||
174 | |||
175 | /** |
||
176 | * Build Url |
||
177 | * |
||
178 | * builds the url to make the request to Teamwork with |
||
179 | * and passes it into Guzzle. Also checks if trailing slash |
||
180 | * is present. |
||
181 | * |
||
182 | * @param $endpoint |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | public function buildUrl($endpoint) |
||
197 | |||
198 | /** |
||
199 | * Get Request |
||
200 | * |
||
201 | * @return mixed |
||
202 | */ |
||
203 | public function getRequest() |
||
207 | } |
||
208 |
When comparing the result of a bit operation, we suggest to add explicit parenthesis and not to rely on PHP’s built-in operator precedence to ensure the code behaves as intended and to make it more readable.
Let’s take a look at these examples: