PHP code example of mnapoli / blackbox

1. Go to this page and download the library: Download mnapoli/blackbox 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/ */

    

mnapoli / blackbox example snippets


namespace BlackBox;

interface Storage extends Traversable
{
    public function get(string $id);
    public function set(string $id, $data) : void;
    public function remove(string $id) : void;
}

$storage->set('foo', 'Hello World!');

echo $storage->get('foo'); // Hello World!

foreach ($storage as $key => $item) {
    echo $key; // foo
    echo $item; // Hello World!
}

// Encode the data in JSON
$storage = new JsonEncoder(
    // Store data in files
    new DirectoryStorage('some/directory')
);

$storage->set('foo', [
    'name' => 'Lebowski',
]);
// will encode it in JSON
// then will store it into a file

$data = $storage->get('foo');
// will read from the file
// then will decode the JSON

echo $data['name']; // Lebowski