Pocket
Little storing services, (*1)
, (*2)
This project aims to provide quick and easy in-file persisting capabilities., (*3)
Usage
The projec is composed by 3 main classes:, (*4)
-
ValuePocket: This class stores just a single value of any type. It requires the path of the file where
the data will be persisted. Optionally, you can pass a default value that will be returned if nothing
has been stored yet. For example:, (*5)
use carlosV2\Pocket\ValuePocket;
$pocket = new ValuePocket('/path/to/the/file', 42);
$pocket->load(); // Returns: 42
$pocket->save(4);
$pocket->load(); // Returns: 4
-
CollectionPocket: This class stores a collection of values of any type. It requries the path of the
file where the data will be persisted. For example:, (*6)
use carlosV2\Pocket\CollectionPocket;
$pocket = new CollectionPocket('/path/to/the/file');
$pocket->add('a');
$pocket->add(1);
$pocket->add(true);
$pocket->getValues(); // Returns: ['a', 1, true]
-
IndexedPocket: This class stores an indexed collection of values of any type. It requires the path of
the file where the data will be persisted. For example:, (*7)
use carlosV2\Pocket\IndexedPocket;
$pocket = new IndexedPocket('/path/to/the/file');
$pocket->add('key1', 'a');
$pocket->add('key2', 1);
$pocket->add('key3', true);
$pocket->getValues(); // Returns: ['a', 1, true]
$pocket->getKeys(); // Returns: ['key1', 'key2', 'key3']
Additionally, a manager class is provided so that a single folder path is needed. The files management is
carried out by this class. Additionally, it can perform maintenance task. For example:, (*8)
use carlosV2\Pocket\PocketManager;
$manager = new PocketManager('/path/to/the/folder/');
$manager->getValuePocket(); // Returns an instance of ValuePocket
$manager->getCollectionPocket(); // Returns an instance of CollectionPocket
$manager->getIndexedPocket(); // Returns an instance of IndexedPocket
$manager->clear(); // Removes any file inside /path/to/the/folder/ folder
Install
Open a command console, enter your project directory and execute the
following command to download the latest stable version of this project:, (*9)
$ composer require --dev carlosv2/pocket
This command requires you to have Composer installed globally, as explained
in the installation chapter
of the Composer documentation., (*10)