arifmahmudrana / context
PHP 单一上下文。键值存储在当前上下文中。
v1.0.0
2017-02-05 21:08 UTC
This package is not auto-updated.
Last update: 2024-09-23 15:33:02 UTC
README
这实际上只是在当前上下文中的键值存储。你可以存储值,在其他地方你可以通过它的键来检索值。
用法
步骤 1: 通过 Composer 安装
composer require arifmahmudrana/context
这样就完成了。
示例
设置值
use ArifMahmudRana\Context\ContextContainer;
ContextContainer::set('user', User::find(1))//Save user Returns true
获取值
use ArifMahmudRana\Context\ContextContainer;
ContextContainer::get('user')//Get user
检查值是否存在
use ArifMahmudRana\Context\ContextContainer;
ContextContainer::has('user')//Return true
所有值
use ArifMahmudRana\Context\ContextContainer;
ContextContainer::all()//Returns key value ['user' => User Object] default empty array
移除值
use ArifMahmudRana\Context\ContextContainer;
ContextContainer::remove('user')//Returns true removes the key
重要
- 如果你尝试实例化此类,将会抛出
CannotInstantiateClassExceptions异常 - 你可以使用字符串作为键,否则将会抛出
\InvalidArgumentException异常
测试
运行测试
./vendor/bin/phpunit //run phpunit
贡献
欢迎所有贡献,对于任何错误、问题或合并请求,请参考 CONTRIBUTING.md
许可证
在 MIT 许可证下发布,请参阅 LICENSE。