Skip to content

Commit

Permalink
Type Safe property setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Oct 9, 2024
1 parent d26503d commit ad37c9d
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/Ease/Molecule.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getObjectName()
/**
* Set up one of the properties by 1) array 2) ENV 3) Constant.
*
* @param array $options array of given availble properties
* @param array $options array of given available properties
* @param string $name name of property to set up
* @param string $constant load default property value from constant / ENV
*/
Expand All @@ -76,16 +76,37 @@ public function setupProperty($options, $name, $constant = ''): void
} elseif (\array_key_exists($constant, $options)) {
$this->{$name} = $options[$constant];
} else { // If No values specified we must use constants or environment
if ($constant && (empty(Functions::cfg($constant)) === false)) {
$this->{$name} = Functions::cfg($constant);
$value = Functions::cfg($constant);
if ($constant && (empty($value) === false)) {
switch (gettype($this->{$name})) {
case 'boolean':
switch (strtolower($value)) {
case 'true':
$this->{$name} = true;
break;
case 'false':
$this->{$name} = false;
break;
default:
$this->{$name} = (bool)Functions::cfg($constant);
break;
}
break;
case 'string':
$this->{$name} = (string)Functions::cfg($constant);
break;
default:
$this->{$name} = Functions::cfg($constant);
break;
}
}
}
}

/**
* Set up one of the properties by 1) array 2) ENV 3) Constant to int value.
*
* @param array $options array of given availble properties
* @param array $options array of given available properties
* @param string $name name of property to set up
* @param string $constant load default property value from constant / ENV
*/
Expand Down

0 comments on commit ad37c9d

Please sign in to comment.