Odyssey
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
FeatureGateConfig Class Reference

Public Member Functions

 HasFeature (String $feature)
 
 GetFeatureData (String $feature)
 

Static Public Member Functions

static GetInstance ($dbh)
 

Protected Member Functions

 __construct ($dbh)
 
 GetConfig ()
 
 LoadConfig ()
 

Protected Attributes

 $data = []
 
 $dbh
 

Static Protected Attributes

static $instance
 

Detailed Description

Class to retrieve and contain the database configuration for Feature Gates

Definition at line 8 of file FeatureGateConfig.i.

Constructor & Destructor Documentation

◆ __construct()

FeatureGateConfig::__construct (   $dbh)
protected

FeatureGateConfig constructor.

Parameters
$dbhObject Database handler
Exceptions
exception

Definition at line 19 of file FeatureGateConfig.i.

19  {
20  $this->dbh = $dbh;
21  $this->LoadConfig();
22  }

Member Function Documentation

◆ GetConfig()

FeatureGateConfig::GetConfig ( )
protected

Database access. Ideally this would be repository class.

Returns
array Database result; empty array if no rows
Exceptions
exception

Definition at line 30 of file FeatureGateConfig.i.

30  :array {
31  $sql = <<< SQL
32 SELECT feature, enabled_all, enabled_cu, params
33 FROM cufeaturegate;
34 SQL;
35  $query = db_query($sql, $this->dbh);
36  if (!$query) {
37  throw new Exception('Could not read cufeaturegate table.');
38  }
39  $rows = db_fetch_all($query);
40  if (!$rows) {
41  return [];
42  }
43  return $rows;
44  }

◆ GetFeatureData()

FeatureGateConfig::GetFeatureData ( String  $feature)

Return the config for a particular feature.

Parameters
String$featureIndicates which feature to gate
Returns
bool|mixed

Definition at line 92 of file FeatureGateConfig.i.

92  {
93  if ($this->HasFeature($feature)) {
94  return $this->data[$feature];
95  }
96  return false;
97  }
HasFeature(String $feature)

◆ GetInstance()

static FeatureGateConfig::GetInstance (   $dbh)
static

Create or recover an instance of FeatureGateConfig

Parameters
$dbhObject Database handle
Returns
FeatureGateConfig
Exceptions
exception

Definition at line 69 of file FeatureGateConfig.i.

70  if (!static::$instance instanceof FeatureGateConfig) {
71  static::$instance = new FeatureGateConfig($dbh);
72  }
73  return static::$instance;
74  }

◆ HasFeature()

FeatureGateConfig::HasFeature ( String  $feature)

Checks if the feature is represented in the config

Parameters
String$featureIndicates which feature to gate
Returns
bool

Definition at line 82 of file FeatureGateConfig.i.

82  :bool {
83  return array_key_exists($feature, $this->data);
84  }

◆ LoadConfig()

FeatureGateConfig::LoadConfig ( )
protected

Iterates through data, loading it by feature id

Exceptions
exception

Definition at line 51 of file FeatureGateConfig.i.

51  {
52  $data = $this->GetConfig();
53  foreach ($data as $dataRow) {
54  $this->data[$dataRow['feature']] = [
55  'enabled_all' => $dataRow['enabled_all'],
56  'enabled_cu' => json_decode($dataRow['enabled_cu'], true) ?? [],
57  'params' => json_decode($dataRow['params'], true) ?? [],
58  ];
59  }
60  }

The documentation for this class was generated from the following file: