https://github.com/morphable/simplecontainer
https://github.com/morphable/simplecontainer
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/morphable/simplecontainer
- Owner: Morphable
- License: mit
- Created: 2019-01-24T18:44:23.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-29T19:09:36.000Z (over 7 years ago)
- Last Synced: 2025-01-01T02:34:57.626Z (over 1 year ago)
- Language: PHP
- Size: 14.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple container component
A simple container component, easy to implement into any system
## Installing
```terminal
$ composer require morphable/simple-container
```
## Usage
```php
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
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