Skip to content

Commit

Permalink
#15447 add flexible feature scheduling v3.0 (#4)
Browse files Browse the repository at this point in the history
#15447 add flexible feature scheduling v3.0
  • Loading branch information
mthazin authored Mar 5, 2018
1 parent d51f900 commit 1033588
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/Stanza.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Stanza

public function __construct(array $stanza)
{
// #15447 replace default variants with scheduled variants if scheduled is valid
$stanza = $this->getScheduledVariant($stanza);

// Pull stuff from the config stanza.
$this->description = $this->parseDescription($stanza);
$this->enabled = $this->parseEnabled($stanza);
Expand All @@ -34,12 +37,43 @@ public function __construct(array $stanza)
$this->end = $this->parseEnd($stanza);
}


public function __get($name)
{
if (isset($this->$name)) return $this->$name;
throw new \Exception("$name is not a property of the Stanza class");
}


/*
* Get scheduled variants if exists and active
* @param : feature config array
* @return : schedued variants if scheduling is active, otherwise default variants
*/
private function getScheduledVariant($stanza){

// check if scheduled config obj exists
if(isset($stanza['scheduled']) ){
$time = time();
$scheduled_config = $stanza['scheduled'];
$start_time = $this->parseStart($scheduled_config);
$end_time = $this->parseEnd($scheduled_config);

// override scheduled variants if scheduling is active
if( ( !empty($start_time) && $start_time <= $time )
&& ( empty($end_time) || ( !empty($end_time) && $end_time >= $time ) ) ){

$stanza = $scheduled_config;

}

}

return $stanza;

}


////////////////////////////////////////////////////////////////////////
// Configuration parsing

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

private function parsePublicURLOverride(array $stanza)
{
if (!isset($stanza['public_url_override'])) return false;
if (!isset($stanza['public_url_override'])) return true; //set true by default
return $stanza['public_url_override'];
}

Expand Down

0 comments on commit 1033588

Please sign in to comment.