frostealth / php-data-storage
Simple PHP Data Storage
Installs: 12 248
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: 4.2.*
This package is not auto-updated.
Last update: 2024-12-21 17:58:09 UTC
README
Simple PHP Data Storage.
Installation
Run the Composer command to install the latest stable version:
composer require frostealth/php-data-storage @stable
Usage
$storage = new frostealth\storage\Data(); // or new frostealth\storage\Data($array); $storage->set('login', 'example@example.com'); // ... if ($storage->has('login')) { $login = $storage->get('login'); $storage->remove('login'); } // or with default value if ($storage->get('login', false)) { $login = $storage->get('login'); $storage->remove('login'); } // ... $storage->clear(); // clear all values
Working with arrays using "dot" notation
$storage = new frostealth\storage\ArrayData(); $storage->set('params', ['method' => 'post', 'url' => 'http://example.com/']); $url = $storage->get('params.url'); // 'http://example.com/' $storage->set('params.method', 'get'); $method = $storage->get('params.method'); // 'get' $params = $storage->get('params'); // ['method' => 'get', 'url' => 'http://example.com/'] $storage->set('options.my_option', 'value'); $options = $storage->get('options'); // ['my_option' => 'value']
Dependency Injection
use frostealth\storage\DataInterface; class MyClass { /** * @var DataInterface */ protected $data; /** * @param DataInterface $data */ public function __construct(DataInterface $data) { $this->data = $data; } }
License
The MIT License (MIT). See LICENSE.md for more information.