Example #1
0
 /**
  * Handle the event
  * 
  * @param  Event $e 
  * @return void
  */
 public function handle(EventInterface $e = null)
 {
     if (null === $e) {
         $e = new Event();
     }
     $pubsub = $this->getPubSub();
     $e->setPubSub($pubsub);
     $e->setStates($this->_states);
     // Figure this part out...
     $e->setResponse($pubsub->getResponse());
     // Closure to determine if state has changed
     $stateChanged = function () use($e) {
         return $e->isStateChanged();
     };
     routing:
     $e->markState();
     $pubsub->publishUntil($stateChanged, 'mvc.routing.pre', $e);
     if ($e->isStateChanged()) {
         goto switchState;
     }
     $pubsub->publishUntil($stateChanged, 'mvc.routing', $e);
     if ($e->isStateChanged()) {
         goto switchState;
     }
     $pubsub->publishUntil($stateChanged, 'mvc.routing.post', $e);
     if ($e->isStateChanged()) {
         goto switchState;
     }
     $e->setState('dispatching');
     dispatching:
     $e->markState();
     $pubsub->publishUntil($stateChanged, 'mvc.dispatching.pre', $e);
     if ($e->isStateChanged()) {
         goto switchState;
     }
     $pubsub->publishUntil($stateChanged, 'mvc.dispatching', $e);
     if ($e->isStateChanged()) {
         goto switchState;
     }
     $pubsub->publishUntil($stateChanged, 'mvc.dispatching.post', $e);
     if ($e->isStateChanged()) {
         goto switchState;
     }
     $e->setState('response');
     response:
     $e->markState();
     $pubsub->publishUntil($stateChanged, 'mvc.response.pre', $e);
     if ($e->isStateChanged()) {
         goto switchState;
     }
     $pubsub->publishUntil($stateChanged, 'mvc.response', $e);
     if ($e->isStateChanged()) {
         goto switchState;
     }
     $pubsub->publishUntil($stateChanged, 'mvc.response.post', $e);
     if ($e->isStateChanged()) {
         goto switchState;
     }
     return;
     error:
     $e->markState();
     $pubsub->publishUntil($stateChanged, 'mvc.error', $e);
     if ($e->isStateChanged()) {
         goto switchState;
     }
     goto response;
     switchState:
     switch ($e->getState()) {
         case 'routing':
             goto routing;
         case 'dispatching':
             goto dispatching;
         case 'response':
             goto response;
         case 'error':
             goto error;
         default:
             throw new StateException();
     }
 }