Simple PHP Valuestore Class

If you’re looking for a simple Value Store (you know: key-value) Freek and Jolita over at spatie has whipped up a simple class that does this for you.

$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

Would love to see this actually get split up into an (in memory) Valuestore and PersistentValue class though … not everything needs to be saved on disk 😉

Easily store some loose values →

Reminds me of an even simpler DataStore class I once wrote. PSR-6 didn’t even exist back then, so I went ahead and chose to use PHP’s Magic Functions in it.


Faker is a PHP library that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.

Uses formatters for the different types of data (e.g. names, addresses, etc) you want to generate

$faker = Faker\Factory::create();

for ($i=0; $i < 10; $i++) { 
  echo $faker->name, "\n";
  // Adaline Reichel
  // Dr. Santa Prosacco DVM
  // Noemy Vandervort V
  // Lexi O'Conner
  // Gracie Weber
  // Roscoe Johns
  // Emmett Lebsack
  // Keegan Thiel
  // Wellington Koelpin II
  // Ms. Karley Kiehn V

Faker →

(via @oemebamo)

Accessing data saved in the class property of DOM-elements with jQuery

Use of this plugin is not recommended anymore. Use data-* attributes and $ instead. This was a possible solution, a long time ago.

A few weeks ago former colleague Jurriaan wrote a PrototypeJS extension to accessing data stored within classes of HTML elements. Basically it comes down to assigning extra classes (classes such as gender_male for example, which represent a property and a value) on an element, which you then read/write via Jurriaan’s extension. As this way of assigning data is a technique I’ve been using too, I took the liberty of writing a jQuery blend of his script.

Continue reading “Accessing data saved in the class property of DOM-elements with jQuery”