Skip to content

Commit 1033588

Browse files
authored
#15447 add flexible feature scheduling v3.0 (#4)
#15447 add flexible feature scheduling v3.0
1 parent d51f900 commit 1033588

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/Stanza.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class Stanza
1919

2020
public function __construct(array $stanza)
2121
{
22+
// #15447 replace default variants with scheduled variants if scheduled is valid
23+
$stanza = $this->getScheduledVariant($stanza);
24+
2225
// Pull stuff from the config stanza.
2326
$this->description = $this->parseDescription($stanza);
2427
$this->enabled = $this->parseEnabled($stanza);
@@ -34,12 +37,43 @@ public function __construct(array $stanza)
3437
$this->end = $this->parseEnd($stanza);
3538
}
3639

40+
3741
public function __get($name)
3842
{
3943
if (isset($this->$name)) return $this->$name;
4044
throw new \Exception("$name is not a property of the Stanza class");
4145
}
4246

47+
48+
/*
49+
* Get scheduled variants if exists and active
50+
* @param : feature config array
51+
* @return : schedued variants if scheduling is active, otherwise default variants
52+
*/
53+
private function getScheduledVariant($stanza){
54+
55+
// check if scheduled config obj exists
56+
if(isset($stanza['scheduled']) ){
57+
$time = time();
58+
$scheduled_config = $stanza['scheduled'];
59+
$start_time = $this->parseStart($scheduled_config);
60+
$end_time = $this->parseEnd($scheduled_config);
61+
62+
// override scheduled variants if scheduling is active
63+
if( ( !empty($start_time) && $start_time <= $time )
64+
&& ( empty($end_time) || ( !empty($end_time) && $end_time >= $time ) ) ){
65+
66+
$stanza = $scheduled_config;
67+
68+
}
69+
70+
}
71+
72+
return $stanza;
73+
74+
}
75+
76+
4377
////////////////////////////////////////////////////////////////////////
4478
// Configuration parsing
4579

@@ -134,7 +168,7 @@ private function parseVariantName(array $stanza, $what)
134168

135169
private function parsePublicURLOverride(array $stanza)
136170
{
137-
if (!isset($stanza['public_url_override'])) return false;
171+
if (!isset($stanza['public_url_override'])) return true; //set true by default
138172
return $stanza['public_url_override'];
139173
}
140174

0 commit comments

Comments
 (0)