Valuestore

轻松存储一些值。(Easily store some values)

Github星跟蹤圖

Easily store some loose values

Latest Version on Packagist
Software License
Build Status
Quality Score
StyleCI
Total Downloads

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.

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

主要指標

概覽
名稱與所有者spatie/valuestore
主編程語言PHP
編程語言PHP (語言數: 1)
平台BSD, Cross-platform, Linux, Mac, Solaris, Windows
許可證MIT License
所有者活动
創建於2016-03-15 14:47:39
推送於2025-02-14 13:02:06
最后一次提交
發布數13
最新版本名稱1.3.3 (發布於 )
第一版名稱0.0.1 (發布於 )
用户参与
星數761
關注者數12
派生數47
提交數139
已啟用問題?
問題數11
打開的問題數0
拉請求數24
打開的拉請求數0
關閉的拉請求數13
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?