morphable / simple-container
A simple container component, easy to implement into any system
v1.0.1-stable
2019-01-29 19:07 UTC
Requires
- php: ~7.0
Requires (Dev)
- phpunit/phpunit: >=5.4.3
- squizlabs/php_codesniffer: ^2.3
This package is auto-updated.
Last update: 2024-12-29 05:51:01 UTC
README
A simple container component, easy to implement into any system
Installing
$ composer require morphable/simple-container
Usage
<?php 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 }
Executable container
<?php use \Morphable\SimpleContainer\ExecutableContainer; $container = new ExecutableContainer("required_method"); // needs method required_method $class = new MyClass(); $container->add('item', $class); // executes all items in container $container->execute('any','parameter');
Contributing
- Follow PSR-2 and the .editorconfig
- Start namespaces with \Morphable\SimpleContainer
- Make tests