tasks, [$this, 'registerTask']); } protected function registerTask(array $config, string $name): void { $body = $config['body'] ?? ''; if (is_string($body) && !method_exists($this, $body)) { return; } if (is_callable([$this, $body])) { $task = new Task($name, [$this, $body]); $description = $this->getFunctionSummary($body); if ($description) { $task->desc($description); } } elseif (is_array($body)) { $task = new GroupTask($name, $body); } else { throw new \InvalidArgumentException('Task body should be a function or an array.'); } array_map(function ($selector) use ($task) { $task->addSelector($selector); }, $config['stages'] ?? []); $deployer = Deployer::get(); $deployer->tasks->set($name, $task); } protected function getFunctionSummary(string $function): string { $summary = ''; try { $reflector = new ReflectionMethod(Deployment::class, $function); $comment = $reflector->getDocComment(); if ($comment) { $summary = DocBlockFactory::createInstance()->create($comment)->getSummary(); } } catch (\Exception) { } return $summary; } protected function get(string $name, $default = null) { return get($name, $default); } protected function set(string $name, $value): void { set($name, $value); } protected function has(string $name): bool { return has($name); } protected function hasArray(string $name): bool { return $this->has($name) && is_array($this->get($name)); } }