PHPackages                             kigamba/valuestore - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. kigamba/valuestore

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

kigamba/valuestore
==================

Easily store some values. Now supports PHP 5

v1.1.1(8y ago)017MITPHPPHP &gt;=5.0

Since Jul 28Pushed 8y agoCompare

[ Source](https://github.com/Kigamba/valuestore)[ Packagist](https://packagist.org/packages/kigamba/valuestore)[ Docs](https://github.com/spatie/valuestore)[ RSS](/packages/kigamba-valuestore/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Easily store some loose values
==============================

[](#easily-store-some-loose-values)

[![Latest Version on Packagist](https://camo.githubusercontent.com/973d6a7b6b9ac8fd4301f89efcd877e7eca07830d31357ea688261e6432d12bf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f76616c756573746f72652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/valuestore)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/8de31bd217e0cb2ae3c5c53f1e67e45cdfa4399e926676376db724a8b5f2222d/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7370617469652f76616c756573746f72652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/spatie/valuestore)[![Quality Score](https://camo.githubusercontent.com/66b5f92f4f4cc39b56aaeb85f550bec2c3881aef619e2784493e0659bb48e044/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f76616c756573746f72652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/valuestore)[![StyleCI](https://camo.githubusercontent.com/cb92cd6a94886f08bab7e8cb6fce55c3a3f02a7aafa6f8dbda4c70b15c29f415/68747470733a2f2f7374796c6563692e696f2f7265706f732f35333935323737362f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/53952776)[![Total Downloads](https://camo.githubusercontent.com/f4a81f7c24c5bc66d06fe25a232955361b64eea606b413f3204da30d8ea42132/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f76616c756573746f72652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/valuestore)

This package makes it easy to store and retrieve some values. Stores values are saved as a json in a file.

Support &gt;= PHP 5.0 The parent library supports PHP &gt;= 7.0 only

It can be used like this:

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

Read the [usage](#usage) section of this readme to learn the other methods.

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Postcardware
------------

[](#postcardware)

You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

The best postcards will get published on the open source page on our website.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require kigamba/valuestore
```

Usage
-----

[](#usage)

To create a Valuestore use the `make`-method.

```
$valuestore = Valuestore::make($pathToFile);
```

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)

```
/**
 * 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)

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

### has

[](#has)

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

### all

[](#all)

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

### allStartingWith

[](#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)

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

### flush

[](#flush)

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

### flushStartingWith

[](#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

[](#pull)

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

### increment

[](#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)

```
/**
 * 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)

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

prepend
-------

[](#prepend)

```
**
* Prepend a new value in an array.
*
* @param string $name
* @param $prependValue
*
* @return $this
*
public function push(string $name, $prependValue)
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [Jolita Grazyte](https://github.com/JolitaGrazyte)
- [All Contributors](../../contributors)

About Spatie
------------

[](#about-spatie)

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~20 days

Total

2

Last Release

3238d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/23360506?v=4)[Kigamba](/maintainers/Kigamba)[@Kigamba](https://github.com/Kigamba)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (49 commits)")[![Kigamba](https://avatars.githubusercontent.com/u/23360506?v=4)](https://github.com/Kigamba "Kigamba (3 commits)")[![apiv-thomas](https://avatars.githubusercontent.com/u/53090992?v=4)](https://github.com/apiv-thomas "apiv-thomas (1 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (1 commits)")

---

Tags

jsonspatievaluestore

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kigamba-valuestore/health.svg)

```
[![Health](https://phpackages.com/badges/kigamba-valuestore/health.svg)](https://phpackages.com/packages/kigamba-valuestore)
```

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k328.4M737](/packages/justinrainbow-json-schema)[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k493.5M159](/packages/mtdowling-jmespathphp)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k139.8M905](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k91.4M664](/packages/jms-serializer-bundle)[spatie/laravel-sitemap

Create and generate sitemaps with ease

2.6k15.9M140](/packages/spatie-laravel-sitemap)[spatie/valuestore

Easily store some values

7691.1M55](/packages/spatie-valuestore)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
