Beispiel #1
0
 public function testEvent()
 {
     $event = new Event('test');
     $this->assertSame('test', $event->getType(), 'Event does not return the type that was set');
     $this->assertSame(array(), $event->getData(), 'Not an empty array is returned for the data when data was not set.');
     $testArray = array('key' => 'value');
     $event = new Event('test', $testArray);
     $this->assertSame('test', $event->getType(), 'Event does not return the type that was set');
     $this->assertSame($testArray, $event->getData(), 'Not the set array is returned for the data.');
 }
Beispiel #2
0
 /**
  * Handles an event
  *
  * @param \YapepBase\Event\Event $event   The dispatched event.
  *
  * @return void
  */
 public function handleEvent(Event $event)
 {
     switch ($event->getType()) {
         case Event::TYPE_APPLICATION_BEFORE_OUTPUT_SEND:
             $this->render();
             break;
     }
 }
Beispiel #3
0
 /**
  * Handles the application start and finish events to load and save the session.
  *
  * @param \YapepBase\Event\Event $event   The event.
  *
  * @return void
  *
  * @see YapepBase\Event.IEventHandler::handleEvent()
  */
 public function handleEvent(Event $event)
 {
     switch ($event->getType()) {
         case Event::TYPE_APPLICATION_BEFORE_CONTROLLER_RUN:
             $this->loadSession();
             break;
         case Event::TYPE_APPLICATION_AFTER_CONTROLLER_RUN:
             $this->saveSession();
             break;
     }
 }
 /**
  * Raises an event
  *
  * @param Event $event   The event to raise.
  *
  * @return void
  */
 public function raise(Event $event)
 {
     $type = $event->getType();
     $this->lastTimesForEventTypes[$type] = microtime(true);
     if (!empty($this->eventHandlers[$type])) {
         foreach ($this->eventHandlers[$type] as $handler) {
             /** @var \YapepBase\Event\IEventHandler $handler */
             $handler->handleEvent($event);
         }
     }
 }