/**
  * @param CleverAge\Orchestrator\Events\ServiceEvent
  */
 protected function stopProfiling(ServiceEvent $event)
 {
     if ($this->activeProfileEvent) {
         $this->activeProfileEvent->stop();
         $result = $event->getResource();
         if (is_array($result)) {
             $count = count($result);
         } elseif (is_object($result)) {
             $count = 1;
         } else {
             $count = 0;
         }
         $this->profiles[$event->getService()->getName()][$this->counter]['duration'] = $this->activeProfileEvent->getDuration();
         $this->profiles[$event->getService()->getName()][$this->counter]['result_count'] = $count;
         $this->profiles[$event->getService()->getName()][$this->counter]['result'] = print_r($result, true);
         $this->counter++;
         $this->activeProfileEvent = null;
     }
 }
Пример #2
0
 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);
     }
 }