Beispiel #1
0
 /**
  * @param mixed $method
  * @param array $arguments
  * @param array $eventParameters
  * @return mixed
  */
 protected function getResource($method, $arguments, array $eventParameters = array())
 {
     if ($this->dispatcher) {
         $event = new ServiceEvent();
         $event->setService($this)->setRequestMethod($method)->setRequestParameters($arguments)->setParameters($eventParameters);
         $this->dispatcher->dispatch(OrchestratorEvents::SERVICE_FETCH_PRE, $event);
         if ($event->isResourceSet()) {
             return $event->getResource();
         }
     }
     try {
         $resource = $this->fetchResource($method, $arguments);
         if ($this->dispatcher) {
             $event->setResource($resource);
             $this->dispatcher->dispatch(OrchestratorEvents::SERVICE_FETCH_POST, $event);
         }
     } catch (\Exception $e) {
         $resource = null;
         if ($this->dispatcher) {
             $errorEvent = new ServiceErrorEvent($e);
             $errorEvent->setService($this)->setRequestMethod($method)->setRequestParameters($arguments)->setParameters($eventParameters);
             $this->dispatcher->dispatch(OrchestratorEvents::SERVICE_FETCH_ERROR, $errorEvent);
             if ($errorEvent->isSilent()) {
                 $e = null;
             } else {
                 $e = $errorEvent->getException();
             }
         }
         if ($e) {
             throw new Exception($e->getMessage(), 500, $e);
         }
     }
     return $resource;
 }
 protected function stopProfilingFromError(ServiceErrorEvent $event)
 {
     if ($this->activeProfileEvent) {
         $exception = $event->getOriginalException();
         $this->profiles[$event->getService()->getName()][$this->counter]['error'] = array('code' => $exception->getCode(), 'message' => $exception->getMessage(), 'class' => get_class($exception));
         $this->stopProfiling($event);
     }
 }