1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the O2System PHP 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\Framework\Containers; |
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
17
|
|
|
|
18
|
|
|
use O2System\Database; |
19
|
|
|
use O2System\Framework\Models\Files\Model as FileModel; |
20
|
|
|
use O2System\Framework\Models\NoSql\Model as NoSqlModel; |
21
|
|
|
use O2System\Framework\Models\Sql\Model as SqlModel; |
22
|
|
|
use O2System\Spl\Containers\Datastructures\SplServiceRegistry; |
23
|
|
|
use O2System\Spl\Containers\SplServiceContainer; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class Models |
27
|
|
|
* |
28
|
|
|
* @package O2System\Framework |
29
|
|
|
*/ |
30
|
|
|
class Models extends SplServiceContainer |
31
|
|
|
{ |
32
|
|
|
public $database; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Models::__construct |
36
|
|
|
*/ |
37
|
|
|
public function __construct() |
38
|
|
|
{ |
39
|
|
|
if ($config = config()->loadFile('database', true)) { |
|
|
|
|
40
|
|
|
if ( ! empty($config[ 'default' ][ 'hostname' ]) AND ! empty($config[ 'default' ][ 'username' ])) { |
41
|
|
|
|
42
|
|
|
if(profiler() !== false) { |
|
|
|
|
43
|
|
|
profiler()->watch('Starting Database Service'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$this->database = new Database\Connections( |
47
|
|
|
new Database\Datastructures\Config( |
48
|
|
|
$config->getArrayCopy() |
49
|
|
|
) |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// ------------------------------------------------------------------------ |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Models::load |
59
|
|
|
* |
60
|
|
|
* @param object|string $model |
61
|
|
|
* @param string|null $offset |
62
|
|
|
*/ |
63
|
|
|
public function load($model, $offset = null) |
64
|
|
|
{ |
65
|
|
|
if (is_string($model)) { |
66
|
|
|
$service = new SplServiceRegistry($model); |
67
|
|
|
} elseif ($model instanceof SplServiceRegistry) { |
68
|
|
|
$service = $model; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if (isset($service) && $service instanceof SplServiceRegistry) { |
72
|
|
|
if (profiler() !== false) { |
|
|
|
|
73
|
|
|
profiler()->watch('Load New Model: ' . $service->getClassName()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$this->register($service, $offset); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// ------------------------------------------------------------------------ |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Models::add |
84
|
|
|
* |
85
|
|
|
* @param \O2System\Framework\Models\Sql\Model|\O2System\Framework\Models\NoSql\Model|\O2System\Framework\Models\Files\Model $model |
86
|
|
|
* @param null $offset |
|
|
|
|
87
|
|
|
*/ |
88
|
|
|
public function add($model, $offset = null) |
89
|
|
|
{ |
90
|
|
|
if (is_object($service)) { |
|
|
|
|
91
|
|
|
if ( ! $service instanceof SplServiceRegistry) { |
92
|
|
|
$service = new SplServiceRegistry($service); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if (profiler() !== false) { |
|
|
|
|
97
|
|
|
profiler()->watch('Add New Model: ' . $service->getClassName()); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$this->register($service, $offset); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
// ------------------------------------------------------------------------ |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Models::register |
107
|
|
|
* |
108
|
|
|
* @param SplServiceRegistry $service |
109
|
|
|
* @param string|null $offset |
110
|
|
|
*/ |
111
|
|
|
public function register(SplServiceRegistry $service, $offset = null) |
112
|
|
|
{ |
113
|
|
|
if ($service instanceof SplServiceRegistry) { |
|
|
|
|
114
|
|
|
$offset = isset($offset) |
115
|
|
|
? $offset |
116
|
|
|
: camelcase($service->getParameter()); |
117
|
|
|
|
118
|
|
|
if ($service->isSubclassOf('O2System\Framework\Models\Sql\Model') || |
119
|
|
|
$service->isSubclassOf('O2System\Framework\Models\NoSql\Model') || |
120
|
|
|
$service->isSubclassOf('O2System\Framework\Models\Files\Model') |
121
|
|
|
) { |
122
|
|
|
$this->attach($offset, $service); |
123
|
|
|
|
124
|
|
|
if (profiler() !== false) { |
|
|
|
|
125
|
|
|
profiler()->watch('Register New Model: ' . $service->getClassName()); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
} |
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.