PHP code example of frostealth / php-data-storage

1. Go to this page and download the library: Download frostealth/php-data-storage library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

frostealth / php-data-storage example snippets


$storage = new frostealth\storage\Data(); // or new frostealth\storage\Data($array);
$storage->set('login', '[email protected]');

// ...

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

$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']


use frostealth\storage\DataInterface;

class MyClass
{
    /**
     * @var DataInterface
     */
    protected $data;

    /**
     * @param DataInterface $data
     */
    public function __construct(DataInterface $data)
    {
        $this->data = $data;
    }
}