*/ final class CallbackTask extends AbstractTask implements CallbackTaskInterface { private $callable; private $enqueued = false; /** * @return \common_report_Report */ public function __invoke() { return call_user_func($this->getCallable(), $this->getParameters()); } public function __clone() { if (is_object($this->callable)) { $this->callable = clone $this->callable; } $this->enqueued = false; parent::__clone(); } /** * @param callable $callable * @return CallbackTaskInterface */ public function setCallable(callable $callable) { if ($callable instanceof TaskAwareInterface) { $callable->setTask($this); } $this->callable = $callable; return $this; } /** * @return callable|string|object */ public function getCallable() { if (is_null($this->callable) && ($callableFromJSON = $this->getMetadata('__callable__'))) { $this->callable = $callableFromJSON; } return $this->callable; } /** * @return CallbackTaskInterface */ public function markAsEnqueued() { $this->enqueued = true; return $this; } /** * @return bool */ public function isEnqueued() { return $this->enqueued; } /** * @return array */ public function jsonSerialize() { $callableClassOrArray = $this->getCallable(); if (is_object($callableClassOrArray) && !$callableClassOrArray instanceof \JsonSerializable) { $callableClassOrArray = get_class($callableClassOrArray); } $this->setMetadata('__callable__', $callableClassOrArray); return parent::jsonSerialize(); } /** * @return CallbackTaskInterface */ public function applyWorkerContext() { parent::applyWorkerContext(); if ($this->getCallable() instanceof WorkerContextAwareInterface) { $this->getCallable()->applyWorkerContext(); } return $this; } /** * @return bool */ public function hasChildren() { if ($this->getCallable() instanceof ChildTaskAwareInterface) { return $this->getCallable()->hasChildren(); } return parent::hasChildren(); } /** * @return string[] */ public function getChildren() { if ($this->getCallable() instanceof ChildTaskAwareInterface) { return $this->getCallable()->getChildren(); } return parent::getChildren(); } }