spatie/valuestore
Composer 安装命令:
composer require spatie/valuestore
包简介
Easily store some values
关键字:
README 文档
README
This package makes it easy to store and retrieve some loose values. Stored values are saved as a json file.
It can be used like this:
use Spatie\Valuestore\Valuestore; $valuestore = Valuestore::make($pathToFile); $valuestore->put('key', 'value'); $valuestore->get('key'); // Returns 'value' $valuestore->has('key'); // Returns true // Specify a default value for when the specified key does not exist $valuestore->get('non existing key', 'default') // Returns 'default' $valuestore->put('anotherKey', 'anotherValue'); // Put multiple items in one go $valuestore->put(['ringo' => 'drums', 'paul' => 'bass']); $valuestore->all(); // Returns an array with all items $valuestore->forget('key'); // Removes the item $valuestore->flush(); // Empty the entire valuestore $valuestore->flushStartingWith('somekey'); // remove all items whose keys start with "somekey" $valuestore->increment('number'); // $valuestore->get('number') will return 1 $valuestore->increment('number'); // $valuestore->get('number') will return 2 $valuestore->increment('number', 3); // $valuestore->get('number') will return 5 // Valuestore implements ArrayAccess $valuestore['key'] = 'value'; $valuestore['key']; // Returns 'value' isset($valuestore['key']); // Return true unset($valuestore['key']); // Equivalent to removing the value // Valuestore implements Countable count($valuestore); // Returns 0 $valuestore->put('key', 'value'); count($valuestore); // Returns 1
Read the usage section of this readme to learn about the other methods.
In this post on Laravel News, Tim MacDonald shares how you can use this package to power a settings function.
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
composer require spatie/valuestore
Usage
To create a Valuestore use the make method.
$valuestore = Valuestore::make($pathToFile);
You can also pass some values as a second argument. These will be added to the valuestore using the put method.
$valuestore = Valuestore::make($pathToFile, ['key' => 'value']);
All values will be saved as json in the given file.
When there are no values stored, the file will be deleted.
You can call the following methods on the Valuestore
put
/** * Put a value in the store. * * @param string|array $name * @param string|int|null $value * * @return $this */ public function put($name, $value = null)
get
/** * Get a value from the store. * * @param string $name * * @return null|string */ public function get(string $name)
has
/* * Determine if the store has a value for the given name. */ public function has(string $name) : bool
all
/** * Get all values from the store. * * @return array */ public function all() : array
allStartingWith
/** * Get all values from the store which keys start with the given string. * * @param string $startingWith * * @return array */ public function allStartingWith(string $startingWith = '') : array
forget
/** * Forget a value from the store. * * @param string $key * * @return $this */ public function forget(string $key)
flush
/** * Flush all values from the store. * * @return $this */ public function flush()
flushStartingWith
/** * Flush all values from the store which keys start with the specified value. * * @param string $startingWith * * @return $this */ public function flushStartingWith(string $startingWith)
pull
/** * Get and forget a value from the store. * * @param string $name * * @return null|string */ public function pull(string $name)
increment
/** * Increment a value from the store. * * @param string $name * @param int $by * * @return int|null|string */ public function increment(string $name, int $by = 1)
decrement
/** * Decrement a value from the store. * * @param string $name * @param int $by * * @return int|null|string */ public function decrement(string $name, int $by = 1)
push
/** * Push a new value into an array. * * @param string $name * @param $pushValue * * @return $this */ public function push(string $name, $pushValue)
prepend
/** * Prepend a new value into an array. * * @param string $name * @param $prependValue * * @return $this */ public function prepend(string $name, $prependValue)
count
/** * Count elements. * * @return int */ public function count()
Changelog
Please see CHANGELOG for more information about what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you've found a bug regarding security please mail security@spatie.be instead of using the issue tracker.
Postcardware
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.
We publish all received postcards on our company website.
Credits
License
The MIT License (MIT). Please see License File for more information.
spatie/valuestore 适用场景与选型建议
spatie/valuestore 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.11M 次下载、GitHub Stars 达 766, 最近一次更新时间为 2016 年 04 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「spatie」 「valuestore」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spatie/valuestore 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spatie/valuestore 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spatie/valuestore 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
Receive webhooks in Laravel apps
Easily store some values
An extension of spatie/valuestore with in-memory caching.
统计信息
- 总下载量: 1.11M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 772
- 点击次数: 24
- 依赖项目数: 49
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-05