/** * @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; }
/** * @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; }