This repository was archived by the owner on May 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainer.php
More file actions
126 lines (105 loc) · 3.04 KB
/
Copy pathContainer.php
File metadata and controls
126 lines (105 loc) · 3.04 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
namespace Freicon\StaticContainer;
use Pimple\ServiceProviderInterface;
use Pimple\Tests\Fixtures\PimpleServiceProvider;
/**
* Container main class.
*/
class Container extends \Pimple\Container
{
/**
* @var \Pimple\Container
*/
private static $container;
/**
* @var \Pimple\Container
*/
private static $outerContainer;
private static $commands = array();
/**
* @param \Pimple\Container $container
*/
public static function setContainer(\Pimple\Container $container)
{
self::$container = $container;
foreach (self::$commands as $command) {
call_user_func_array(array($container, $command['command']), $command['args']);
}
}
public function __call($name, $arguments)
{
$this->registerCommand($name, $arguments);
call_user_func_array(array(self::$container, $name), $arguments);
}
public static function lazyRegister(ServiceProviderInterface $interface) {
self::registerCommand('register', array($interface));
}
/**
* Returns the current registered Container Instance
* @return \Pimple\Container
*/
public static function instance()
{
if (!self::$outerContainer) {
self::$outerContainer = new static();
}
if (!self::$container) {
self::$container = new \Pimple\Container();
}
return self::$outerContainer;
}
/**
* @param $command
* @param $args
*/
private static function registerCommand($command, $args)
{
self::$commands[] = array('command' => $command, 'args' => $args);
}
public function offsetSet($id, $value)
{
$this->registerCommand('offsetSet', array($id, $value));
self::$container->offsetSet($id, $value);
}
public function offsetGet($id)
{
return self::$container->offsetGet($id);
}
public function offsetExists($id)
{
return self::$container->offsetExists($id);
}
public function offsetUnset($id)
{
$this->registerCommand('offsetUnset', array($id));
self::$container->offsetUnset($id);
}
public function factory($callable)
{
$this->registerCommand('factory', array($callable));
return self::$container->factory($callable);
}
public function protect($callable)
{
$this->registerCommand('protect', array($callable));
return self::$container->protect($callable);
}
public function raw($id)
{
return self::$container->raw($id);
}
public function extend($id, $callable)
{
$this->registerCommand('extend', array($id, $callable));
return self::$container->extend($id, $callable);
}
public function keys()
{
return self::$container->keys();
}
public function register(ServiceProviderInterface $provider, array $values = array())
{
$this->registerCommand('register', array($provider, $values));
return self::$container->register($provider, $values);
}
}