/**
  * Dispatch an event
  *
  * @param  string     $eventName
  * @param  Event|null $event
  * @return Event
  */
 public function dispatch($eventName, Event $event = null)
 {
     // configure event
     if (null === $event) {
         $event = new Event();
     }
     $event->configure($eventName, $this);
     // are there any matching listeners or callbacks?
     if (!isset($this->eventMap[$eventName])) {
         // nothing to call
         return $event;
     }
     // there is at least one listener or callback
     $event->setHandled(true);
     // sort event map?
     if (!$this->sortMap[$eventName]) {
         $this->sortEventMapFor($eventName);
         $this->sortMap[$eventName] = true;
     }
     // dispatch
     foreach ($this->eventMap[$eventName] as $eventEntry) {
         // invoke handler
         if (0 === $eventEntry[0]) {
             $eventEntry[2]->{$eventEntry[3]}($event);
         } else {
             call_user_func($eventEntry[2], $event);
         }
         // callback
         // check propagation
         if ($event->isPropagationStopped()) {
             break;
         }
     }
     // return
     return $event;
 }
 public function testSetHandled()
 {
     $this->object->setHandled('special');
     $this->assertEquals('special', $this->object->isHandled());
 }