forked from capsulephp/comparison
-
Notifications
You must be signed in to change notification settings - Fork 0
/
illuminate.php
48 lines (37 loc) · 1.08 KB
/
illuminate.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
38
39
40
41
42
43
44
45
46
47
48
<?php
require __DIR__ . '/psr-11-v1/vendor/autoload.php';
require __DIR__ . '/setup.php';
use Illuminate\Container\Container;
$container = new Container();
$container->when(PDO::CLASS)
->needs('$dsn')
->giveConfig('PDO:dsn');
$container->when(PDO::CLASS)
->needs('$username')
->giveConfig('PDO:username');
$container->when(PDO::CLASS)
->needs('$password')
->giveConfig('PDO:password');
$container->when(Foo::CLASS)
->needs('$bar')
->give('bar-wrong');
$container->when(Foo::CLASS)
->needs('$baz')
->give('baz-right');
// simulate override
$container->when(Foo::CLASS)
->needs('$bar')
->give('bar-right');
// lazy-load environment values ...
$configFactory = function () {
$config = new Container();
$config['PDO:dsn'] = getenv('DB_DSN');
$config['PDO:username'] = getenv('DB_USERNAME');
$config['PDO:password'] = getenv('DB_PASSWORD');
return $config;
};
// and bind them where the container expects them
$container->bind('config', $configFactory, true);
// done
echo "Illuminate (Laravel)" . PHP_EOL;
output($container, 'get');