Add "banCreate" event

This commit is contained in:
Dmitriy Simushev 2014-10-21 11:43:10 +00:00
parent ada83c629a
commit 6263f3a2f4
2 changed files with 17 additions and 0 deletions

View File

@ -19,6 +19,9 @@
namespace Mibew; namespace Mibew;
use Mibew\EventDispatcher\EventDispatcher;
use Mibew\EventDispatcher\Events;
/** /**
* A class that represents Ban entity. * A class that represents Ban entity.
*/ */
@ -193,6 +196,8 @@ class Ban
/** /**
* Save the ban to the database. * Save the ban to the database.
*
* Triggers {@link \Mibew\EventDispatcher\Events::BAN_CREATE} event.
*/ */
public function save() public function save()
{ {
@ -211,6 +216,9 @@ class Ban
) )
); );
$this->id = $db->insertedId(); $this->id = $db->insertedId();
$args = array('ban' => $this);
EventDispatcher::getInstance()->triggerEvent(Events::BAN_CREATE, $args);
} else { } else {
// Update existing ban // Update existing ban
$db->query( $db->query(

View File

@ -24,6 +24,15 @@ namespace Mibew\EventDispatcher;
*/ */
final class Events final class Events
{ {
/**
* A ban is created.
*
* This event is triggered after a ban has been created. An associative
* array with the following items is passed to the event handlers:
* - "ban": an instance of {@link \Mibew\Ban} class.
*/
const BAN_CREATE = 'banCreate';
/** /**
* Cron is run. * Cron is run.
* *