Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types=1);
- require __DIR__ . '/vendor/autoload.php';
- class CidHolder {
- public function __construct(public readonly int|string $cid)
- {
- }
- }
- class SomeDependency {}
- class MyService {
- private string|int $cid;
- public function __construct(
- CidHolder $cidHolder,
- private readonly SomeDependency $dependency
- ) {
- $this->cid = $cidHolder->cid;
- }
- }
- $containerBuilder = new \DI\ContainerBuilder();
- $containerBuilder->useAutowiring(true);
- $containerBuilder->addDefinitions([
- CidHolder::class => \DI\factory(function () {
- return new CidHolder($_SESSION['client']['cid'] ?? 'unknown');
- }),
- ]);
- $container = $containerBuilder->build();
- var_dump($container->get(MyService::class));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement