Phergie_Event_Handler::addEvent PHP Method

addEvent() public method

Adds an event to the queue.
public addEvent ( Phergie_Plugin_Abstract $plugin, string $type, array $args = [] ) : Phergie_Event_Handler
$plugin Phergie_Plugin_Abstract Plugin originating the event
$type string Event type, corresponding to a Phergie_Event_Command::TYPE_* constant
$args array Optional event arguments
return Phergie_Event_Handler Provides a fluent interface
    public function addEvent(Phergie_Plugin_Abstract $plugin, $type, array $args = array())
    {
        if (!defined('Phergie_Event_Request::TYPE_' . strtoupper($type))) {
            throw new Phergie_Event_Exception('Unknown event type "' . $type . '"', Phergie_Event_Exception::ERR_UNKNOWN_EVENT_TYPE);
        }
        $event = new Phergie_Event_Command();
        $event->setPlugin($plugin)->setType($type)->setArguments($args);
        $this->events[] = $event;
        return $this;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Tests that attempting to add an event to the handler with an invalid
  * type results in an exception.
  *
  * @return void
  */
 public function testAddEventWithInvalidType()
 {
     $type = 'foo';
     try {
         $this->events->addEvent($this->plugin, $type);
         $this->fail('Expected exception was not thrown');
     } catch (Phergie_Event_Exception $e) {
         if ($e->getCode() != Phergie_Event_Exception::ERR_UNKNOWN_EVENT_TYPE) {
             $this->fail('Unexpected exception code ' . $e->getCode());
         }
     }
 }
All Usage Examples Of Phergie_Event_Handler::addEvent