XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
AssetManager.class.php
1<?php
11
12if (!defined('XOOPS_ROOT_PATH')) {
13 exit();
14}
15
17{
18 public $mDirname = 'profile';
19 public $mAssetList = [];
20 public $_mCache = [];
21
25 public function __construct()
26 {
27 }
28
32 public static function &getSingleton()
33 {
34 static $instance;
35
36 if (!is_object($instance)) {
37 $instance = new Profile_AssetManager();
38 }
39
40 return $instance;
41 }
42
49 public function &create($type, $name)
50 {
51 $instance = null;
52
53 // TODO:Insert your creation code.
54
55 // fallback
56 if (null === $instance) {
57 $instance =& $this->_fallbackCreate($type, $name);
58 }
59
60 $this->_mCache[$type][$name] =& $instance;
61
62 return $instance;
63 }
64
71 public function &_fallbackCreate($type, $name)
72 {
73 $instance = null;
74 if (isset($this->mAssetList[$type][$name])) {
75 $className = $this->mAssetList[$type][$name]['class'];
76 if (isset($this->mAssetList[$type][$name]['absPath'])) {
77 $filePath = $this->mAssetList[$type][$name]['absPath'];
78 } else {
79 $filePath = XOOPS_MODULE_PATH . '/' . $this->mDirname . '/' . $this->mAssetList[$type][$name]['path'];
80 }
81
82 $instance =& $this->_createInstance($className, $filePath);
83 } else {
84 switch ($type) {
85 case 'filter':
86 $instance =& $this->_createFilter($name);
87 break;
88 case 'form':
89 $instance =& $this->_createActionForm($name);
90 break;
91 case 'handler':
92 $instance =& $this->_createHandler($name);
93 break;
94 }
95 }
96
97 return $instance;
98 }
99
106 public function &load($type, $name)
107 {
108 if (isset($this->_mCache[$type][$name])) {
109 return $this->_mCache[$type][$name];
110 }
111
112 return $this->create($type, $name);
113 }
114
120 public function &_createHandler($name)
121 {
122 return xoops_getmodulehandler($name, $this->mDirname);
123 }
124
130 public function &_createFilter($name)
131 {
132 $entity = $name;
133 $isAdmin = false;
134 $adminToken = '';
135
136 if (preg_match("/^admin\.([a-z\_]+)$/i", $name, $matches)) {
137 $entity = $matches[1];
138 $isAdmin = true;
139 $adminToken = 'Admin_';
140 }
141
142 $filePath = $this->_getBasePath($isAdmin) . '/forms/' . ucfirst($entity) . 'FilterForm.class.php';
143 $className = ucfirst($this->mDirname) . "_{$adminToken}" . ucfirst($entity) . 'FilterForm';
144
145 $instance =& $this->_createInstance($className, $filePath);
146
147 return $instance;
148 }
149
155 public function &_createActionForm($name)
156 {
157 $mode = '';
158 $entity = $name;
159 $isAdmin = false;
160 $adminToken = '';
161
162 if (preg_match("/^admin\.([a-z\_]+)$/i", $name, $matches)) {
163 $entity = $matches[1];
164 $isAdmin = true;
165 $adminToken = 'Admin_';
166 }
167
168 if (preg_match("/^([^\_]+)\_(.+)$/", $entity, $matches)) {
169 $mode = $matches[1];
170 $entity = $matches[2];
171 }
172
173 $className = ucfirst($this->mDirname) . "_{$adminToken}" . ucfirst($entity) . ucfirst($mode) . 'Form';
174 $filePath = $this->_getBasePath($isAdmin) . '/forms/' . ucfirst($entity) . ucfirst($mode) . 'Form.class.php';
175
176 $instance =& $this->_createInstance($className, $filePath);
177
178 return $instance;
179 }
180
187 public function &_createInstance($className, $filePath)
188 {
189 $instance = null;
190
191 if (class_exists($className)) {
192 $instance =new $className();
193 return $instance;
194 }
195
196 if (!file_exists($filePath)) {
197 return $instance;
198 }
199
200 require_once $filePath;
201
202 if (class_exists($className)) {
203 $instance =new $className();
204 }
205
206 return $instance;
207 }
208
214 public function _getBasePath($isAdmin = false)
215 {
216 $filePath = XOOPS_MODULE_PATH . '/' . $this->mDirname;
217 if ($isAdmin) {
218 $filePath .= '/admin';
219 }
220
221 return $filePath;
222 }
223}
& _fallbackCreate($type, $name)
& _createInstance($className, $filePath)