2017 © Pedro Peláez
 

library valuestore

Easily store some values. Now supports PHP 5

image

kigamba/valuestore

Easily store some values. Now supports PHP 5

  • Friday, August 18, 2017
  • by Kigamba
  • Repository
  • 0 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Easily store some loose values

Latest Version on Packagist Software License Build Status Quality Score StyleCI Total Downloads, (*1)

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

Support >= PHP 5.0 The parent library supports PHP >= 7.0 only, (*3)

It can be used like this:, (*4)

$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 section of this readme to learn the other methods., (*5)

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website., (*6)

Postcardware

You're free to use this package (it's MIT-licensed), 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., (*7)

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium., (*8)

The best postcards will get published on the open source page on our website., (*9)

Installation

You can install the package via composer:, (*10)

``` bash composer require kigamba/valuestore, (*11)


## Usage To create a Valuestore use the `make`-method. ```php $valuestore = Valuestore::make($pathToFile);

All values will be saved as json in the given file., (*12)

When there are no values stored, the file will be deleted., (*13)

You can call the following methods on the Valuestore, (*14)

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)

Changelog

Please see CHANGELOG for more information what has changed recently., (*15)

Testing

bash $ composer test, (*16)

Contributing

Please see CONTRIBUTING for details., (*17)

Security

If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker., (*18)

Credits

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., (*19)

License

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

The Versions

18/08 2017

dev-master

9999999-dev https://github.com/spatie/valuestore

Easily store some values. Now supports PHP 5

  Sources   Download

MIT

The Requires

  • php >=5.0

 

The Development Requires

json spatie valuestore

18/08 2017

v1.1.1

1.1.1.0 https://github.com/spatie/valuestore

Easily store some values. Now supports PHP 5

  Sources   Download

MIT

The Requires

  • php >=5.0

 

The Development Requires

json spatie valuestore

20/01 2017

1.1.0

1.1.0.0 https://github.com/spatie/valuestore

Easily store some values

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

json spatie valuestore