php代码
基于dialogbox1.0修改可自定义按钮及事件的弹出框插件,每个按钮可绑定单独的触发事件,并且能支持将弹出框作为一个表单来填入数据并获取
35
<?php
//EventUtils:
final class EventArgs {
}
interface EventHandler {
public function Invoke($Sender, EventArgs $E);
}
class Event {
private $EventHandlerList = array ();
public function AddEventHandler(EventHandler $EventHandler) {
$this->EventHandlerList[] = $EventHandler;
}
public function DeleteEventHandler(EventHandler $EventHandler) {
$Index = array_search($EventHandler, $this->EventHanlerList);
array_splice($this->EventHanlerList, $Index, 1);
}
public function Invoke($Sender, EventArgs $E) {
foreach ($this->EventHandlerList as $EventHandler) {
$EventHandler->Invoke($Sender, $E);
}
}
}
//Test Case:
class TestEventHandler implements EventHandler {
public function Invoke($Sender, EventArgs $E) {
// echo "Hello, ".$Sender;
}
}
TestEvent();
function TestEvent() {
$Event = new Event();
$EventHandler = new TestEventHandler();
$Event->AddEventHandler($EventHandler);
$Event->Invoke($Event, new EventArgs());
}
//Output:
//Hello, Object id #5ok.
?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号