forked from capsulephp/comparison
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleague.php
37 lines (29 loc) · 1.09 KB
/
league.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
33
34
35
36
37
<?php
require __DIR__ . '/psr-11-v2/vendor/autoload.php';
require __DIR__ . '/setup.php';
use League\Container\Argument\ResolvableArgument;
use League\Container\Argument\Literal\StringArgument;
use League\Container\Container;
use League\Container\ReflectionContainer;
$container = new Container();
$container->delegate(new ReflectionContainer());
$container->add(PDO::CLASS)
->addArguments([
new ResolvableArgument('PDO:dsn'),
new ResolvableArgument('PDO:username'),
new ResolvableArgument('PDO:password'),
]);
$container->add(Foo::CLASS)
->addArguments([
new ResolvableArgument(PDO::CLASS),
new ResolvableArgument('Foo:bar'),
new StringArgument('baz-right'),
]);
$container->add('Foo:bar', 'bar-wrong');
$container->add('PDO:dsn', function () { return getenv('DB_DSN'); });
$container->add('PDO:username', function () { return getenv('DB_USERNAME'); });
$container->add('PDO:password', function () { return getenv('DB_PASSWORD'); });
// simulate override
$container->add('Foo:bar', 'bar-right');
echo "League" . PHP_EOL;
output($container, 'get');