Skip to content

Commit

Permalink
Change concept from constant to immutable value
Browse files Browse the repository at this point in the history
  • Loading branch information
rafageist committed Aug 14, 2024
1 parent be8ba20 commit 6dd8849
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/laze.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* [[]] Div PHP Laze
*
* A PHP library for defining lazy constants. Values are set as closures
* A PHP library for defining lazy inmutable values. Values are set as closures
* and only materialize upon first access, ensuring efficient and controlled
* initialization.
*
Expand Down Expand Up @@ -41,7 +41,7 @@ class laze
private static string $__version = '1.1.0';

/**
* Store for lazy constants.
* Store for lazy immutable values.
* @var array<string, mixed>
*/
private static array $store = [];
Expand All @@ -53,7 +53,7 @@ class laze
private static array $constraints = [];

/**
* Map of evaluated lazy constants.
* Map of evaluated lazy immutable values.
* @var array<bool>
*/
private static array $evaluated = [];
Expand All @@ -69,7 +69,7 @@ public static function getVersion()
}

/**
* Check if a lazy constant is defined.
* Check if a lazy immutable value is defined.
*
* @param string $key
* @return bool
Expand All @@ -80,20 +80,20 @@ public static function defined(string $key): bool
}

/**
* Check if a lazy constant has been evaluated.
* Check if a lazy immutable value has been evaluated.
*
* @param string $key
* @return bool
*/
public static function evaluated(string $key): bool
{
self::defined($key) or throw new \Exception("Undefined lazy constant: $key");
self::defined($key) or throw new \Exception("Undefined lazy immutable value: $key");

return self::$evaluated[$key];
}

/**
* Define a constraint for a lazy constant.
* Define a constraint for a lazy immutable value.
*
* @param string $name
* @param callable $checker
Expand All @@ -105,7 +105,7 @@ public static function constraint($name, callable $checker): void
}

/**
* Define a lazy constant as a closure.
* Define a lazy immutable value as a closure.
*
* @param string $key
* @param callable $value
Expand All @@ -120,7 +120,7 @@ public static function define(string $key, callable $value): void
}

/**
* Read the value of a lazy constant, evaluating the closure if needed.
* Read the value of a lazy immutable value, evaluating the closure if needed.
*
* @param string $key
* @return mixed
Expand All @@ -133,7 +133,7 @@ public static function read(string $key): mixed
foreach (self::$constraints as $constraint) {
$pass = $constraint[1]($key, $value);
if (!$pass) {
throw new \Exception("Constraint '{$constraint[0]}' failed for lazy constant: $key");
throw new \Exception("Constraint '{$constraint[0]}' failed for lazy immutable value: $key");
}
}

Expand Down

0 comments on commit 6dd8849

Please sign in to comment.