-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathContainer.php
More file actions
81 lines (70 loc) · 1.75 KB
/
Container.php
File metadata and controls
81 lines (70 loc) · 1.75 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace LdapRecord;
/** @mixin ConnectionManager */
class Container
{
/**
* The current container instance.
*/
protected static Container $instance;
/**
* The connection manager instance.
*/
protected ConnectionManager $manager;
/**
* Get or set the current instance of the container.
*/
public static function getInstance(): static
{
return static::$instance ?? static::getNewInstance();
}
/**
* Set the container instance.
*/
public static function setInstance(?self $container = null): ?static
{
return static::$instance = $container;
}
/**
* Set and get a new instance of the container.
*/
public static function getNewInstance(): static
{
return static::setInstance(new static);
}
/**
* Forward missing static calls onto the current instance.
*/
public static function __callStatic(string $method, array $parameters): mixed
{
return static::getInstance()->{$method}(...$parameters);
}
/**
* Constructor.
*/
public function __construct(ConnectionManager $manager = new ConnectionManager)
{
$this->manager = $manager;
}
/**
* Forward missing method calls onto the connection manager.
*/
public function __call(string $method, array $parameters): mixed
{
return $this->manager->{$method}(...$parameters);
}
/**
* Set the current container instance available globally.
*/
public function setAsGlobal(): void
{
static::setInstance($this);
}
/**
* Get the connection manager.
*/
public function getConnectionManager(): ConnectionManager
{
return $this->manager;
}
}