php钩子程序设计

- <?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->reqData = $arrInput;
- $this->hookGroupPrev[] = $pageModulesConf['hook_group']['prev'];
- $this->hookGroupAfter[] = $pageModulesConf['hook_group']['after'];
- }
- /**
- * 执行filter
- * @param string
- */
- 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
- */
- 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
- # 钩子组
[group]- [.check_req_customer]
- : checkReqCustomerBaseInfo
- [.after_demo]
- : 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

php钩子程序设计的更多相关文章
- c++程序设计之编程思想
代码块愈小,代码的功能就愈容易管理,代码的处理和移动就愈轻松. 任何一个傻瓜都能写出计算机可以理解的代码,唯有写出人类容易理解的代码,才是优秀的程序员. 绝大多数情况下,函数应该放在它所使用的数据的所 ...
- Java动态程序设计:反射介绍
使用运行的类的信息使你的程序设计更加灵活 反射授予了你的代码访问装载进JVM内的Java类的内部信息的权限,并且允许你编写在程序执行期间与所选择的类的一同工作的代码,而不是在源代码中.这种机制使得反射 ...
- 使用PreTranslateMessage替代钩子函数处理键盘消息
2002年左右,我所在公司在开发基于H.323的VoIP电话系统(用了以色列一家公司的库,具体名字忘记了). 去电信科技研究院测试系统,同事发现处理键盘消息总有一些莫名其妙的问题,比如延迟或异常. 我 ...
- Windows环境下32位汇编语言程序设计(典藏版)
Windows环境下32位汇编语言程序设计(典藏版)(含CD光盘1张)(年,经典再现!) 罗云彬 著 ISBN 978-7-121-20759-4 2013年7月出版 定价:99.00元 756页 1 ...
- 利用钩子函数来捕捉键盘响应的windows应用程序
一:引言: 你也许一直对金山词霸的屏幕抓词的实现原理感到困惑,你也许希望将你的键盘,鼠标的活动适时的记录下来,甚至你想知道木马在windows操作系统是怎样进行木马dll的加载的…..其实这些都是用到 ...
- 《windows核心编程系列》十八谈谈windows钩子
windows应用程序是基于消息驱动的.各种应用程序对各种消息作出响应从而实现各种功能. windows钩子是windows消息处理机制的一个监视点,通过安装钩子能够达到监视指定窗体某种类型的消息的功 ...
- 【windows核心编程】系统消息与自定义钩子(Hook)使用
一.HOOk Hook是程序设计中最为灵活多变的技巧之一,在windows下,Hook有两种含义: 1.系统提供的消息Hook机制 2.自定义的Hook编程技巧 其中,由系统提供的消息钩子机制是由一系 ...
- VC++开发Windows系统全局钩子
本文的大部分内容属于对一篇网文的实践与练习,同时参考的还有一本书,在此向网文与书的作者表示敬意. 这个程序是一个windows系统键盘监控程序,随着开机自动启动,可以监控系统中各用户的键盘,并将按键记 ...
- Windows环境下32位汇编语言程序设计(典藏版)
<Windows环境下32位汇编语言程序设计(典藏版) > 基本信息 作者: 罗云彬 出版社:电子工业出版社 ISBN:9787121207594 上架时间:2013-7-8 出版日期:2 ...
随机推荐
- NHibernate中使用memcache二级缓存
在NHibernate中使用memcache二级缓存 一.Windows下安装Memcache 1. 下载 http://jehiah.cz/projects/memcached-win32/ ...
- Grunt使用入门
Grunt使用入门 (by vczero) 一.前言 项目中一直在使用Grunt,只是对Grunt的基本使用,却未系统的总结过.为什么要构建工具?一句话:自动化.对于需要反复重复的任务,例如压缩(mi ...
- .NET MVC4 实训记录之二(扩展WebSecurity模型下的UserProfile表)
使用VS2013创建MVC4项目后,自动生成的代码中默认使用WebSecurity模型创建用户管理,生成以下数据库:
- AngularJS Change Path Without Reloading
To change path URL with AngularJS, $location.path() is passed the new URL as a parameter, and the pa ...
- Python语言在企业级应用上的十大谬误
英文原文:https://www.paypal-engineering.com/2014/12/10/10-myths-of-enterprise-python/ 翻译原文:http://www.os ...
- Shards
跟我一起云计算(5)——Shards 什么是sharding Sharding的基本思想就要把一个数据库切分成多个部分放到不同的数据库 (server)上,从而缓解单一数据库的性能问题.不太严格的 ...
- 使用Entity Framework 4进行代码优先开发
[原文地址]Code-First Development with Entity Framework 4 .NET 4随带发布了一个改进版的Entity Framework(EF)- 一个位于Sy ...
- jquery实现城市选择器效果(二级联动)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- ios开发实践之UIDatePicker(已对之前无法解决的问题做了解答)
需求:要做一个生日选择的控件,但除了选择之外还需要自定义几个控件,跟生日选择控件组合一起. 做法:自定义了一个UIImageView,并且作为背景.在这个背景view上再添加其他button和时间选择 ...
- node.js系列笔记之fs模块《二》
一:感触 最近工作比较忙,感觉也比较多,因为工作上的不顺利,再加上加班比较多,所以最近心情不是很好,再加上英语能力差到不行,所以最近半个月学习进度也比较慢, 但还是告诉自己每天都坚持学一点,即使今天心 ...