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