|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OhDear\PhpSdk\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use OhDear\PhpSdk\Resources\MaintenancePeriod; |
|
6
|
|
|
|
|
7
|
|
|
trait ManagesMaintenancePeriods |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @param int $siteId |
|
11
|
|
|
* |
|
12
|
|
|
* @return array |
|
13
|
|
|
*/ |
|
14
|
|
|
public function maintenancePeriods(int $siteId): array |
|
15
|
|
|
{ |
|
16
|
|
|
return $this->transformCollection( |
|
|
|
|
|
|
17
|
|
|
$this->get("sites/{$siteId}/maintenance-periods")['data'], |
|
|
|
|
|
|
18
|
|
|
MaintenancePeriod::class |
|
19
|
|
|
); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param int $siteId |
|
24
|
|
|
* @param int $stopMaintenanceAfterSeconds Stops after one hour by default |
|
25
|
|
|
* |
|
26
|
|
|
* @return MaintenancePeriod |
|
27
|
|
|
*/ |
|
28
|
|
|
public function startSiteMaintenance(int $siteId, int $stopMaintenanceAfterSeconds = 60 * 60): MaintenancePeriod |
|
29
|
|
|
{ |
|
30
|
|
|
$attributes = $this->post("sites/{$siteId}/start-maintenance", [ |
|
|
|
|
|
|
31
|
|
|
'stop_maintenance_after_seconds' => $stopMaintenanceAfterSeconds, |
|
32
|
|
|
]); |
|
33
|
|
|
|
|
34
|
|
|
return new MaintenancePeriod($attributes, $this); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param int $siteId |
|
39
|
|
|
*/ |
|
40
|
|
|
public function stopSiteMaintenance(int $siteId) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->post("sites/{$siteId}/stop-maintenance"); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param int $siteId |
|
47
|
|
|
* @param string $startsAt Y:m:d H:i |
|
48
|
|
|
* @param string $endsAt Y:m:d H:i |
|
49
|
|
|
* |
|
50
|
|
|
* @return MaintenancePeriod |
|
51
|
|
|
*/ |
|
52
|
|
|
public function createSiteMaintenance(int $siteId, string $startsAt, string $endsAt): MaintenancePeriod |
|
53
|
|
|
{ |
|
54
|
|
|
$payload = [ |
|
55
|
|
|
'site_id' => $siteId, |
|
56
|
|
|
'starts_at' => $startsAt, |
|
57
|
|
|
'ends_at' => $endsAt, |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
|
|
$attributes = $this->post('maintenance-periods', $payload); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
return new MaintenancePeriod($attributes, $this); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param int $maintenancePeriodId |
|
67
|
|
|
*/ |
|
68
|
|
|
public function deleteSiteMaintenance(int $maintenancePeriodId) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->delete("maintenance-periods/{$maintenancePeriodId}"); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.