本篇文章介绍如何单独使用symfony的event-dispatcher组件
思路是 创建个单独的事件处理类 以及 该事件的订阅者类 通过调度者触发
使用订阅者 subscriber
配置文件系统结构
1 | composer require symfony/event-dispatcher |
index.php
1 | <?php |
CustomerEvent.php
1 | <?php |
CustomerSubscriber.php
1 | <?php |
访问index.php

使用监听者 listener
创建 CustomerListener.php
1 | # src/EventListener/CustomerListener.php |
index.php 使用
1 | # index.php |
访问index.php

具体信息请参考官方文档 symfony document