1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright 2014 Brian Smith <[email protected]>. |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace phparia\Client; |
20
|
|
|
|
21
|
|
|
use GuzzleHttp\Exception\RequestException; |
22
|
|
|
use phparia\Exception\ConflictException; |
23
|
|
|
use phparia\Exception\InvalidParameterException; |
24
|
|
|
use phparia\Exception\NotFoundException; |
25
|
|
|
use phparia\Exception\ServerException; |
26
|
|
|
use phparia\Exception\UnprocessableEntityException; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @author Brian Smith <[email protected]> |
30
|
|
|
*/ |
31
|
98 |
|
abstract class AriClientAware implements AriClientAwareInterface |
32
|
|
|
{ |
33
|
98 |
|
/** |
34
|
98 |
|
* @var AriClient |
35
|
|
|
*/ |
36
|
|
|
protected $client; |
37
|
|
|
|
38
|
|
|
public function __construct(AriClient $client) |
39
|
|
|
{ |
40
|
|
|
$this->client = $client; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return AriClient |
45
|
|
|
*/ |
46
|
|
|
public function getClient() |
47
|
|
|
{ |
48
|
|
|
return $this->client; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @todo This doesn't really belong here |
53
|
|
|
* @param RequestException $e |
54
|
|
|
* @throws ConflictException |
55
|
|
|
* @throws InvalidParameterException |
56
|
|
|
* @throws NotFoundException |
57
|
|
|
* @throws UnprocessableEntityException |
58
|
|
|
* @throws ServerException |
59
|
|
|
*/ |
60
|
|
|
protected function processRequestException(RequestException $e) { |
61
|
|
|
switch ($e->getCode()) { |
62
|
|
|
case 400: // Missing parameter |
63
|
|
|
throw new InvalidParameterException($e); |
64
|
|
|
case 404: // Does not exist |
65
|
|
|
throw new NotFoundException($e); |
66
|
|
|
case 409: |
67
|
|
|
throw new ConflictException($e); |
68
|
|
|
case 422: |
69
|
|
|
throw new UnprocessableEntityException($e); |
70
|
|
|
case 500: |
71
|
|
|
throw new ServerException($e); |
72
|
|
|
default: |
73
|
|
|
throw $e; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|