1 Star 0 Fork 65

MyFork/MasterLab

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
event_test.php 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
<?php
echo " ?\"ddd\"><><>\n";
echo htmlspecialchars(" ?\"ddd\"><><>");
die;
require './app/globals.php';
use Symfony\Contracts\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class Order
{
public $no = '';
public $status = '';
public function __construct($no, $status)
{
$this->no =$no;
$this->status = $status;
}
}
/**
* The order.placed event is dispatched each time an order is created
* in the system.
*/
class OrderPlacedEvent extends Event
{
const NAME = 'order.placed';
protected $order;
public function __construct(Order $order)
{
$this->order = $order;
}
public function getOrder()
{
return $this->order;
}
}
class StoreSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'kernel.response'=> [
['onKernelResponsePre', 10],
['onKernelResponsePost', -10],
],
OrderPlacedEvent::NAME => 'onStoreOrder',
];
}
public function onKernelResponsePre(Event $event)
{
// ...
var_dump('onKernelResponsePre');
}
public function onKernelResponsePost(Event $event)
{
// ...
var_dump('onKernelResponsePost');
}
public function onStoreOrder(OrderPlacedEvent $event)
{
// ...
var_dump($event);
var_dump('onStoreOrder');
}
}
$dispatcher = new EventDispatcher();
// the order is somehow created or retrieved
// ...
$subscriber = new StoreSubscriber();
$dispatcher->addSubscriber($subscriber);
// creates the OrderPlacedEvent and dispatches it
$order = new Order(time(), mt_rand(1,10));
$event = new OrderPlacedEvent($order);
$dispatcher->dispatch($event, OrderPlacedEvent::NAME);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/my_forks/MasterLab.git
git@gitee.com:my_forks/MasterLab.git
my_forks
MasterLab
MasterLab
master

搜索帮助