Package Data | |
---|---|
Maintainer Username: | wegnermedia |
Maintainer Contact: | stefan@wegnermedia.de (Stefan Wegner) |
Package Create Date: | 2014-07-21 |
Package Last Update: | 2014-07-21 |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2024-11-19 03:01:55 |
Package Statistics | |
---|---|
Total Downloads: | 14 |
Monthly Downloads: | 2 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This Package gives you an easy way to raise and dispatch events.
Per usual, install Commander through Composer.
"require": {
"wegnermedia/event-manager": "dev-master"
}
Next, add the facade app/config/app.php
.
'aliases' => [
'EventManager' => 'Wegnermedia\EventManager\Facade'
]
And now build something awesome.
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();
Done!