kigamba / valuestore
轻松存储一些值。现在支持 PHP 5
v1.1.1
2017-08-18 05:22 UTC
Requires
- php: >=5.0
Requires (Dev)
- phpunit/phpunit: ^5.0
This package is not auto-updated.
Last update: 2024-09-18 22:05:49 UTC
README
此包使得存储和检索一些值变得简单。存储的值以 json 格式保存在文件中。
支持 >= PHP 5.0 父级库仅支持 PHP >= 7.0
它可以这样使用
$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 who's keys start with "somekey" $valuestore->increment('number'); // $valuestore->get('key') will return 1 $valuestore->increment('number'); // $valuestore->get('key') will return 2 $valuestore->increment('number', 3); // $valuestore->get('key') 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 impements Countable count($valuestore); // Returns 0 $valuestore->put('key', 'value'); count($valuestore); // Returns 1
阅读此 readme 的 使用 部分,了解其他方法。
Spatie 是一家位于比利时的安特卫普的网页设计公司。您可以在我们的网站上找到所有开源项目的概述 这里。
Postcardware
您可以使用此包(它是 MIT 许可的),但如果它进入您的生产环境,您需要从您的家乡给我们寄一张明信片,说明您正在使用我们的哪些包。
我们的地址是:Spatie,Samberstraat 69D,2060 安特卫普,比利时。
最好的明信片将被发布在我们的网站上开源页面。
安装
您可以通过 composer 安装此包
composer require kigamba/valuestore
使用方法
要创建 Valuestore,请使用 make
方法。
$valuestore = Valuestore::make($pathToFile);
所有值都将保存为给定的文件中的 json 格式。
如果没有存储值,则文件将被删除。
您可以在 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 in an array. * * @param string $name * @param $prependValue * * @return $this * public function push(string $name, $prependValue)
变更日志
请参阅 变更日志 以获取有关最近更改的更多信息。
测试
$ composer test
贡献
有关详细信息,请参阅 CONTRIBUTING。
安全性
如果您发现任何安全相关的问题,请通过电子邮件 freek@spatie.be 而不是使用问题跟踪器。
致谢
关于 Spatie
Spatie 是一家位于比利时的安特卫普的网页设计公司。您可以在我们的网站上找到所有开源项目的概述 这里。
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。