-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTinydbView.php
More file actions
67 lines (61 loc) · 2.03 KB
/
TinydbView.php
File metadata and controls
67 lines (61 loc) · 2.03 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
<?php
/**
* Tinydbプラグイン用Viewクラス
*/
App::uses('View', 'View');
/**
* Class TinydbView
*/
class TinydbView extends View {
/**
* _paths
*
* TinydbのViewファイルと同名のファイルが具象プラグインにあれば
* 具象プラグインのViewファイルでレンダリングされるようにする
*
* @param string|null $plugin plugin
* @param bool $cached cached
* @return array
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
protected function _paths($plugin = null, $cached = true) {
$paths = parent::_paths($plugin, $cached);
// TinydbのViewを使うときは具象プラグインのPathsを優先で追加
if ($plugin === 'Tinydb') {
$currentDbType = \NetCommons\Tinydb\Lib\CurrentDbType::instance()->getDbType();
if ($currentDbType === 'Tinydb') {
return $paths;
}
$currentDbTypePaths = parent::_paths($currentDbType);
$currentDbTypePaths = array_reverse($currentDbTypePaths);
foreach ($currentDbTypePaths as $path) {
if (strpos($path, $currentDbType) !== false) {
array_unshift($paths, $path);
}
}
$this->_pathsForPlugin['Tinydb'] = $paths;
return $paths;
}
// Tinydb具象プラグインを使うときはTinydbのViewPathsを劣後で追加
if (\NetCommons\Tinydb\Lib\CurrentDbType::instance()->getDbType() === $plugin) {
$currentDbType = \NetCommons\Tinydb\Lib\CurrentDbType::instance()->getDbType();
if ($currentDbType === 'Tinydb') {
return $paths;
}
// TinydbのViewを劣後で追加
$tinydbPaths = parent::_paths('Tinydb');
$tinydbPaths = array_filter($tinydbPaths, function ($path) {
return strpos($path, 'Tinydb') !== false;
});
$currentPluginPaths = array_filter($paths, function ($path) {
return strpos($path, $this->plugin) !== false;
});
$otherPaths = array_filter($paths, function ($path) {
return strpos($path, $this->plugin) === false;
});
$paths = array_merge($currentPluginPaths, $tinydbPaths, $otherPaths);
$this->_pathsForPlugin[$this->plugin] = $paths;
}
return $paths;
}
}