1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Adlogix package. |
4
|
|
|
* |
5
|
|
|
* (c) Allan Segebarth <[email protected]> |
6
|
|
|
* (c) Jean-Jacques Courtens <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Adlogix\ConfluenceClient\Service; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
use Adlogix\ConfluenceClient\Exception\ExceptionWrapper; |
16
|
|
|
use Adlogix\ConfluenceClient\HttpClient\HttpClientInterface; |
17
|
|
|
use GuzzleHttp\Exception\RequestException; |
18
|
|
|
use JMS\Serializer\SerializerInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class AbstractApiService |
22
|
|
|
* @package Adlogix\ConfluenceClient\Service |
23
|
|
|
* @author Cedric Michaux <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class AbstractApiService extends AbstractService |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var HttpClientInterface |
29
|
|
|
*/ |
30
|
|
|
protected $httpClient; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* AbstractService constructor. |
34
|
|
|
* |
35
|
|
|
* @param SerializerInterface $serializer |
36
|
|
|
* @param HttpClientInterface $httpClient |
37
|
|
|
*/ |
38
|
|
|
public function __construct(SerializerInterface $serializer, HttpClientInterface $httpClient) |
39
|
|
|
{ |
40
|
|
|
parent::__construct($serializer); |
41
|
|
|
$this->httpClient = $httpClient; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function get($uri, array $options = []) |
45
|
|
|
{ |
46
|
|
|
try { |
47
|
|
|
$response = $this->httpClient |
48
|
|
|
->get($uri, $options); |
49
|
|
|
|
50
|
|
|
return $response->getBody() |
51
|
|
|
->getContents(); |
52
|
|
|
|
53
|
|
|
} catch (RequestException $exception) { |
54
|
|
|
throw ExceptionWrapper::wrap($exception, $this->serializer); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param array $oldQueryOptions |
60
|
|
|
* @param array $newQueryOptions |
61
|
|
|
* |
62
|
|
|
* @return mixed |
63
|
|
|
*/ |
64
|
|
|
protected function mergeQueryOptions(array $oldQueryOptions, array $newQueryOptions){ |
65
|
|
|
return array_merge_recursive( |
66
|
|
|
$oldQueryOptions, |
67
|
|
|
$newQueryOptions |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|