- <?php
- /**
- * @name Service_Page_Test
- * @desc page层对接第三方抽象类
- * @author
- */
- abstract class Service_Page_Test
- {
- public $hookGroupPrev = null; // 前钩子组
- public $hookGroupAfter = null; // 前钩子组
- public $hookReturn = array(); //钩子返回值
- public $reqData = null; // page模块分析的数据
- /**
- * 获取需要验证的参数配置
- * @return array
- */
- public function _getCheckParams()
- {
- return array();
- }
- /**
- * 入库方法
- * @param array $arrInput
- * @return array
- */
- public function execute($arrInput)
- {
- $res = array(
- 'errno' => Test_Errno::ERRNO_SUCCESS,
- 'errmsg' => Test_Errno::$ERRMSG[Test_Errno::ERRNO_SUCCESS],
- );
- try {
- $this->_init($arrInput);
- $this->_beforeExecute();
- $res = $this->doExecute($arrInput);
- $this->_afterExecute();
- } catch (Test_Exception $e) {
- $res = array(
- 'errno' => $e->getCode(),
- 'errmsg' => $e->getMessage(),
- );
- } catch (Exception $e) {
- $res = array(
- 'errno' => $e->getCode(),
- 'errmsg' => $e->getMessage(),
- );
- }
- return $res;
- }
- /**
- * auto exec
- * @param array $arrInput
- * @throws Exception
- * @return array
- */
- protected function doExecute($arrInput){
- }
- /**
- * 获取权限信息
- * @param array $arrInput
- * @return array
- */
- public function _init($arrInput)
- {
- $pageModulesConf = Conf::getConf('page/' . get_class($this));
- $this->hookGroupPrev[] = $pageModulesConf['hook_group']['prev'];
- $this->hookGroupAfter[] = $pageModulesConf['hook_group']['after'];
- }
- /**
- * 执行filter
- * @param string $filterName
- */
- public function _beforeExecute()
- {
- if (!empty($this->hookGroupPrev) && is_array($this->hookGroupPrev)) {
- foreach ($this->hookGroupPrev as $hookGroups) {
- foreach ($hookGroups as $hookGroup) {
- $this->_executeHook($hookGroup, $this->reqData);
- }
- }
- }
- }
- /**
- * @param array $arrInput
- * @return array
- */
- public function _afterExecute()
- {
- if (!empty($this->hookGroupAfter) && is_array($this->hookGroupAfter)) {
- foreach ($this->hookGroupAfter as $hookGroups) {
- foreach ($hookGroups as $hookGroup) {
- $this->_executeHook($hookGroup, $this->reqData);
- }
- }
- }
- }
- /**
- * 执行filter
- * @param string $filterName
- */
- public function _executeHook($hookGroup, $reqData)
- {
- $hookGroupConf = Conf::getConf('hook/group/' . $hookGroup);
- if(!empty($hookGroupConf)){
- foreach($hookGroupConf as $hook){
- $hookConf = Conf::getConf('hook/hook/' . $hook);
- $class = $hookConf['class'];
- $method = $hookConf['method'];
- $inputParams = isset($hookConf['getInputParams']) ? $this->{$hookConf['getInputParams']}() : null;
- if (class_exists($class)) {
- $obj = new $class();
- if (method_exists($obj, $method)) {
- $this->hookReturn[$hook][] = $obj->$method($inputParams, $reqData);
- }
- }
- }
- }
- }
- }
hook.conf
page.conf
- [group]
- [.check_req_customer]
- 0 : checkReqCustomerBaseInfo
- [.after_demo]
- 0 : afterDemo
- [hook]
- [.checkReqCustomerBaseInfo]
- class: Service_Page_Hook_Customer
- method: checkBaseInfo
- getInputParams: _getCheckParams
- [.afterDemo]
- class: Service_Page_Hook_Customer
- method: afterDemo
- getInputParams: _getCheckParams
- [Service_Page_Input]
- [.hook_group]
- [..prev]
- 0 : check_req_customer
- [..after]
- 0 : after_demo
来源: