frostealth / php-data-storage
简单的PHP数据存储
2.1.0
2015-11-11 08:46 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: 4.2.*
This package is not auto-updated.
Last update: 2024-09-14 16:24:05 UTC
README
简单的PHP数据存储。
安装
运行Composer命令来安装最新稳定版本
composer require frostealth/php-data-storage @stable
使用方法
$storage = new frostealth\storage\Data(); // or new frostealth\storage\Data($array); $storage->set('login', 'example@example.com'); // ... if ($storage->has('login')) { $login = $storage->get('login'); $storage->remove('login'); } // or with default value if ($storage->get('login', false)) { $login = $storage->get('login'); $storage->remove('login'); } // ... $storage->clear(); // clear all values
使用点符号与数组进行交互
$storage = new frostealth\storage\ArrayData(); $storage->set('params', ['method' => 'post', 'url' => 'http://example.com/']); $url = $storage->get('params.url'); // 'http://example.com/' $storage->set('params.method', 'get'); $method = $storage->get('params.method'); // 'get' $params = $storage->get('params'); // ['method' => 'get', 'url' => 'http://example.com/'] $storage->set('options.my_option', 'value'); $options = $storage->get('options'); // ['my_option' => 'value']
依赖注入
use frostealth\storage\DataInterface; class MyClass { /** * @var DataInterface */ protected $data; /** * @param DataInterface $data */ public function __construct(DataInterface $data) { $this->data = $data; } }
许可证
MIT许可证(MIT)。更多信息请参阅LICENSE.md。