示例#1
0
 public function onPostRun(ProbeNotification $notification) : ExecutionTimeProbe
 {
     $endTime = microtime(true);
     $executionTime = ($endTime - $this->startTime) * 1000;
     $result = $notification->getResult();
     $result->setData('execTime', $executionTime);
     return $this;
 }
示例#2
0
 /**
  * @inheritDoc
  */
 public function run(Result &$result = null, array $input = null) : Result
 {
     $preRunNotification = new ProbeNotification();
     $preRunNotification->setEventName(static::EVENT_PRE_RUN);
     $preRunNotification->setResult($result);
     $this->trigger($preRunNotification);
     $result = $this->doRun($result, $input);
     $postRunNotification = clone $preRunNotification;
     $postRunNotification->setEventName(static::EVENT_POST_RUN);
     $this->trigger($postRunNotification);
     return $result;
 }
示例#3
0
 /**
  * @inheritDoc
  */
 protected function doRun(Result &$result = null, array $inputs = null) : Result
 {
     $class = get_class($this->instance);
     $reflectionClass = new \ReflectionClass($class);
     $reflectionMethod = $reflectionClass->getMethod($this->method);
     $minimalParametersCount = $reflectionMethod->getNumberOfRequiredParameters();
     if (count($inputs) < $minimalParametersCount) {
         //@todo throw exception
     }
     try {
         $methodRunNotification = new ProbeNotification();
         $methodRunNotification->setEventName(ExecutionTimeProbe::EVENT_START_TIME);
         $methodRunNotification->setResult($result);
         $this->trigger($methodRunNotification);
         $output = $reflectionMethod->invokeArgs($this->instance, $inputs);
         $methodRunNotification->setEventName(ExecutionTimeProbe::EVENT_END_TIME);
         $this->trigger($methodRunNotification);
         $result->setOutput($output);
     } catch (\Exception $e) {
         $result->setException($e);
     }
     return $result;
 }