-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingleton.php
More file actions
51 lines (38 loc) · 786 Bytes
/
singleton.php
File metadata and controls
51 lines (38 loc) · 786 Bytes
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
49
50
51
<?php
use Please\Container\Container as BaseContainer;
use Please\Container\Support\Traits\Singleton;
require __DIR__ . '/../vendor/autoload.php';
class Container extends BaseContainer
{
use Singleton;
}
class Foo
{
function __construct(public Bar $bar)
{
dump('foo::created');
}
}
class Bar
{
function __construct(public Baz $baz)
{
dump('bar::created');
}
}
class Baz
{
function __construct()
{
dump('baz::created');
}
}
$container = Container::getInstance();
$container->bind(Foo::class);
$container->bind('bar', Bar::class);
$container->bind([Baz::class, 'baz', 'baz-alias'], Baz::class);
$container->get(Foo::class);
echo PHP_EOL;
$container->get(Bar::class);
echo PHP_EOL;
$container->get('baz-alias');