symfony2中的EventDispatcher的项目使用
来源:互联网 发布:淘宝推广预算 编辑:程序博客网 时间:2024/05/13 18:26
项目使用:
$dispatcher = new EventDispatcher();$listener = new InventoryEventListener();$dispatcher->addListener('add_stock_history.action', array($listener,'addStockHistory'));$event = new InventoryEvent($record, $this->entityManager, $targetUser);$dispatcher->dispatch('add_stock_history.action', $event);
//inventoryEvent.php
class InventoryEventListener{ public function addStockHistory(InventoryEvent $event) { $record = $event->getRecord(); $entityManager = $event->getEntityManager(); $targetUser = $event->getTargetUser(); $operatorName = $targetUser->getName(); $inventoryQuantity = $record->getInventoryQuantity(); $operatorId = $targetUser->getId(); if ($record->getQuantity() != $inventoryQuantity) { $stockHistory = new StockHistory(); $date = date('Y-m-d'); $description = "[$date] $operatorName "; // 判断是盘存入库,还是盘存出库 if ($record->getQuantity() > $inventoryQuantity) { $stockHistory->setAction(StockHistory::INVENTORY_OUTBOUND); $description .= "盘存出库 "; } else { $stockHistory->setAction(StockHistory::INVENTORY_INBOUND); $description .= "盘存入库 "; } $quantity = $record->getQuantity(); $description .= $record->getGoodsName(); $description .= " "; $description .= $record->getMaterialSn(); $description .= " {$quantity} -> {$inventoryQuantity}"; $stockHistory->setQuantityBefore($record->getQuantity()); $stockHistory->setQuantityAfter($inventoryQuantity); $stockHistory->setMaterialId($record->getMaterialId()); $stockHistory->setOperatorId($operatorId); $stockHistory->setDescription($description); $entityManager->persist($stockHistory); } }}//inventoryEvent.php
class InventoryEvent extends Event{ protected $record; protected $entityManager; protected $targetUser; public function __construct($record, ObjectManager $entityManager ,$targetUser) { $this->record = $record; $this->entityManager = $entityManager; $this->targetUser = $targetUser; } public function getRecord() { return $this->record; } public function getEntityManager() { return $this->entityManager; } public function getTargetUser() { return $this->targetUser; }}
0 0
- symfony2中的EventDispatcher的项目使用
- symfony2 EventDispatcher组件使用
- 使用 Netbeans 创建 Symfony2 项目
- symfony2项目中的单测实例
- Symfony2 中event的使用
- 使用PHP composer创建Symfony2框架项目
- eventDispatcher 简单使用
- 关于EventDispatcher的讨论
- symfony2 knp-menu-bundle 的使用
- symfony2中的经典查询
- Symfony2函数使用
- Symfony2中使用AngularJS
- Symfony2 安装与使用
- 使用 Symfony2 的组件创建自己的 PHP 框架
- Symfony2的Nginx配置
- Symfony2
- Symfony2
- EventDispatcher的比喻(转自AS3CN)
- Android gradle 入门
- Android4.2锁屏流程【Android锁屏解析三】
- mybatis使用group by返回sum,count数据
- oracle之 any、all 解析
- HDU 1166 线段树
- symfony2中的EventDispatcher的项目使用
- Hashtable与hashmap 比较
- unity3d模型制作规范
- UNIX - umask函数,创建文件模式屏蔽字
- 3626: [LNOI2014]LCA LCT
- Oracle数据库、实例、用户、表空间、角色基本概念和关系
- 转载---Linux vim配置及alias命令
- Android MVP Pattern
- 【Android】自定义ViewPager控制其页面切换速度