1. [文件] class.Dispatcher.php ~ 967B     下载(9)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
session_start();
require_once('class.Handler_Event.php');
header("Content-type:text/html; charset=utf-8");
 
class Dispatcher{
    private $handle;
     
    function __construct($event_handle){
        $this->handle=$event_handle;
    }
     
    function handle_the_event(){
        $name="handler_$this->handle";
        if(class_exists("$name")){
            $handler_obj=new $name($this->handle);
            $response=$handler_obj->secure_handler();
            return $response;
        }else{
            echo "I can't handle this!";
        }
    }
}
?>
<html>
<head><title>Secure,Event Driven Record Viewer!</title></head>
 
<body>
<form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post">
   <input type="submit" name="event" value="View">
   <input type="submit" name="event" value="Edit">
</form>
</body>
</html>
<?php
function handle(){
    $event=$_POST['event'];
    $do=new Dispatcher($event);
    $do->handle_the_event();
}
 
$_SESSION['name']="Wangzy";
 
if(isset($_POST['event'])) handle();
?>

2. [文件] class.Handler_Event.php ~ 1KB     下载(6)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
//Event parent
abstract class Event_Handler{
    function dbconn(){
        $link_id=mysql_connect("localhost","root","root");
        mysql_select_db("mytest",$link_id);
        mysql_query("set names utf8",$link_id);
        return $link_id;
    }
     
    abstract function handled_event();
    abstract function secure_handler();
}
 
//View Event
class Handler_View extends Event_Handler{
    private $handle;
     
    function __construct($event_handle){
        $this->handle=$event_handle;
    }
     
    function handled_event(){
        echo "The event, $this->handle, is now handled.<br>
        It is ,I promise!<br><br>
        Your records are as follows:<br><br>";
         
        $id=parent::dbconn();
        $result=mysql_query("select * from table01",$id);
        while($row=mysql_fetch_array($result)){
            echo "Numbers:".$row['number']."\tName:".$row['name']."<br>";
        }
    }
     
    function secure_handler(){
        if($_SESSION['name']=="Wangzy"){
            $this->handled_event();
        }else{
            echo "Sorry {$_SESSION['name']} you are not authorized!";
        }
    }
}
 
//Edit Event
class Handler_Edit extends Event_Handler{
    private $handle;
     
    function __construct($event_handle){
        $this->handle=$event_handle;
    }
     
    function handled_event(){
        echo "This is event $this->handle, which is now handled -no kidding!<br>";
    }
     
    function secure_handler(){
        $this->handled_event();
    }
}

