Permalink
Browse files

Merge branch 'hotfix/2688'

Close #2688
  • Loading branch information...
weierophinney committed Oct 8, 2012
2 parents 46d786f + 0f6e254 commit f430f3192083f30e42ce59471247694d87d924ea
@@ -18,16 +18,17 @@
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Update;
use Zend\Db\TableGateway\Exception;
+use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerInterface;
+use Zend\EventManager\EventsCapableInterface;
/**
* @category Zend
* @package Zend_Db
* @subpackage TableGateway
*/
-class EventFeature extends AbstractFeature
+class EventFeature extends AbstractFeature implements EventsCapableInterface
{
-
/**
* @var EventManagerInterface
*/
@@ -42,37 +43,103 @@ class EventFeature extends AbstractFeature
* @param EventManagerInterface $eventManager
* @param EventFeature\TableGatewayEvent $tableGatewayEvent
*/
- public function __construct(EventManagerInterface $eventManager, EventFeature\TableGatewayEvent $tableGatewayEvent)
- {
- $this->eventManager = $eventManager;
+ public function __construct(
+ EventManagerInterface $eventManager = null,
+ EventFeature\TableGatewayEvent $tableGatewayEvent = null
+ ) {
+ $this->eventManager = ($eventManager instanceof EventManagerInterface)
+ ? $eventManager
+ : new EventManager;
+
+ $this->eventManager->setIdentifiers(array(
+ 'Zend\Db\TableGateway\TableGateway',
+ ));
+
$this->event = ($tableGatewayEvent) ?: new EventFeature\TableGatewayEvent();
}
+ /**
+ * Retrieve composed event manager instance
+ *
+ * @return EventManagerInterface
+ */
+ public function getEventManager()
+ {
+ return $this->eventManager;
+ }
+
+ /**
+ * Retrieve composed event instance
+ *
+ * @return EventFeature\TableGatewayEvent
+ */
+ public function getEvent()
+ {
+ return $this->event;
+ }
+
+ /**
+ * Initialize feature and trigger "preInitialize" event
+ *
+ * Ensures that the composed TableGateway has identifiers based on the
+ * class name, and that the event target is set to the TableGateway
+ * instance. It then triggers the "preInitialize" event.
+ *
+ * @return void
+ */
public function preInitialize()
{
+ if (get_class($this->tableGateway) != 'Zend\Db\TableGateway\TableGateway') {
+ $this->eventManager->addIdentifiers(get_class($this->tableGateway));
+ }
+
$this->event->setTarget($this->tableGateway);
$this->event->setName(__FUNCTION__);
$this->eventManager->trigger($this->event);
}
+ /**
+ * Trigger the "postInitialize" event
+ *
+ * @return void
+ */
public function postInitialize()
{
- $this->event->setTarget($this->tableGateway);
$this->event->setName(__FUNCTION__);
$this->eventManager->trigger($this->event);
}
+ /**
+ * Trigger the "preSelect" event
+ *
+ * Triggers the "preSelect" event mapping the following parameters:
+ * - $select as "select"
+ *
+ * @param Select $select
+ * @return void
+ */
public function preSelect(Select $select)
{
- $this->event->setTarget($this->tableGateway);
$this->event->setName(__FUNCTION__);
$this->event->setParams(array('select' => $select));
$this->eventManager->trigger($this->event);
}
+ /**
+ * Trigger the "postSelect" event
+ *
+ * Triggers the "postSelect" event mapping the following parameters:
+ * - $statement as "statement"
+ * - $result as "result"
+ * - $resultSet as "result_set"
+ *
+ * @param StatementInterface $statement
+ * @param ResultInterface $result
+ * @param ResultSetInterface $resultSet
+ * @return void
+ */
public function postSelect(StatementInterface $statement, ResultInterface $result, ResultSetInterface $resultSet)
{
- $this->event->setTarget($this->tableGateway);
$this->event->setName(__FUNCTION__);
$this->event->setParams(array(
'statement' => $statement,
@@ -82,17 +149,35 @@ public function postSelect(StatementInterface $statement, ResultInterface $resul
$this->eventManager->trigger($this->event);
}
+ /**
+ * Trigger the "preInsert" event
+ *
+ * Triggers the "preInsert" event mapping the following parameters:
+ * - $insert as "insert"
+ *
+ * @param Insert $insert
+ * @return void
+ */
public function preInsert(Insert $insert)
{
- $this->event->setTarget($this->tableGateway);
$this->event->setName(__FUNCTION__);
$this->event->setParams(array('insert' => $insert));
$this->eventManager->trigger($this->event);
}
+ /**
+ * Trigger the "postInsert" event
+ *
+ * Triggers the "postInsert" event mapping the following parameters:
+ * - $statement as "statement"
+ * - $result as "result"
+ *
+ * @param StatementInterface $statement
+ * @param ResultInterface $result
+ * @return void
+ */
public function postInsert(StatementInterface $statement, ResultInterface $result)
{
- $this->event->setTarget($this->tableGateway);
$this->event->setName(__FUNCTION__);
$this->event->setParams(array(
'statement' => $statement,
@@ -101,17 +186,35 @@ public function postInsert(StatementInterface $statement, ResultInterface $resul
$this->eventManager->trigger($this->event);
}
+ /**
+ * Trigger the "preUpdate" event
+ *
+ * Triggers the "preUpdate" event mapping the following parameters:
+ * - $update as "update"
+ *
+ * @param Update $update
+ * @return void
+ */
public function preUpdate(Update $update)
{
- $this->event->setTarget($this->tableGateway);
$this->event->setName(__FUNCTION__);
$this->event->setParams(array('update' => $update));
$this->eventManager->trigger($this->event);
}
+ /**
+ * Trigger the "postUpdate" event
+ *
+ * Triggers the "postUpdate" event mapping the following parameters:
+ * - $statement as "statement"
+ * - $result as "result"
+ *
+ * @param StatementInterface $statement
+ * @param ResultInterface $result
+ * @return void
+ */
public function postUpdate(StatementInterface $statement, ResultInterface $result)
{
- $this->event->setTarget($this->tableGateway);
$this->event->setName(__FUNCTION__);
$this->event->setParams(array(
'statement' => $statement,
@@ -120,23 +223,40 @@ public function postUpdate(StatementInterface $statement, ResultInterface $resul
$this->eventManager->trigger($this->event);
}
+ /**
+ * Trigger the "preDelete" event
+ *
+ * Triggers the "preDelete" event mapping the following parameters:
+ * - $delete as "delete"
+ *
+ * @param Delete $delete
+ * @return void
+ */
public function preDelete(Delete $delete)
{
- $this->event->setTarget($this->tableGateway);
$this->event->setName(__FUNCTION__);
$this->event->setParams(array('delete' => $delete));
$this->eventManager->trigger($this->event);
}
+ /**
+ * Trigger the "postDelete" event
+ *
+ * Triggers the "postDelete" event mapping the following parameters:
+ * - $statement as "statement"
+ * - $result as "result"
+ *
+ * @param StatementInterface $statement
+ * @param ResultInterface $result
+ * @return void
+ */
public function postDelete(StatementInterface $statement, ResultInterface $result)
{
- $this->event->setTarget($this->tableGateway);
$this->event->setName(__FUNCTION__);
$this->event->setParams(array(
'statement' => $statement,
'result' => $result,
));
$this->eventManager->trigger($this->event);
}
-
}
@@ -44,7 +44,7 @@ class TableGatewayEvent implements EventInterface
*/
public function getName()
{
- return get_class($this->target) . '.' . $this->name;
+ return $this->name;
}
/**
Oops, something went wrong.

0 comments on commit f430f31

Please sign in to comment.