-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathContainer.php
More file actions
47 lines (40 loc) · 931 Bytes
/
Container.php
File metadata and controls
47 lines (40 loc) · 931 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
<?php
/**
* Created by PhpStorm.
* User: jyl
* Date: 2019/2/20
* Time: 10:34 AM
*/
declare(strict_types = 1);
namespace ContainerCore;
class Container
{
public $binds;
public $instances;
/**
* @param mixed $abstract
* @param mixed $concreate
*/
public function bind($abstract, $concreate)
{
if ($concreate instanceof \Closure)
$this->binds[$abstract] = $concreate;
else
$this->instances[$abstract] = $concreate;
}
/**
* make binds function() {}
*
* @param mixed $abstract
* @param array $parameters
*
* @return
*/
public function make($abstract, array $parameters = [])
{
if (isset($this->instances[$abstract]))
return $this->instances[$abstract];
array_unshift($parameters, $this);
return call_user_func_array($this->binds[$abstract], $parameters);
}
}