1. Go to this page and download the library: Download phpbench/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/ */
phpbench / container example snippets
$container = new Container();
$container->register('foobar', function (Container $container) {
return new \stdClass();
});
$container = new Container(
[
MyExtension::class
],
[
'foo.bar' => 'my_new_value',
]
);
$container->init(); // will trigger loading of the extensions.
class MyExtension implements ExtensionInterface
{
public function load(Container $container)
{
$container->register('my_service', function (Container $container) {
$service = new MyService(
$container->getParameter('foo_bar'),
$container->get('some_other_service')
);
foreach ($container->getServiceIdsForTag('tag') as $serviceId => $params) {
$service->add($container->get($serviceId));
}
return $service;
});
$container->register('tagged_service', function (Container $container) {
return new MyService(
$container->getParameter('foo_bar'),
$container->get('some_other_service')
);
}, [ 'tag' => [ 'param1' => 'foobar' ]);
}
/**
* Return the default parameters for the container.
*
* @return array
*/
public function getDefaultConfig()
{
return [
'foo_bar' => 'this is foo'
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.