PHP code example of wegnermedia / event-manager

1. Go to this page and download the library: Download wegnermedia/event-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wegnermedia / event-manager example snippets


'aliases' => [
    'EventManager' => 'Wegnermedia\EventManager\Facade'
]



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
	}
}



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();