php事件驱动的更多相关文章

  1. C++ 事件驱动型银行排队模拟

    最近重拾之前半途而废的C++,恰好看到了<C++ 实现银行排队服务模拟>,但是没有实验楼的会员,看不到具体的实现,正好用来作为练习. 模拟的是银行的排队叫号系统,所有顾客以先来后到的顺序在 ...

  2. Node学习笔记(二):事件驱动

    接触Node,提得最多的可能就是回调,异步非阻塞处理,思前想后,JavaScript从前端语言过渡到服务器端,最大的劣势可能就是线程,当然这方面的不足现在也被慢慢弥补起来了(很多第三方的npm包可供下 ...

  3. IDDD 实现领域驱动设计-CQRS(命令查询职责分离)和 EDA(事件驱动架构)

    上一篇:<IDDD 实现领域驱动设计-SOA.REST 和六边形架构> 阅读目录: CQRS-命令查询职责分离 EDA-事件驱动架构 Domin Event-领域事件 Long-Runni ...

  4. Reactor事件驱动的两种设计实现:面向对象 VS 函数式编程

    Reactor事件驱动的两种设计实现:面向对象 VS 函数式编程 这里的函数式编程的设计以muduo为例进行对比说明: Reactor实现架构对比 面向对象的设计类图如下: 函数式编程以muduo为例 ...

  5. 输入事件驱动---evdev_handler的大致实现流程(修整版)

    一.input输入子系统框架 下 图是input输入子系统框架,输入子系统由输入子系统核心层(input core),驱动层和事件处理层(Event Handler)三部分组成.一个输入事件,比如滑动 ...

  6. NodeJS中的异步I/O、事件驱动

    nodejs的主要特点是单线程.异步I/O.事件驱动.让我们先大概了解一下这些名词的意思. 单线程 单线程是任务按照顺序执行的,并且每次只执行一个任务,只有前面的任务执行完成以后,后面的任务才执行.在 ...

  7. 事件驱动之Twsited异步网络框架

    在这之前先了解下什么是事件驱动编程 传统的编程是如下线性模式的: 开始--->代码块A--->代码块B--->代码块C--->代码块D--->......--->结 ...

  8. Python交互式编程导论----事件驱动编程

    传统的编程是如下线性模式的: 开始--->代码块A--->代码块B--->代码块C--->代码块D--->......--->结束 每一个代码块里是完成各种各样事情 ...

  9. [.NET领域驱动设计实战系列]专题七:DDD实践案例:引入事件驱动与中间件机制来实现后台管理功能

    一.引言 在当前的电子商务平台中,用户下完订单之后,然后店家会在后台看到客户下的订单,然后店家可以对客户的订单进行发货操作.此时客户会在自己的订单状态看到店家已经发货.从上面的业务逻辑可以看出,当用户 ...

  10. ENode 1.0 - 事件驱动架构(EDA)思想的在框架中如何体现

    开源地址:https://github.com/tangxuehua/enode 上一篇文章,我给大家分享了我的一个基于DDD以及EDA架构的框架enode,但是只是介绍了一个大概.接下来我准备用很多 ...

随机推荐

  1. 《高性能Javascript》读书笔记-4

    第四章 算法和流程控制 代码组织结构和解决具体问题的思路是影响代码性能的主要因素 循环处理是最常见的编程模式之一,也是提高性能的关注点之一 循环分四种:标准for循环 ; i < Things. ...

  2. 【转】js获取url传递参数

    <Script language="javascript">var Request = new Object();Request = GetRequest();var ...

  3. ES6 相关资料

    Configuring Babel 6 Setting up ES6

  4. json_encode转成带 花括号的{ } 和 中括号的[ ] 2种 形式 json数据

    //提交多个出差人员 .命名为数组 name="apply_members[] " //php接收到数据 为 数组  $aa = array('0'=>11,'1'=> ...

  5. 4、Math对象

    1.编辑html页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// ...

  6. ZUFE(周赛) 2326 交换字母(STL)

    Time Limit: 1 Sec  Memory Limit: 128 MB Description 有一个长度为n的字符串(只包含小写字母),操作m次,每次操作交换两个字母,输出最终字符串. In ...

  7. MVC3+EF4.1学习系列(十)----MVC+EF处理树形结构

    通过前几篇文章 我们处理了 一对一, 一对多,多对多关系 很好的发挥了ORM框架的做用 但是 少说了一种 树形结构的处理, 而这种树形关系 我们也经常遇到,常见的N级类别的处理, 以及经常有数据与类别 ...

  8. yum安装memcache,mongo扩展以及python的mysql模块安装

    //启动memcached/usr/local/memcached/bin/memcached -d -c 10240 -m 1024 -p 11211 -u root/usr/local/memca ...

  9. PHP ServerPush (推送) 技术

    用来代替ajax的请求 转自:http://blog.163.com/bailin_li/blog/static/17449017920124811524364/ 需求: 我想做个会员站内通知的功能. ...

  10. 4.编写Java应用程序。首先,定义一个时钟类——Clock,它包括三个int型 成员变量分别表示时、分、秒,一个构造方法用于对三个成员变量(时、分、秒) 进行初始化,还有一个成员方法show()用于显示时钟对象的时间。其次,再定义 一个主类——TestClass,在主类的main方法中创建多个时钟类的对象,使用这 些对象调用方法show()来显示时钟的时间。

    Clock package com.hanqi.test; public class Clock { int hour,minute,second; Clock(int h,int m,int s) ...