2016-12-31 07:52:25 +01:00
|
|
|
<?php
|
2022-04-10 06:20:03 +02:00
|
|
|
|
2016-12-31 07:52:25 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the Magallanes package.
|
|
|
|
*
|
|
|
|
* (c) Andrés Montañez <andres@andresmontanez.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Mage\Task;
|
|
|
|
|
2017-01-01 05:33:34 +01:00
|
|
|
use Mage\Runtime\Runtime;
|
2016-12-31 07:52:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract base class for Magallanes Tasks
|
|
|
|
*
|
|
|
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
|
|
|
*/
|
|
|
|
abstract class AbstractTask
|
|
|
|
{
|
2022-04-10 06:20:03 +02:00
|
|
|
/** @var array<string, string|int|null> */
|
|
|
|
protected array $options = [];
|
2016-12-31 07:52:25 +01:00
|
|
|
|
2022-04-10 06:20:03 +02:00
|
|
|
protected Runtime $runtime;
|
2016-12-31 07:52:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Name/Code of the Task
|
|
|
|
*/
|
2022-04-10 06:20:03 +02:00
|
|
|
abstract public function getName(): string;
|
2016-12-31 07:52:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a short Description of the Task
|
|
|
|
*/
|
2022-04-10 06:20:03 +02:00
|
|
|
abstract public function getDescription(): string;
|
2016-12-31 07:52:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the Command
|
|
|
|
*/
|
2022-04-10 06:20:03 +02:00
|
|
|
abstract public function execute(): bool;
|
2016-12-31 07:52:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set additional Options for the Task
|
|
|
|
*
|
2022-04-10 06:20:03 +02:00
|
|
|
* @param array<string, string|int|null> $options
|
2016-12-31 07:52:25 +01:00
|
|
|
*/
|
2022-04-10 06:20:03 +02:00
|
|
|
public function setOptions(array $options = []): self
|
2016-12-31 07:52:25 +01:00
|
|
|
{
|
2017-02-11 04:03:38 +01:00
|
|
|
$this->options = array_merge($this->getDefaults(), $options);
|
2016-12-31 07:52:25 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the Runtime instance
|
|
|
|
*/
|
2022-04-10 06:20:03 +02:00
|
|
|
public function setRuntime(Runtime $runtime): self
|
2016-12-31 07:52:25 +01:00
|
|
|
{
|
|
|
|
$this->runtime = $runtime;
|
|
|
|
return $this;
|
|
|
|
}
|
2017-02-11 03:57:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return Default options
|
2022-04-10 06:20:03 +02:00
|
|
|
*
|
|
|
|
* @return array<string, string|int|null>
|
2017-02-11 03:57:34 +01:00
|
|
|
*/
|
2022-04-10 06:20:03 +02:00
|
|
|
public function getDefaults(): array
|
2017-02-11 03:57:34 +01:00
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
2016-12-31 07:52:25 +01:00
|
|
|
}
|