예제 #1
0
 /**
  * Determines if we're dealing with the required Resource
  * before dispatching to actions
  *
  * @param Event $e
  * @return mixed|void
  */
 public function dispatch(Event $e)
 {
     switch ($e->getName()) {
         case 'create.post':
         case 'update.post':
         case 'patch.post':
             /**
              * Redirect client to newly created resource
              */
             $controller = $e->getTarget();
             if ($controller instanceof ResourceController) {
                 $resource = $controller->getResource();
                 if ($resource instanceof Resource) {
                     $model = $e->getParam('resource');
                     if ($model instanceof ResourceJsonModel) {
                         $object = $model->getPayload();
                         if ($object instanceof BackendResourceInterface) {
                             $e->stopPropagation(true);
                             $response = $controller->redirect()->toRoute('api/default', array('resource' => $resource->getIdentifier(), 'id' => $object->getId()));
                             return $response;
                             //@TODO remove until fixed CORS redirect
                         }
                     }
                 }
             }
             break;
     }
 }
예제 #2
0
 /**
  * Emit handlers matching the current identifier found in the static handler
  * 
  * @param  callback $callback 
  * @param  Event $event 
  * @param  ResponseCollection $responses 
  * @return ResponseCollection
  */
 protected function triggerStaticHandlers($callback, Event $event, ResponseCollection $responses)
 {
     if (!($staticConnections = $this->getStaticConnections())) {
         return $responses;
     }
     $identifiers = (array) $this->identifier;
     foreach ($identifiers as $id) {
         if (!($handlers = $staticConnections->getHandlers($id, $event->getName()))) {
             continue;
         }
         foreach ($handlers as $handler) {
             $responses->push(call_user_func($handler->getCallback(), $event));
             if ($event->propagationIsStopped()) {
                 $responses->setStopped(true);
                 break;
             }
             if (call_user_func($callback, $responses->last())) {
                 $responses->setStopped(true);
                 break;
             }
         }
     }
     return $responses;
 }
 /**
  * @param Event $e
  */
 public function listen(Event $e)
 {
     $this->caughtEvents[] = $e->getName();
     array_unique($this->caughtEvents);
 }