forked from capsulephp/comparison
-
Notifications
You must be signed in to change notification settings - Fork 0
/
php-di.php
32 lines (27 loc) · 869 Bytes
/
php-di.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
require __DIR__ . '/psr-11-v1/vendor/autoload.php';
require __DIR__ . '/setup.php';
use DI\ContainerBuilder;
$containerBuilder = new ContainerBuilder();
$containerBuilder->useAutowiring(true);
$containerBuilder->useAnnotations(false);
$containerBuilder->addDefinitions([
PDO::CLASS => DI\autowire()
->constructor(
DI\env('DB_DSN'),
DI\env('DB_USERNAME'),
DI\env('DB_PASSWORD')
),
Foo::CLASS => DI\autowire()
// use a configuration value
->constructorParameter('bar', \DI\get('Foo:bar'))
->constructorParameter('baz', 'baz-right'),
'Foo:bar' => 'bar-wrong',
]);
// simulate override via configuration values
$containerBuilder->addDefinitions([
'Foo:bar' => 'bar-right',
]);
$container = $containerBuilder->build();
echo "PHP-DI" . PHP_EOL;
output($container, 'get');