Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Update Environment.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Radovan Kepák committed Aug 12, 2021
1 parent 532da37 commit 8d67b40
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class Environment
{
public const STRING = 'string';
public const BOOL = 'bool';
public const BOOLEAN = 'boolean';
public const INT = 'int';
public const INTEGER = 'integer';
public const FLOAT = 'float';

public function __construct(
Expand All @@ -25,8 +27,8 @@ public static function bool(string $name, bool $default = false): bool
private static function castIt(?string $value, string $cast): null|string|bool|int|float
{
return ($value !== null) ? match ($cast) {
self::BOOL => !($value === 'false' || !$value),
self::INT => (int)$value,
self::BOOL, self::BOOLEAN => !($value === 'false' || !$value),
self::INT, self::INTEGER => (int)$value,
self::FLOAT => (float)$value,
default => $value,
} : null;
Expand Down Expand Up @@ -60,6 +62,6 @@ public function __toString(): string

public function get(string $cast = self::STRING): string|bool|int|float
{
return self::castIt(self::env($this->name) ?? $this->default, $cast) ?? '';
return self::castIt(self::env($this->name) ?? $this->default, strtolower($cast)) ?? '';
}
}

0 comments on commit 8d67b40

Please sign in to comment.