PHP code example of morphable / simple-container

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

    

morphable / simple-container example snippets




use \Morphable\SimpleContainer;

$container = new SimpleContainer();
$container->add('item', new MyClass());
$container->get('item');
$container->exists('item');
$container->update('item', 'something else');
$container->delete('item');

// if you don't know whether the item exists, every method except exists throws an exception

try {
    $container->get('item that does not exists');
} catch (\Morphable\SimpleContainer\Exception\InstanceNotFound $e) {
    // handle exception
}

try {
    $container->add('item that exists', '...');
} catch (\Morphable\SimpleContainer\Exception\InstanceAlreadyExists $e) {
    // handle exception
}




use \Morphable\SimpleContainer\ExecutableContainer;

$container = new ExecutableContainer("ecutes all items in container
$container->execute('any','parameter');