wegnermedia / event-manager
该软件包的最新版本(1.0.0)没有可用的许可证信息。
Laravel的简单事件管理工具
1.0.0
2014-07-21 19:43 UTC
Requires
- php: >=5.4.0
- illuminate/support: 4.2.*
This package is not auto-updated.
Last update: 2024-09-24 02:27:54 UTC
README
本软件包为您提供了简单的方式来创建和分发事件。
安装
按照常规方法,通过Composer安装Commander。
"require": { "wegnermedia/event-manager": "dev-master" }
接下来,添加facade app/config/app.php
。
'aliases' => [ 'EventManager' => 'Wegnermedia\EventManager\Facade' ]
现在开始构建一些令人惊叹的东西。
用法
app/controllers/CartController.php
<?php class CartController extends ShopController { /** * Add Item to Cart. * * @return Response */ public function addItem() { $inputs = Input::all(); // Validation goes here ... $command = new AddItemToCartCommand($inputs); $result = Commander::execute($command); EventManager::dispatch(); // ... create the Response } }
app/Shop/Cart/AddItemToCartCommandHandler.php
<?php use Wegnermedia\Commander\CommandHandlerInterface; class AddItemToCartCommandHandler implements CommandHandlerInterface { /** * Handle the command * * @return mixed */ public function handle($command) { // some awesome stuff ... // Raise and event with the Namespace of "Shop" // Event::listen('whenShop*', ... ); EventManager::raise( new AddingItemToCartWasSuccessfulEvent($cart, $item), 'Shop' ) // ... create the Response } }
有时你可能想查看堆栈
$stack = EventManager::stack();
完成!