divengine/laze
Composer 安装命令:
composer require divengine/laze
包简介
Div PHP Laze
关键字:
README 文档
README
laze is a PHP library designed for defining lazy evaluation. Values are set as closures and only materialize upon first access, ensuring efficient and controlled initialization. Once a closure function is evaluated, it becomes immutable and cannot be redefined as a different value. However, it can be redefined as a closure until it’s accessed, at which point it transforms into a non-closure value.
Laze provides lazy immutable values for PHP. You define a key with a closure, and the value is computed on first read and then cached.
Requirements
- PHP 8.0 or higher
Installation
composer require divengine/laze
Quick start
<?php require 'vendor/autoload.php'; use divengine\laze; laze::define('APP_NAME', fn () => 'Laze Demo'); echo laze::read('APP_NAME');
Core API
laze::define($key, $callable)registers a lazy value.laze::read($key)evaluates once and returns the stored value.laze::defined($key)checks if a key exists.laze::evaluated($key)checks if a key was evaluated (throws if undefined).laze::constraint($name, $checker)validates values on evaluation.
Redefinition rules
You can redefine a value before it is evaluated. After the first read, the
value becomes immutable and further define calls are ignored.
<?php laze::define('FOO', fn () => 1); laze::define('FOO', fn () => 2); echo laze::read('FOO'); // 2 laze::define('FOO', fn () => 3); echo laze::read('FOO'); // still 2
Constraints
<?php laze::constraint( 'APP_PORT must be an int', fn ($key, $value) => $key === 'APP_PORT' ? is_int($value) : true ); laze::define('APP_PORT', fn () => 8080);
Constraints run when a value is evaluated. If a constraint returns false,
read throws an exception.
Testing tips
Laze stores state statically. You can reset it between tests with reflection:
<?php use divengine\laze; $reflection = new ReflectionClass(laze::class); $store = $reflection->getProperty('store'); $store->setAccessible(true); $store->setValue(null, []); $constraints = $reflection->getProperty('constraints'); $constraints->setAccessible(true); $constraints->setValue(null, []); $evaluated = $reflection->getProperty('evaluated'); $evaluated->setAccessible(true); $evaluated->setValue(null, []);
Or run PHPUnit with process isolation:
vendor/bin/phpunit --process-isolation
Docs
See docs/README.md for guides and FAQ.
License
This project is licensed under the GNU General Public License. See LICENSE.
Contributing
Contributions are welcome. Please open an issue or submit a pull request.
About
Laze is developed and maintained by Divengine Software Solutions.
divengine/laze 适用场景与选型建议
divengine/laze 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「dependency injection」 「closures」 「constants」 「lazy loading」 「object-oriented」 「constraints」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 divengine/laze 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 divengine/laze 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 divengine/laze 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An implementation of the Closure Tables pattern for Eloquent.
Configurable DI for the ZF service manager. Modeled after Symfony 2's DI config files.
A fast and intuitive dependency injection container.
PHP Active Record for MySQL. Connects to the your database and generates the Object Relational Mapping. Built in Database Query Processor for custom queries. Ability to use closures to process rows
Configurable DI for the ZF service manager. Modeled after Symfony 2's DI config files.
Dependency injection container for the Monolith framework.
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2024-08-13