Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
V

valuestore

> 编程语言
Open source

Easily store some values

768 stars0 likes1 views
WebsiteGitHub

About

Easily store some values

Easily store some loose values

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:

…

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:

bash
composer require spatie/valuestore

Usage

To create a Valuestore use the make method.

php
$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.

php
$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

php
/**
 * Put a value in the store.
 *
 * @param string|array $name
 * @param string|int|null $value
 * 
 * @return $this
 */
public function put($name, $value = null)

get

php
/**
 * Get a value from the store.
 *
 * @param string $name
 *
 * @return null|string
 */
public function get(string $name)

has

php
/*
 * Determine if the store has a value for the given name.
 */
public function has(string $name) : bool

all

php
/**
 * Get all values from the store.
 *
 * @return array
 */
public function all() : array

allStartingWith

php
/**
 * 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

php
/**
 * Forget a value from the store.
 *
 * @param string $key
 *
 * @return $this
 */
public function forget(string $key)

flush

php
/**
 * Flush all values from the store.
 *
 * @return $this
 */
 public function flush()

flushStartingWith

php
/**
 * Flush all values from the store which keys start with the specified value.
 *
 * @param string $startingWith
 *
 * @return $this
 */
 public function flushStartingWith(string $startingWith)

pull

php
/**
 * Get and forget a value from the store.
 *
 * @param string $name 
 *
 * @return null|string
 */
public function pull(string $name)

increment

php
/**
 * 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

php
/**
 * 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

php
/**
 * Push a new value into an array.
 *
 * @param string $name
 * @param $pushValue
 *
 * @return $this
 */
public function push(string $name, $pushValue)

prepend

php
/**
 * Prepend a new value into an array.
 *
 * @param string $name
 * @param $prependValue
 *
 * @return $this
 */
public function prepend(string $name, $prependValue)

count

php
/**
 * Count elements.
 *
 * @return int
 */
public function count()

Changelog

Please see CHANGELOG for more information about what has changed recently.

Testing

bash
$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you've found a bug regarding security please mail [email protected] 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

  • Freek Van der Herten
  • Jolita Grazyte
  • All Contributors

License

The MIT License (MIT). Please see License File for more information.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPcachejsonphpvaluestore

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言