/** * @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; }
public function onServicePostFetch(ServiceEvent $event) { if (!$this->enabled) { return; } $params = $event->getParameters(); $cacheKey = isset($params['cache_key']) ? $event->getService()->getName() . '_' . $params['cache_key'] : false; $lifetime = isset($params['cache_lifetime']) ? $params['cache_lifetime'] : self::DEFAULT_LIFETIME; if ($cacheKey && $lifetime) { $this->cache->save($cacheKey, $event->getResource(), $lifetime); } }
public function onServicePreFetch(ServiceEvent $event) { if (!$event->isResourceSet()) { $this->activeProfileEvent = $this->startProfiling($event); } }