|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the O2System Framework package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Steeve Andrian Salim |
|
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------ |
|
13
|
|
|
|
|
14
|
|
|
namespace O2System\Reactor\Containers; |
|
15
|
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
|
17
|
|
|
|
|
18
|
|
|
use O2System\Database; |
|
19
|
|
|
use O2System\Spl\Containers\DataStructures\SplServiceRegistry; |
|
20
|
|
|
use O2System\Spl\Containers\SplServiceContainer; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class Models |
|
24
|
|
|
* |
|
25
|
|
|
* @package O2System\Reactor\Containers |
|
26
|
|
|
*/ |
|
27
|
|
|
class Models extends SplServiceContainer |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Models::$database |
|
31
|
|
|
* |
|
32
|
|
|
* @var \O2System\Database\Connections |
|
33
|
|
|
*/ |
|
34
|
|
|
public $database; |
|
35
|
|
|
|
|
36
|
|
|
// ------------------------------------------------------------------------ |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Models::__construct |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct() |
|
42
|
|
|
{ |
|
43
|
|
|
if ($config = config()->loadFile('database', true)) { |
|
|
|
|
|
|
44
|
|
|
if ( ! empty($config[ 'default' ][ 'hostname' ]) AND ! empty($config[ 'default' ][ 'username' ])) { |
|
45
|
|
|
|
|
46
|
|
|
if (profiler() !== false) { |
|
47
|
|
|
profiler()->watch('Starting Database Service'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$this->database = new Database\Connections( |
|
51
|
|
|
new Database\DataStructures\Config( |
|
52
|
|
|
$config->getArrayCopy() |
|
53
|
|
|
) |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
// ------------------------------------------------------------------------ |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Models::load |
|
63
|
|
|
* |
|
64
|
|
|
* @param object|string $model |
|
65
|
|
|
* @param string|null $offset |
|
66
|
|
|
*/ |
|
67
|
|
|
public function load($model, $offset = null) |
|
68
|
|
|
{ |
|
69
|
|
|
if (is_string($model)) { |
|
70
|
|
|
$service = new SplServiceRegistry($model); |
|
71
|
|
|
} elseif ($model instanceof SplServiceRegistry) { |
|
72
|
|
|
$service = $model; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
if (isset($service) && $service instanceof SplServiceRegistry) { |
|
76
|
|
|
if (profiler() !== false) { |
|
77
|
|
|
profiler()->watch('Load New Model: ' . $service->getClassName()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$this->register($service, $offset); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
// ------------------------------------------------------------------------ |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Models::register |
|
88
|
|
|
* |
|
89
|
|
|
* @param SplServiceRegistry $service |
|
90
|
|
|
* @param string|null $offset |
|
91
|
|
|
*/ |
|
92
|
|
|
public function register(SplServiceRegistry $service, $offset = null) |
|
93
|
|
|
{ |
|
94
|
|
|
if ($service instanceof SplServiceRegistry) { |
|
|
|
|
|
|
95
|
|
|
$offset = isset($offset) |
|
96
|
|
|
? $offset |
|
97
|
|
|
: camelcase($service->getParameter()); |
|
98
|
|
|
|
|
99
|
|
|
if ($service->isSubclassOf('O2System\Framework\Models\Sql\Model') || |
|
100
|
|
|
$service->isSubclassOf('O2System\Framework\Models\NoSql\Model') || |
|
101
|
|
|
$service->isSubclassOf('O2System\Framework\Models\Files\Model') |
|
102
|
|
|
) { |
|
103
|
|
|
$this->attach($offset, $service); |
|
104
|
|
|
|
|
105
|
|
|
if (profiler() !== false) { |
|
106
|
|
|
profiler()->watch('Register New Model: ' . $service->getClassName()); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
// ------------------------------------------------------------------------ |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Models::add |
|
116
|
|
|
* |
|
117
|
|
|
* @param \O2System\Framework\Models\Sql\Model|\O2System\Framework\Models\NoSql\Model|\O2System\Framework\Models\Files\Model $model |
|
|
|
|
|
|
118
|
|
|
* @param null $offset |
|
|
|
|
|
|
119
|
|
|
*/ |
|
120
|
|
|
public function add($model, $offset = null) |
|
121
|
|
|
{ |
|
122
|
|
|
if (is_object($model)) { |
|
123
|
|
|
if ( ! $model instanceof SplServiceRegistry) { |
|
124
|
|
|
$model = new SplServiceRegistry($model); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
if (profiler() !== false) { |
|
129
|
|
|
profiler()->watch('Add New Model: ' . $model->getClassName()); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
$this->register($model, $offset); |
|
133
|
|
|
} |
|
134
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.