-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCore.php
91 lines (78 loc) · 1.79 KB
/
Core.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
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
<?php
/**
* Core
*/
namespace Yonna;
use Yonna\Core\Glue;
use Yonna\Bootstrap\Bootstrap;
use Yonna\IO\RequestBuilder;
class Core
{
/**
* 单例
*/
protected static $instance;
/**
* 核心所管理的实例
*/
protected static $instances = [];
/**
* @return Core
*/
public static function getInstance(): Core
{
if (null === static::$instance) {
static::$instance = new static();
}
return static::$instance;
}
/**
* @return array
*/
public static function getInstances(): array
{
return static::$instances;
}
/**
* 获取实例
* @param string $class
* @param array $params
* @return object
*/
public static function singleton($class, ...$params): object
{
if (isset(static::$instances[$class])) {
return static::$instances[$class];
} else {
static::$instances[$class] = Glue::paste($class, $params);
}
return static::$instances[$class];
}
/**
* 获取新实例
* @param string $class
* @param array $params
* @return object
*/
public static function get(string $class, ...$params): object
{
return Glue::paste($class, $params);
}
/**
* 驱动净神
* bootstrap
* @param $root
* @param null $env_name
* @param null $boot_type
* @param RequestBuilder | null $builder
* @return Response\Collector
*/
public static function bootstrap($root, $env_name, $boot_type, RequestBuilder $builder = null)
{
/**
* @var Bootstrap $bootstrap
*/
$bootstrap = Core::get(Bootstrap::class);
return $bootstrap->boot($root, $env_name, $boot_type, $builder);
}
}