PageRenderTime 65ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 0ms

/xoops_trust_path/modules/rpglink/class/AssetManager.class.php

https://github.com/kilica/playermap
PHP | 274 lines | 146 code | 30 blank | 98 comment | 20 complexity | d5db6c4b9b820d7780beb837b43a8108 MD5 | raw file
  1. <?php
  2. /**
  3. * @file
  4. * @package rpglink
  5. * @version $Id$
  6. **/
  7. if(!defined('XOOPS_ROOT_PATH'))
  8. {
  9. exit;
  10. }
  11. /**
  12. * Rpglink_AssetManager
  13. **/
  14. class Rpglink_AssetManager
  15. {
  16. public /*** string ***/ $mDirname = '';
  17. public /*** string ***/ $mTrustDirname = 'rpglink';
  18. public /*** string[][][] ***/ $mAssetList = array();
  19. private /*** object[][] ***/ $_mCache = array();
  20. /**
  21. * __construct
  22. *
  23. * @param string $dirname
  24. *
  25. * @return void
  26. **/
  27. public function __construct(/*** string ***/ $dirname)
  28. {
  29. $this->mDirname = $dirname;
  30. }
  31. /**
  32. * &getInstance
  33. *
  34. * @param string $dirname
  35. *
  36. * @return Rpglink_AssetManager
  37. **/
  38. public function &getInstance(/*** string ***/ $dirname)
  39. {
  40. /**
  41. * @var Rpglink_AssetManager[]
  42. **/
  43. static $instance = array();
  44. if(!isset($instance[$dirname]))
  45. {
  46. $instance[$dirname] = new self($dirname);
  47. }
  48. return $instance[$dirname];
  49. }
  50. /**
  51. * &getObject
  52. *
  53. * @param string $type
  54. * @param string $name
  55. * @param bool $isAdmin
  56. * @param string $mode
  57. *
  58. * @return &object<XCube_ActionFilter,XCube_ActionForm,XoopsObjectGenericHandler>
  59. **/
  60. public function &getObject(/*** string ***/ $type,/*** string ***/ $name,/*** bool ***/ $isAdmin = false,/*** string ***/ $mode = null)
  61. {
  62. if(isset($this->_mCache[$type][$name]))
  63. {
  64. return $this->_mCache[$type][$name];
  65. }
  66. $instance = null;
  67. $methodName = 'create' . ucfirst($name) . ucfirst($mode) . ucfirst($type);
  68. if(method_exists($this,$methodName))
  69. {
  70. $instance =& $this->$methodName();
  71. }
  72. if($instance === null)
  73. {
  74. $instance =& $this->_fallbackCreate($type,$name,$isAdmin,$mode);
  75. }
  76. $this->_mCache[$type][$name] =& $instance;
  77. return $instance;
  78. }
  79. /**
  80. * getRoleName
  81. *
  82. * @param string $role
  83. *
  84. * @return string
  85. **/
  86. public function getRoleName(/*** string ***/ $role)
  87. {
  88. return 'Module.' . $this->mDirname . '.' . $role;
  89. }
  90. /**
  91. * &_fallbackCreate
  92. *
  93. * @param string $type
  94. * @param string $name
  95. * @param bool $isAdmin
  96. * @param string $mode
  97. *
  98. * @return &object<XCube_ActionFilter,XCube_ActionForm,XoopsObjectGenericHandler>
  99. **/
  100. private function &_fallbackCreate(/*** string ***/ $type,/*** string ***/ $name,/*** bool ***/ $isAdmin = false,/*** string ***/ $mode = null)
  101. {
  102. $className = null;
  103. $instance = null;
  104. if(isset($this->mAssetList[$type][$name]['class']))
  105. {
  106. $asset = $this->mAssetList[$type][$name];
  107. if(isset($asset['absPath']) && $this->_loadClassFile($asset['absPath'],$asset['class']))
  108. {
  109. $className = $asset['class'];
  110. }
  111. if($className == null && isset($asset['path']))
  112. {
  113. if($this->_loadClassFile($this->_getPublicPath() . $asset['path'],$asset['class']))
  114. {
  115. $className = $asset['class'];
  116. }
  117. if($className == null && $this->_loadClassFile($this->_getTrustPath() . $asset['path'],$asset['class']))
  118. {
  119. $className = $asset['class'];
  120. }
  121. }
  122. }
  123. if($className == null)
  124. {
  125. switch($type)
  126. {
  127. case 'filter':
  128. $className = $this->_getFilterName($name,$isAdmin);
  129. break;
  130. case 'form':
  131. $className = $this->_getActionFormName($name,$isAdmin,$mode);
  132. break;
  133. case 'handler':
  134. $className = $this->_getHandlerName($name);
  135. break;
  136. default:
  137. return $instance;
  138. }
  139. }
  140. if($type == 'handler')
  141. {
  142. $root =& XCube_Root::getSingleton();
  143. $instance = new $className($root->mController->getDB(),$this->mDirname);
  144. }
  145. else
  146. {
  147. $instance = new $className();
  148. }
  149. return $instance;
  150. }
  151. /**
  152. * _getFilterName
  153. *
  154. * @param string $name
  155. * @param bool $isAdmin
  156. *
  157. * @return string
  158. **/
  159. private function _getFilterName(/*** string ***/ $name,/*** bool ***/ $isAdmin = false)
  160. {
  161. $name = ucfirst($name) . 'FilterForm';
  162. $path = 'forms/' . $name . '.class.php';
  163. $className = ucfirst($this->mTrustDirname) . ($isAdmin ? '_Admin_' : '_') . $name;
  164. return (
  165. $this->_loadClassFile($this->_getPublicPath($isAdmin) . $path,$className) ||
  166. $this->_loadClassFile($this->_getTrustPath($isAdmin) . $path,$className)
  167. ) ? $className : null;
  168. }
  169. /**
  170. * _getActionFormName
  171. *
  172. * @param string $name
  173. * @param bool $isAdmin
  174. * @param string $mode
  175. *
  176. * @return string
  177. **/
  178. private function _getActionFormName(/*** string ***/ $name,/*** bool ***/ $isAdmin = false,/*** string ***/ $mode = null)
  179. {
  180. $name = ucfirst($name) . ucfirst($mode) . 'Form';
  181. $path = 'forms/' . $name . '.class.php';
  182. $className = ucfirst($this->mTrustDirname) . ($isAdmin ? '_Admin_' : '_') . $name;
  183. return (
  184. $this->_loadClassFile($this->_getPublicPath($isAdmin) . $path,$className) ||
  185. $this->_loadClassFile($this->_getTrustPath($isAdmin) . $path,$className)
  186. ) ? $className : null;
  187. }
  188. /**
  189. * _getHandlerName
  190. *
  191. * @param string $name
  192. *
  193. * @return string
  194. **/
  195. private function _getHandlerName(/*** string ***/ $name)
  196. {
  197. $path = 'class/handler/' . ucfirst($name) . '.class.php';
  198. $className = ucfirst($this->mTrustDirname) . '_' . ucfirst($name) . 'Handler';
  199. return (
  200. $this->_loadClassFile($this->_getPublicPath() . $path,$className) ||
  201. $this->_loadClassFile($this->_getTrustPath() . $path,$className)
  202. ) ? $className : null;
  203. }
  204. /**
  205. * _loadClassFile
  206. *
  207. * @param string $path
  208. * @param string $class
  209. *
  210. * @return bool
  211. **/
  212. private function _loadClassFile(/*** string ***/ $path,/*** string ***/ $class)
  213. {
  214. if(!file_exists($path))
  215. {
  216. return false;
  217. }
  218. require_once $path;
  219. return class_exists($class);
  220. }
  221. /**
  222. * _getPublicPath
  223. *
  224. * @param bool $isAdmin
  225. *
  226. * @return string
  227. **/
  228. private function _getPublicPath(/*** bool ***/ $isAdmin = false)
  229. {
  230. return XOOPS_MODULE_PATH . '/' . $this->mDirname . ($isAdmin ? '/admin/' : '/');
  231. }
  232. /**
  233. * _getTrustPath
  234. *
  235. * @param bool $isAdmin
  236. *
  237. * @return string
  238. **/
  239. private function _getTrustPath(/*** bool ***/ $isAdmin = false)
  240. {
  241. return RPGLINK_TRUST_PATH . ($isAdmin ? '/admin/' : '/');
  242. }
  243. }
  244. ?>