magallanes/src/Command/AbstractCommand.php

67 lines
1.4 KiB
PHP
Raw Normal View History

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\Command;
use Mage\MageApplication;
2017-01-07 06:28:46 +01:00
use Mage\Utils;
2017-01-01 05:33:34 +01:00
use Mage\Runtime\Runtime;
2016-12-31 07:52:25 +01:00
use Psr\Log\LogLevel;
use Symfony\Component\Console\Command\Command;
/**
* Abstract base class for Magallanes Commands
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
abstract class AbstractCommand extends Command
{
2022-04-10 06:20:03 +02:00
protected int $statusCode = 0;
protected Runtime $runtime;
2016-12-31 07:52:25 +01:00
/**
* Set the Runtime configuration
2016-12-31 07:52:25 +01:00
*/
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;
2016-12-31 07:52:25 +01:00
return $this;
}
/**
* Logs a message
2016-12-31 07:52:25 +01:00
*/
2022-04-10 06:20:03 +02:00
public function log(string $message, string $level = LogLevel::DEBUG): void
2016-12-31 07:52:25 +01:00
{
$this->runtime->log($message, $level);
2016-12-31 07:52:25 +01:00
}
2017-01-07 06:28:46 +01:00
/**
* Get the Human friendly Stage name
*/
2022-04-10 06:20:03 +02:00
protected function getStageName(): string
2017-01-07 06:28:46 +01:00
{
$utils = new Utils();
return $utils->getStageName($this->runtime->getStage());
2017-01-07 06:28:46 +01:00
}
2017-01-29 23:25:03 +01:00
/**
* Requires the configuration to be loaded
*/
2022-04-10 06:20:03 +02:00
protected function requireConfig(): void
2017-01-29 23:25:03 +01:00
{
$app = $this->getApplication();
if ($app instanceof MageApplication) {
$app->configure();
}
2017-01-29 23:25:03 +01:00
}
2016-12-31 07:52:25 +01:00
}