-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTinydbAppModel.php
More file actions
74 lines (68 loc) · 1.72 KB
/
TinydbAppModel.php
File metadata and controls
74 lines (68 loc) · 1.72 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
<?php
/**
* TinydbAppModel
*/
App::uses('AppModel', 'Model');
/**
* Class TinydbAppModel
*/
class TinydbAppModel extends AppModel {
/**
* TinydbAppModel constructor.
*
* @param int|bool $id id
* @param string|null $table table
* @param mixed|null $ds ds
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function __construct($id = false, $table = null, $ds = null) {
$dbType = \NetCommons\Tinydb\Lib\CurrentDbType::instance();
if ($dbType !== null) {
$this->plugin = $dbType->getDbType();
}
parent::__construct($id, $table, $ds);
}
/**
* _triggerEvent
*
* @param string $localEventName model event name
* @param mixed &$args 引数
* @return void
*/
protected function _triggerEvent(string $localEventName, &...$args) {
$dbTypeInstance = \NetCommons\Tinydb\Lib\CurrentDbType::instance();
if ($dbTypeInstance === null) {
return;
}
$dbType = $dbTypeInstance->getDbType();
$fullEventName = $dbType . '.Tinydb.Model.' . $localEventName;
\NetCommons\Tinydb\Lib\EventManager::instance()->dispatchByArray($fullEventName, $args);
}
/**
* _setUpDbType
*
* @return void
*/
protected function _setUpDbType() {
// Migration実行時にdbType不定になるので
$dbTypeInstance = \NetCommons\Tinydb\Lib\CurrentDbType::instance();
if ($dbTypeInstance === null) {
return;
}
$dbType = $dbTypeInstance->getDbType();
if ($dbType === 'Tinydb') {
return;
}
$pluginName = $dbType;
$modelName = str_replace('Tinydb', $dbType, get_class($this));
$dbModel = ClassRegistry::init($pluginName . '.' . $modelName, true);
if ($dbModel) {
$this->hasOne[$modelName] = [
'className' => $pluginName . '.' . $modelName,
'conditions' => [
]
];
$this->$modelName = $dbModel;
}
}
}