1 | <?php |
||
14 | trait HasWaiterTrait |
||
15 | { |
||
16 | /** |
||
17 | * Provides a blocking operation until the resource has reached a particular state. The method |
||
18 | * will enter a loop, requesting feedback from the remote API until it sends back an appropriate |
||
19 | * status. |
||
20 | * |
||
21 | * @param string $status The state to be reached |
||
22 | * @param int $timeout The maximum timeout. If the total time taken by the waiter has reached |
||
23 | * or exceed this timeout, the blocking operation will immediately cease. |
||
24 | * @param int $sleepPeriod The amount of time to pause between each HTTP request. |
||
25 | */ |
||
26 | public function waitUntil($status, $timeout = 60, $sleepPeriod = 1) |
||
40 | |||
41 | /** |
||
42 | * Provides a blocking operation until the resource has reached a particular state. The method |
||
43 | * will enter a loop, executing the callback until TRUE is returned. This provides great |
||
44 | * flexibility. |
||
45 | * |
||
46 | * @param callable $fn An anonymous function that will be executed on every iteration. You can |
||
47 | * encapsulate your own logic to determine whether the resource has |
||
48 | * successfully transitioned. When TRUE is returned by the callback, |
||
49 | * the loop will end. |
||
50 | * @param int|bool $timeout The maximum timeout in seconds. If the total time taken by the waiter has reached |
||
51 | * or exceed this timeout, the blocking operation will immediately cease. If FALSE |
||
52 | * is provided, the timeout will never be considered. |
||
53 | * @param int $sleepPeriod The amount of time to pause between each HTTP request. |
||
54 | */ |
||
55 | public function waitWithCallback(callable $fn, $timeout = 60, $sleepPeriod = 1) |
||
71 | |||
72 | /** |
||
73 | * Internal method used to identify whether a timeout has been exceeded. |
||
74 | * |
||
75 | * @param bool|int $timeout |
||
76 | * @param int $startTime |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | private function shouldHalt($timeout, $startTime) |
||
88 | |||
89 | /** |
||
90 | * Convenience method providing a blocking operation until the resource transitions to an |
||
91 | * ``ACTIVE`` status. |
||
92 | * |
||
93 | * @param int|bool $timeout The maximum timeout in seconds. If the total time taken by the waiter has reached |
||
94 | * or exceed this timeout, the blocking operation will immediately cease. If FALSE |
||
95 | * is provided, the timeout will never be considered. |
||
96 | */ |
||
97 | public function waitUntilActive($timeout = 60) |
||
101 | |||
102 | public function waitUntilDeleted($timeout = 60, $sleepPeriod = 1) |
||
123 | } |
||
124 |
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
Idable
provides a methodequalsId
that 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.