modle factory
来源:互联网 发布:国际象棋在线对弈软件 编辑:程序博客网 时间:2024/06/05 17:01
interface InterfaceFactory { /** * @param string $name * @return mixed */ public static function create($name);}
model
class ModelFactory implements InterfaceFactory{ private static $_models = array(); public static function create($name) { if (strrpos($name, 'Model') === false) { $name .= 'Model'; } $params = array_slice(func_get_args(), 1); // @attention keep val same type, for generate same uniqName foreach ($params as & $v) { if (is_numeric($v)) { $v = (int) $v; } } $uniqName = $name . '_' . md5(serialize($params)); if (!isset(self::$_models[$uniqName])) { $obj = new ReflectionClass($name); self::$_models[$uniqName] = $obj->newInstanceArgs($params); self::_setLogger(self::$_models[$uniqName]); } return self::$_models[$uniqName]; } /** * @param BaseModel $model */ private static function _setLogger($model) { if (method_exists($model, 'setLogger')) { // @todo get dir&level from config global $sharePrefix; $logDir = LOGPATH . $sharePrefix; $logger = Utils_Logger::getInstance($logDir,defined('ROTATE_LOGGING_LEVEL') ? ROTATE_LOGGING_LEVEL : Utils_Logger::OFF); $model->setLogger($logger); } } /** * @param array $configs * @return BaseModel */ public static function createByConfig($configs) { $params = array_slice(func_get_args(), 1); $uniqName = 'anonymous' . '_' . md5(serialize($configs) . md5(serialize($params))); if (!isset(self::$_models[$uniqName])) { $obj = new ReflectionClass('BaseModel'); /** @var BaseModel $model */ $model = $obj->newInstanceArgs($params); $model->setProperties($configs); self::_setLogger($model); self::$_models[$uniqName] = $model; } return self::$_models[$uniqName]; }}
control
$app = isset($_GET['_a']) ? $_GET['_a'] : 'Admin';$module = ucfirst((isset($_GET['_m']) ? $_GET['_m'] : 'MysteryChest_')) . 'Module';$controller = ucfirst((isset($_GET['_c']) ? $_GET['_c'] : 'MysteryChestTracker_')) . 'Controller';$action = (isset($_REQUEST['_ac']) ? $_REQUEST['_ac'] : 'index') . 'Action';$cls = new $controller();if(method_exists($cls,$action)) { try { $cls->$action(); }catch (CException $e) { if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { echo json_encode(array('error_code' => $e->getCodeBE(), 'msg' => $e->getMessage(), 'data' => array())); } else { throw $e; } }} else { throw new CException(404, "Method [{$controller}::{$action}] Not Found");}class MysteryChestTracker_Controller { const END_OF_WORLD = 32503651200;// 3000-1-1 public function __get($name) { if ($name == '_tpl') { return $this->_tpl = new TemplateLoader(array('tplDir' => PAGEPATH . 'admin/templates/')); } return NULL; } private function _initServersInfo() { } public function indexAction() { $this->_initServersInfo(); $this->_tpl->display('MysteryChestTracker/index.php'); } public function showTableAction() { $starttime = 0; $endtime = self::END_OF_WORLD; if (isset($_GET['starttime']) && !empty($_GET['starttime']) ) { $starttime = strtotime($_GET['starttime']); } if (isset($_GET['endtime']) && !empty($_GET['endtime']) ) { $endtime = strtotime($_GET['endtime']); } $this->_tpl->assign('trackerInfo', ModuleFactory::create('MysteryChest_TrackerModule')->getTrackerInfo($starttime,$endtime)); $this->_tpl->display('MysteryChestTracker/table.php'); }
0 0
- modle factory
- modle
- affine modle
- via modle
- android studio 新建modle和删除modle
- JAVA_OPTS and memory Modle
- modle模型 - scope
- [NS3]Openflow Modle安装
- python modle addr
- import modle error cv2
- Factory
- factory
- factory
- Factory
- Factory
- factory
- Factory
- Factory
- Android实战之 万能的接口回调
- UVA 127 ``Accordian'' Patience
- 7月27日--爬虫心得
- FZU 2168 防守阵地 I(公式推导)(经典)(中等)
- ngx_listening_s
- modle factory
- R语言支持向量机SVM
- 开发团队周总结流水20150724
- python class __slots__
- 线段树_HDU_1754
- Android ndk 单步调试
- 关于caffe-windows中 compute_image_mean.exe出现的问题
- 效率极低人群之七大习惯------写得很透彻
- 关于iOS push一些问题的理解