context = adp_context(); $this->rule = $contextOrRule instanceof Rule ? $contextOrRule : $deprecated; $this->ruleRepository = new RuleRepository(); $this->execRuleStart = null; $this->lastExecTime = null; } public function withContext(Context $context) { $this->context = $context; } public function withRuleRepository(RuleRepositoryInterface $repository) { $this->ruleRepository = $repository; } public function start() { $this->execRuleStart = microtime(true); $this->lastExecTime = null; } /** * @return float */ public function finish() { if ( ! isset($this->execRuleStart)) { return floatval(0); } $this->lastExecTime = microtime(true) - $this->execRuleStart; $this->execRuleStart = null; return $this->lastExecTime; } /** * @throws RuleExecutionTimeout */ public function checkExecutionTime() { $rule_max_exec_time = (float)$this->context->getOption('rule_max_exec_time'); if (empty($rule_max_exec_time)) { return; } if ((microtime(true) - $this->execRuleStart) > $rule_max_exec_time) { throw new RuleExecutionTimeout(); } } /** * @return float */ public function getLastExecTime() { return $this->lastExecTime; } public function handleOutOfTime() { $this->context->adminNotice->addOutOfTimeNotice($this->rule->getId(), false); $this->ruleRepository->markAsDisabledByPlugin($this->rule->getId()); } }