1. Go to this page and download the library: Download decodelabs/pandora 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/ */
decodelabs / pandora example snippets
use DecodeLabs\Pandora\Container;
$container = new Container();
use My\Library\CoolInterface;
use My\Library\CoolImplementation; // Implements CoolInterface
// Instance
$container->bind(CoolInterface::class, new CoolImplementation());
$imp = $container->get(CoolInterface::class);
// Reused class
$container->bind(CoolInterface::class, CoolImplementation::class);
// Creates a new instace every call
$imp = $container->get(CoolInterface::class);
// Shared class
$container->bindShared(CoolInterface::class, CoolImplementation::class);
// Stores created instance and returns that each call
$imp = $container->get(CoolInterface::class);
// Locked instance - will only bind if CoolInterface has not been bound before
$container->bindLocked(CoolInterface::class, new CoolImplementation());
$imp = $container->get(CoolInterface::class);
// Bind a factory
$container->bind(CoolInterface::class, function($container) {
return new CoolImplementation();
})
// Group multiple bindings
$container->bindToGroup(CoolInterface::class, new CoolImplementation(1));
$container->bindToGroup(CoolInterface::class, new CoolImplementation(2));
$container->bindToGroup(CoolInterface::class, new CoolImplementation(3));
$group = $container->getGroup(CoolInterface::class); // Contains 3 Implementations
$container->each(CoolInterface::class, function($instance, $container) {
// Do something with each instance
});
// Aliased instance
$container->bind(CoolInterface::class, new CoolImplementation())
->alias('cool.thing');
$imp = $container->get('cool.thing');
// Or
$container->registerAlias(CoolInterface::class, 'cool.thing');
$container->bind(CoolInterface::class, CoolImplementation::class);
$imp = $container->get('cool.thing');
$imp = $container->getWith(CoolInterface::class, ['list', 'of', 'params']);
// Or inject parameters for later:
$container->inject(CoolInterface::class, 'paramName', 'paramValue');
$imp = $container->get(CoolInterface::class);