#AnnEvents for Kdyby Events
AnnEvents expanding Kdyby Events. Adds the ability to create events by using annotations.
The best way to install DIPcom/AnnEvents is using Composer:
$ composer require dipcom/annevents
extensions:
events: Kdyby\Events\DI\EventsExtension
doctrine: Kdyby\Doctrine\DI\OrmExtension
annevents: DIPcom\AnnEvents\DI\AnnEventsExtension
####Annotations
@Event()
Event class@Listener()
Listener event@On()
Property interconnection pointTarget(listener="class", referenced="property")
Target listener and his parameterslistener="class"
andreferenced="property"
Before using AnnEvents docs Kdyby Events.
####Create listener class
namespace App\Events;
use Nette;
use DIPcom\AnnEvents\Mapping as EV;
/**
* @EV\Listener()
*/
class Order extends Nette\Object{
/**
* @EV\On()
*/
public $onCreateOrder = array();
/**
* @see \App\Models\Order::createOrder()
* @param array $items
*/
public function pushBillItem(array $items){
$this->onPushBillItem($items, $this);
}
}
####Create event class
namespace App\Events;
use Nette;
use DIPcom\AnnEvents\Mapping as EV;
use App\Events\Order;
/**
* @EV\Event()
*/
class OrderEvent extends Nette\Object{
/**
* @EV\On()
*/
public $onCreateOrder = array();
/**
* @EV\Targe(listener="App\Events\Order", referenced="onCreateOrder")
*/
public function myAction(array $items, Order $listener){
dump($items);
}
}