PluginProbe
Media Cloud Sync / 1.2.11
Media Cloud Sync v1.2.11
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / EndpointDiscovery / EndpointList.php

EndpointList.php in Media Cloud Sync 1.2.11, at includes/sdk/s3/Aws/EndpointDiscovery/EndpointList.php

81 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\EndpointDiscovery;
4
5 class EndpointList
6 {
7 private $active;
8 private $expired = [];
9 public function __construct(array $endpoints)
10 {
11 $this->active = $endpoints;
12 \reset($this->active);
13 }
14 /**
15 * Gets an active (unexpired) endpoint. Returns null if none found.
16 *
17 * @return null|string
18 */
19 public function getActive()
20 {
21 if (\count($this->active) < 1) {
22 return null;
23 }
24 while (\time() > \current($this->active)) {
25 $key = \key($this->active);
26 $this->expired[$key] = \current($this->active);
27 $this->increment($this->active);
28 unset($this->active[$key]);
29 if (\count($this->active) < 1) {
30 return null;
31 }
32 }
33 $active = \key($this->active);
34 $this->increment($this->active);
35 return $active;
36 }
37 /**
38 * Gets an active endpoint if possible, then an expired endpoint if possible.
39 * Returns null if no endpoints found.
40 *
41 * @return null|string
42 */
43 public function getEndpoint()
44 {
45 if (!empty($active = $this->getActive())) {
46 return $active;
47 }
48 return $this->getExpired();
49 }
50 /**
51 * Removes an endpoint from both lists.
52 *
53 * @param string $key
54 */
55 public function remove($key)
56 {
57 unset($this->active[$key]);
58 unset($this->expired[$key]);
59 }
60 /**
61 * Get an expired endpoint. Returns null if none found.
62 *
63 * @return null|string
64 */
65 private function getExpired()
66 {
67 if (\count($this->expired) < 1) {
68 return null;
69 }
70 $expired = \key($this->expired);
71 $this->increment($this->expired);
72 return $expired;
73 }
74 private function increment(&$array)
75 {
76 if (\next($array) === \false) {
77 \reset($array);
78 }
79 }
80 }
81