1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TonicForHealth\PagerDutyClient\Client; |
4
|
|
|
|
5
|
|
|
use Http\Client\Common\HttpMethodsClient; |
6
|
|
|
use Http\Discovery\Exception\NotFoundException; |
7
|
|
|
use Http\Discovery\HttpClientDiscovery; |
8
|
|
|
use Http\Discovery\MessageFactoryDiscovery; |
9
|
|
|
use TonicForHealth\PagerDutyClient\Client\Exception\EventClientFactoryCreateException; |
10
|
|
|
use TonicForHealth\PagerDutyClient\Entity\Event\EventRepresentation; |
11
|
|
|
use TonicForHealth\PagerDutyClient\RepresentProcessor\RepresentProcessor; |
12
|
|
|
use TonicForHealth\PagerDutyClient\Validation\ValidationResponseFactory; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class EventClientFactory. |
16
|
|
|
*/ |
17
|
|
|
class EventClientFactory |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param string $apiRootUrl |
21
|
|
|
* |
22
|
|
|
* @return EventClient |
23
|
|
|
* |
24
|
|
|
* @throws EventClientFactoryCreateException |
25
|
|
|
*/ |
26
|
|
|
public static function createEventClient($apiRootUrl) |
27
|
|
|
{ |
28
|
|
|
$httpClient = self::createHttpClient(); |
29
|
|
|
|
30
|
|
|
$representProcessor = self::createRepresentProcessor(); |
31
|
|
|
self::addBasicRepresentations($representProcessor); |
32
|
|
|
$validationResponse = ValidationResponseFactory::createValidation('Event'); |
33
|
|
|
|
34
|
|
|
$eventClient = new EventClient( |
35
|
|
|
$apiRootUrl, |
36
|
|
|
$httpClient, |
37
|
|
|
$representProcessor, |
38
|
|
|
$validationResponse |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
return $eventClient; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return HttpMethodsClient |
46
|
|
|
* |
47
|
|
|
* @throws EventClientFactoryCreateException |
48
|
|
|
*/ |
49
|
|
|
protected static function createHttpClient() |
50
|
|
|
{ |
51
|
|
|
try { |
52
|
|
|
$httpClient = new HttpMethodsClient( |
53
|
|
|
HttpClientDiscovery::find(), |
54
|
|
|
MessageFactoryDiscovery::find() |
55
|
|
|
); |
56
|
|
|
} catch (NotFoundException $exception) { |
57
|
|
|
throw new EventClientFactoryCreateException($exception->getMessage(), $exception->getCode(), $exception); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $httpClient; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return RepresentProcessor |
65
|
|
|
*/ |
66
|
|
|
protected static function createRepresentProcessor() |
67
|
|
|
{ |
68
|
|
|
return new RepresentProcessor(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* add basic representations for EventClient. |
73
|
|
|
* |
74
|
|
|
* @param RepresentProcessor $representProcessor |
75
|
|
|
*/ |
76
|
|
|
protected static function addBasicRepresentations(RepresentProcessor $representProcessor) |
77
|
|
|
{ |
78
|
|
|
$representProcessor->addRepresentation(new EventRepresentation()); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|