11<?php
22namespace Olive \UDMS \Addon \Json ;
33
4+ use Olive \Tools ;
45use Olive \UDMS \Common as Common ;
56use Olive \UDMS \Model \Addon as Addon ;
6- use Olive \Tools ;
77class Point implements Addon
88{
99 use Common;
1010
11+ private $ cacheDB ;
12+
13+ private $ cacheDBC ;
14+
1115 public function createDatabase ($ name , $ options )
1216 {
13- $ dir = $ this ->getUCPath ($ name . '/json/ ' );
17+ $ dir = $ this ->getCore -> getUCPath ($ name . '/json/ ' );
1418 if (! is_dir ($ dir )) {
1519 mkdir ($ dir );
1620 }
@@ -20,12 +24,12 @@ public function createDatabase($name, $options)
2024
2125 public function dropDatabase ($ name )
2226 {
23- Tools::rmDir ($ this ->getUCPath ($ name . '/json/ ' ));
27+ Tools::rmDir ($ this ->getCore -> getUCPath ($ name . '/json/ ' ));
2428 }
2529
2630 public function existsDatabase ($ name )
2731 {
28- if (file_exists ($ this ->getUCPath ($ name . '/json/db.json ' ))) {
32+ if (file_exists ($ this ->getCore -> getUCPath ($ name . '/json/db.json ' ))) {
2933 return true ;
3034 } else {
3135 return false ;
@@ -35,9 +39,9 @@ public function existsDatabase($name)
3539 public function listDatabases ()
3640 {
3741 $ return = [];
38- $ dbdirs = Tools::getDirList ($ this ->getUCPath ());
42+ $ dbdirs = Tools::getDirList ($ this ->getCore -> getUCPath ());
3943 foreach ($ dbdirs as $ db ) {
40- if (file_exists ($ this ->getUCPath ($ db . '/json/db.json ' ))) {
44+ if (file_exists ($ this ->getCore -> getUCPath ($ db . '/json/db.json ' ))) {
4145 $ return [] = $ db ;
4246 }
4347 }
@@ -51,32 +55,32 @@ public function renameDatabase($name, $to)
5155
5256 private function get_db ($ name )
5357 {
54- if (! isset ( $ GLOBALS [ ' __udms_global ' ][ ' addon ' ][ ' json ' ][ ' db ' ][ $ name ] )) {
55- $ GLOBALS [ ' __udms_global ' ][ ' addon ' ][ ' json ' ][ ' db ' ][ $ name ] = Tools::getJsonFile ($ this ->getUCPath ($ name . '/json/db.json ' ));
58+ if (is_null ( $ this -> cacheDB )) {
59+ $ this -> cacheDB = Tools::getJsonFile ($ this -> getCore ->getUCPath ($ name . '/json/db.json ' ));
5660 }
5761
58- return $ GLOBALS [ ' __udms_global ' ][ ' addon ' ][ ' json ' ][ ' db ' ][ $ name ] ;
62+ return $ this -> cacheDB ;
5963 }
6064
6165 private function update_db ($ name , $ data = [])
6266 {
63- Tools::file ($ this ->getUCPath ($ name . '/json/db.json ' ), Tools::jsonEncode ($ data ));
64- $ GLOBALS [ ' __udms_global ' ][ ' addon ' ][ ' json ' ][ ' db ' ][ $ name ] = $ data ;
67+ Tools::file ($ this ->getCore -> getUCPath ($ name . '/json/db.json ' ), Tools::jsonEncode ($ data ));
68+ $ this -> cacheDB = $ data ;
6569 }
6670
6771 private function get_dbc ($ name )
6872 {
69- if (! isset ( $ GLOBALS [ ' __udms_global ' ][ ' addon ' ][ ' json ' ][ ' config ' ][ $ name ] )) {
70- $ GLOBALS [ ' __udms_global ' ][ ' addon ' ][ ' json ' ][ ' config ' ][ $ name ] = Tools::getJsonFile ($ this ->getUCPath ($ name . '/json/config.json ' ));
73+ if (is_null ( $ this -> cacheDBC )) {
74+ $ this -> cacheDBC = Tools::getJsonFile ($ this -> getCore ->getUCPath ($ name . '/json/config.json ' ));
7175 }
7276
73- return $ GLOBALS [ ' __udms_global ' ][ ' addon ' ][ ' json ' ][ ' config ' ][ $ name ] ;
77+ return $ this -> cacheDBC ;
7478 }
7579
7680 private function update_dbc ($ name , $ data = [])
7781 {
78- Tools::file ($ this ->getUCPath ($ name . '/json/config.json ' ), Tools::jsonEncode ($ data ));
79- $ GLOBALS [ ' __udms_global ' ][ ' addon ' ][ ' json ' ][ ' config ' ][ $ name ] = $ data ;
82+ Tools::file ($ this ->getCore -> getUCPath ($ name . '/json/config.json ' ), Tools::jsonEncode ($ data ));
83+ $ this -> cacheDBC = $ data ;
8084 }
8185
8286 public function createTable ($ db , $ name , $ options )
@@ -221,9 +225,8 @@ public function get($db, $table)
221225 }
222226 }
223227
224- public function __construct ($ path , $ udmsCacheDir , $ option = [])
228+ public function __construct ($ point , $ option = [])
225229 {
226- $ this ->setPath ($ path );
227- $ this ->setUCPath ($ udmsCacheDir );
230+ $ this ->getCore = $ point ;
228231 }
229232}
0 commit comments