PHP code example of andrey-tech / data-storage-php

1. Go to this page and download the library: Download andrey-tech/data-storage-php 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/ */

    

andrey-tech / data-storage-php example snippets


use \App\DataStorage\FileStorage;
use \App\DataStorage\FileStorageException;
use \App\AppException;

try {

    $storage = new FileStorage('storage-1');

    $storage->set([
        'manager_id' => 2369305,
        'numbers'    => [ 4, 8, 15, 16, 23, 42 ],
        'error_time' => null,
        'user_ids'   => [ 'alex' => 23, 'bob' => 2 ],
        'months'     => [ '0' => [ 1, 4 ], '1' => [  1, 2, 5  ] ]
    ]);
    $storage->set([ 'group_id' => 94824 ]);

    var_dump($storage->hasKey('numbers'));

    print_r($storage->get('numbers'));
    print_r($storage->get([ 'manager_id', 'user_ids' ]));

    $storage->delete('group_id');

    $storage->update(
        $set = [ 'error_time' => 1596124230 ],
        $delete = [ 'manager_id' ]
    );

    print_r($storage->load());

} catch (FileStorageException $e) {
    printf('Ошибка (%d): %s' . PHP_EOL, $e->getCode(), $e->getMessage());
} catch (AppException $e) {
    printf('Ошибка (%d): %s' . PHP_EOL, $e->getCode(), $e->getMessage());
}

"andrey-tech/data-storage-php"