1. Go to this page and download the library: Download bayfrontmedia/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/ */
bayfrontmedia / container example snippets
// Set a service with no dependencies
$container->set('Fully\Namespaced\ClassName', function () {
return new ClassName();
});
// Set a service with dependencies
$container->set('Fully\Namespaced\ClassName', function (ContainerInterface $container) {
$dependency = $container->get('Fully\Namespaced\Dependency');
return new ClassName($dependency);
});
// Any type of value can be set, then used as a parameter
$container->set('classname_config', [
// Config array
]);
$container->set('Fully\Namespaced\ClassName', function (ContainerInterface $container) {
$config = $container->get('classname_config');
return new ClassName($config);
});
// Preexisting class instances can be set without using an anonymous function
$class = new ClassName();
$container->set('ClassName', $class);