class VariablesSet in Business Rules 8
Same name and namespace in other branches
- 2.x src/VariablesSet.php \Drupal\business_rules\VariablesSet
Class VariablesSet to be returned on each BusinessRulesVariable plugin.
@package Drupal\business_rules
Hierarchy
- class \Drupal\business_rules\VariablesSet
Expanded class hierarchy of VariablesSet
16 files declare their use of VariablesSet
- BusinessRulesConditionPluginInterface.php in src/
Plugin/ BusinessRulesConditionPluginInterface.php - BusinessRulesItemPluginBase.php in src/
Plugin/ BusinessRulesItemPluginBase.php - BusinessRulesItemPluginInterface.php in src/
Plugin/ BusinessRulesItemPluginInterface.php - BusinessRulesProcessor.php in src/
Util/ BusinessRulesProcessor.php - DataComparison.php in src/
Plugin/ BusinessRulesCondition/ DataComparison.php
File
- src/
VariablesSet.php, line 10
Namespace
Drupal\business_rulesView source
class VariablesSet {
/**
* The variables storage.
*
* @var array
*/
protected $variables = [];
/**
* Append the variable to the array.
*
* @param \Drupal\business_rules\VariableObject $variable
* The variable set.
*/
public function append(VariableObject $variable) {
$this->variables[$variable
->getId()] = $variable;
}
/**
* Replace the content of one variable.
*
* @param string $variable_id
* The variable id.
* @param mixed $value
* The variable value.
*
* @internal param \Drupal\business_rules\VariableObject $variable
*/
public function replaceValue($variable_id, $value) {
if ($this
->count()) {
foreach ($this->variables as $key => $var) {
if ($var
->getId() == $variable_id) {
$this->variables[$key]
->setValue($value);
}
}
}
}
/**
* Number of variables inside the set.
*
* @return int
* The number of variables on the variable set.
*/
public function count() {
return count($this->variables);
}
/**
* Remove one variable from the variables set.
*
* @param string $variable_id
* The variable id.
*/
public function remove($variable_id) {
if ($this
->count()) {
foreach ($this->variables as $key => $variable) {
if ($variable
->getId() == $variable_id) {
unset($this->variables[$key]);
}
}
}
}
/**
* Return all variables.
*
* @return array
* Array of variables.
*/
public function getVariables() {
return $this->variables;
}
/**
* Return variable by id.
*
* @param string $variable_id
* The variable id.
*
* @return VariableObject|null
* The variable object or null if variable id not exists.
*/
public function getVariable($variable_id) {
if ($this
->count()) {
foreach ($this->variables as $variable) {
if ($variable
->getId() == $variable_id) {
return $variable;
}
}
}
return NULL;
}
/**
* Return the variables ids.
*
* @return array
* Array of variables ids.
*/
public function getVariablesIds() {
$ids = [];
if ($this
->count()) {
foreach ($this->variables as $variable) {
$ids[] = $variable
->getId();
}
}
return $ids;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
VariablesSet:: |
protected | property | The variables storage. | |
VariablesSet:: |
public | function | Append the variable to the array. | |
VariablesSet:: |
public | function | Number of variables inside the set. | |
VariablesSet:: |
public | function | Return variable by id. | |
VariablesSet:: |
public | function | Return all variables. | |
VariablesSet:: |
public | function | Return the variables ids. | |
VariablesSet:: |
public | function | Remove one variable from the variables set. | |
VariablesSet:: |
public | function | Replace the content of one variable. |