From 6dd8849e1f12ad3338129833af1653a8c8924418 Mon Sep 17 00:00:00 2001 From: rafageist Date: Wed, 14 Aug 2024 09:23:49 -0300 Subject: [PATCH 1/2] Change concept from constant to immutable value --- src/laze.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/laze.php b/src/laze.php index dbe44f2..1ae5828 100644 --- a/src/laze.php +++ b/src/laze.php @@ -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. * @@ -41,7 +41,7 @@ class laze private static string $__version = '1.1.0'; /** - * Store for lazy constants. + * Store for lazy immutable values. * @var array */ private static array $store = []; @@ -53,7 +53,7 @@ class laze private static array $constraints = []; /** - * Map of evaluated lazy constants. + * Map of evaluated lazy immutable values. * @var array */ private static array $evaluated = []; @@ -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 @@ -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 @@ -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 @@ -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 @@ -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"); } } From 0e4af7fe022bbd81dfc84b88d2cfeb2dddfc3bfd Mon Sep 17 00:00:00 2001 From: rafageist Date: Wed, 14 Aug 2024 09:27:31 -0300 Subject: [PATCH 2/2] fix tests --- tests/BasicTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/BasicTest.php b/tests/BasicTest.php index a470d14..08b49fa 100644 --- a/tests/BasicTest.php +++ b/tests/BasicTest.php @@ -9,7 +9,7 @@ class BasicTest extends TestCase { - public function testScalarConstant(): void + public function testScalarImmutable(): void { laze::define('FOO', fn() => 42); @@ -88,7 +88,7 @@ public function testConstraintFailure(): void laze::define('QUUX', fn() => 42); $this->expectException(\Exception::class); - $this->expectExceptionMessage("Constraint 'Must be a string' failed for lazy constant: QUUX"); + $this->expectExceptionMessage("Constraint 'Must be a string' failed for lazy immutable value: QUUX"); laze::read('QUUX'); }