|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Acquia\LiftClient\Manager; |
|
4
|
|
|
|
|
5
|
|
|
use Acquia\LiftClient\Entity\Slot; |
|
6
|
|
|
use GuzzleHttp\Psr7\Request; |
|
7
|
|
|
|
|
8
|
|
|
class SlotManager extends ManagerBase |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Get a list of slots. |
|
12
|
|
|
* |
|
13
|
|
|
* Example of how to structure the $options parameter: |
|
14
|
|
|
* <code> |
|
15
|
|
|
* $options = [ |
|
16
|
|
|
* 'visible_on_page' => 'http://localhost/blog/*', |
|
17
|
|
|
* 'status' => 'enabled', |
|
18
|
|
|
* ]; |
|
19
|
|
|
* </code> |
|
20
|
|
|
* |
|
21
|
|
|
* @see http://docs.decision-api.acquia.com/#slots_get |
|
22
|
|
|
* |
|
23
|
|
|
* @param array $options |
|
24
|
|
|
* |
|
25
|
|
|
* @return \Acquia\LiftClient\Entity\Slot[] |
|
26
|
|
|
* |
|
27
|
|
|
* @throws \GuzzleHttp\Exception\RequestException |
|
28
|
|
|
*/ |
|
29
|
|
|
public function query($options = []) |
|
30
|
|
|
{ |
|
31
|
|
|
$variables = $options + [ |
|
32
|
|
|
'limit' => 1000, |
|
33
|
|
|
'start' => 0, |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
$url = '/slots'; |
|
37
|
|
|
$url .= isset($variables['visible_on_page']) ? "&visible_on_page={$variables['visible_on_page']}" : ''; |
|
38
|
|
|
$url .= isset($variables['status']) ? "&status={$variables['status']}" : ''; |
|
39
|
|
|
|
|
40
|
|
|
// Now make the request. |
|
41
|
|
|
$request = new Request('GET', $url); |
|
42
|
|
|
$data = $this->client->getResponseJson($request); |
|
43
|
|
|
|
|
44
|
|
|
// Get them as Slot objects |
|
45
|
|
|
$slots = []; |
|
46
|
|
|
foreach ($data as $dataItem) { |
|
47
|
|
|
$slots[] = new Slot($dataItem); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return $slots; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get a specific slot. |
|
55
|
|
|
* |
|
56
|
|
|
* Example of how to structure the $options parameter: |
|
57
|
|
|
* |
|
58
|
|
|
* @see http://docs.decision-api.acquia.com/#slots__slotId__get |
|
59
|
|
|
* |
|
60
|
|
|
* @param array $options |
|
|
|
|
|
|
61
|
|
|
* |
|
62
|
|
|
* @return \Acquia\LiftClient\Entity\Slot |
|
63
|
|
|
* |
|
64
|
|
|
* @throws \GuzzleHttp\Exception\RequestException |
|
65
|
|
|
*/ |
|
66
|
|
View Code Duplication |
public function get( |
|
|
|
|
|
|
67
|
|
|
$slotId |
|
68
|
|
|
) { |
|
69
|
|
|
$url = "/slots/{$slotId}"; |
|
70
|
|
|
|
|
71
|
|
|
// Now make the request. |
|
72
|
|
|
$request = new Request('GET', $url); |
|
73
|
|
|
$data = $this->client->getResponseJson($request); |
|
74
|
|
|
|
|
75
|
|
|
return new Slot($data); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Add a slot. |
|
80
|
|
|
* |
|
81
|
|
|
* @param \Acquia\LiftClient\Entity\Slot $slot |
|
82
|
|
|
* |
|
83
|
|
|
* @return \Acquia\LiftClient\Entity\Slot |
|
84
|
|
|
* |
|
85
|
|
|
* @throws \GuzzleHttp\Exception\RequestException |
|
86
|
|
|
*/ |
|
87
|
|
View Code Duplication |
public function add( |
|
|
|
|
|
|
88
|
|
|
Slot $slot |
|
89
|
|
|
) { |
|
90
|
|
|
$body = $slot->json(); |
|
91
|
|
|
$url = '/slots'; |
|
92
|
|
|
$request = new Request('POST', $url, [], $body); |
|
93
|
|
|
$data = $this->client->getResponseJson($request); |
|
94
|
|
|
|
|
95
|
|
|
return new Slot($data); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Deletes a slot by ID. |
|
100
|
|
|
* |
|
101
|
|
|
* @param string $id |
|
102
|
|
|
* |
|
103
|
|
|
* @return bool |
|
104
|
|
|
* returns TRUE if successful |
|
105
|
|
|
* |
|
106
|
|
|
* @throws \GuzzleHttp\Exception\RequestException |
|
107
|
|
|
*/ |
|
108
|
|
|
public function delete( |
|
109
|
|
|
$id |
|
110
|
|
|
) { |
|
111
|
|
|
$url = "/slots/{$id}"; |
|
112
|
|
|
$this->client->delete($url); |
|
113
|
|
|
|
|
114
|
|
|
return true; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.