Odyssey
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
FeatureGate Class Reference
Inheritance diagram for FeatureGate:
CreditUnionGate

Public Member Functions

 __construct (String $feature, FeatureGateConfig $config)
 
 WillPass (String $creditUnion, array $params=null)
 

Protected Member Functions

 DetermineCreditUnionPass (String $creditUnion)
 
 GetFeatureParams (String $creditUnion)
 
 DeterminePass (String $creditUnion, array $params=null)
 

Protected Attributes

 $featureGateConfig
 
 $feature = ''
 

Detailed Description

Abstract base class to determine if a gate is passed. A gate can look at the credit union and if that passes look to see if there is an additional username filter. The minimal implementation is for a credit union to pass. Other entry points will allow testing of other parameters to make sure those requirements pass the gate check.

Definition at line 11 of file FeatureGate.i.

Constructor & Destructor Documentation

◆ __construct()

FeatureGate::__construct ( String  $feature,
FeatureGateConfig  $config 
)

FeatureGate constructor.

Parameters
String$featureIndicates which feature to gate
FeatureGateConfig$config
Exceptions
Exception

Definition at line 22 of file FeatureGate.i.

22  {
23  $this->featureGateConfig = $config;
24  if (strlen(trim($feature)) == 0) {
25  throw new Exception('Must supply a non-empty feature');
26  }
27  $this->feature = $feature;
28  }

Member Function Documentation

◆ DetermineCreditUnionPass()

FeatureGate::DetermineCreditUnionPass ( String  $creditUnion)
protected

Since all possible types of feature gates must start with a check for the credit union, this is located in the abstract class. If the feature does not exist, default return to false.

Parameters
String$creditUnionCredit union to check the gate for
Returns
bool

Definition at line 48 of file FeatureGate.i.

48  :bool {
49  $config = $this->featureGateConfig->GetFeatureData($this->feature);
50  if ($config) {
51  switch ($config['enabled_all']) {
52  case 'Y': // YES
53  return true;
54  break;
55  case 'O': // OFF
56  return false;
57  break;
58  case 'N': // NOT EVERONE - check credit union
59  return in_array($creditUnion, $config['enabled_cu']);
60  break;
61  default:
62  return false;
63  }
64  }
65  return false;
66  }

◆ DeterminePass()

FeatureGate::DeterminePass ( String  $creditUnion,
array  $params = null 
)
abstractprotected

Abstract method to determine if the credit union does, indeed, pass

Parameters
String$creditUnionCredit union to check the gate for
array$paramsExtra params for the gate check [Optional]
Returns
bool

◆ GetFeatureParams()

FeatureGate::GetFeatureParams ( String  $creditUnion)
protected

Return the params for a particular feature. This should only be called if the caller knows the credit union is allowed (i.e DetermineCreditUnionPass returned true).

params would be json string object in the form: {"creditUnion":{"usernames":["BongoBob","958777"],"ip":["192.168.1.14"],"someOtherParam":["item1","item2"]}} example: {"MYCU":{"usernames":["smith","jones"]}, "SCRUBCU":{"usernames":["bongobob", "4188"]}}

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

Definition at line 79 of file FeatureGate.i.

79  {
80  if ($this->featureGateConfig->HasFeature($this->feature)) {
81  $config = $this->featureGateConfig->GetFeatureData($this->feature);
82 
83  if ( $config && is_array($config) && array_key_exists("params", $config) ) {
84  // convert json params to array
85  $paramsByCU = $config["params"];
86  $returnArray = isset( $paramsByCU[$creditUnion] ) ? $paramsByCU[$creditUnion] : array();
87 
88  return $returnArray;
89  }
90  }
91  return false;
92  }

◆ WillPass()

FeatureGate::WillPass ( String  $creditUnion,
array  $params = null 
)

Check if credit union is allowed to pass.

Parameters
String$creditUnionCredit union to check the gate for
array$paramsExtra params for the gate check [Optional]
Returns
bool

Definition at line 37 of file FeatureGate.i.

37  :bool {
38  return $this->DeterminePass($creditUnion, $params);
39  }
DeterminePass(String $creditUnion, array $params=null)

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