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