setDefaultConfiguration(); $this->initializeTasks(); } protected function setDefaultConfiguration(): void { } protected function initializeTasks(): void { array_walk($this->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 commandExist(string $command): bool { return testLocally("hash $command 2>/dev/null"); } protected function set(string $name, $value): void { set($name, $value); } protected function get(string $name, $default = null) { return get($name, $default); } protected function has(string $name): bool { return has($name); } protected function hasArray(string $name): bool { return $this->has($name) && is_array($this->get($name)); } protected function getApplicationContext(): string { return $this->has('application_context') ? 'TYPO3_CONTEXT="' . $this->get('application_context') . '" ' : ''; } protected function getSudo(): string { return $this->get('clear_use_sudo') ? 'sudo ' : ''; } protected function getTYPO3Bin(string $path, string $testPath): string { if (test('[ -f ' . $testPath . '/releases/{{release_name}}/vendor/bin/typo3cms ]')) { $bin = $path . '/releases/{{release_name}}/vendor/bin/typo3cms'; } else { $bin = $path . '/releases/{{release_name}}/vendor/bin/typo3'; } return $bin; } }