1. Go to this page and download the library: Download phpsoftbox/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/ */
phpsoftbox / container example snippets
use PhpSoftBox\Container\ContainerBuilder;
use Psr\Container\ContainerInterface;
use function PhpSoftBox\Container\autowire;
use function PhpSoftBox\Container\factory;
use function PhpSoftBox\Container\get;
$builder = new ContainerBuilder();
$builder->useAutowiring(true);
$builder->addDefinitions([
LoggerInterface::class => autowire(Logger::class),
UserService::class => factory(
static fn (ContainerInterface $c): UserService => new UserService($c->get(LoggerInterface::class)),
),
UserServiceInterface::class => get(UserService::class),
]);
$builder->lazy(UserService::class);
$container = $builder->build();
ContainerBuilder::clearCompiledCache(__DIR__ . '/var/cache/di'); // int — количество удалённых файлов
use PhpSoftBox\Container\Reset\ServicesResetter;
$resetter = new ServicesResetter($container, [
// Классы из пакетов, которые не зависят от контейнера: запись → метод (или список методов).
ConnectionManagerInterface::class => 'clearWarmup',
EntityManagerInterface::class => 'clear',
]);
$resetter->reset();