magallanes/src/Command/AbstractCommand.php

70 lines
1.4 KiB
PHP
Raw Normal View History

2016-12-31 07:52:25 +01:00
<?php
/*
* 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;
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
{
2017-01-07 06:28:46 +01:00
/**
* @var int
*/
protected $statusCode = 0;
2016-12-31 07:52:25 +01:00
/**
2017-01-01 05:33:34 +01:00
* @var Runtime Current Runtime instance
2016-12-31 07:52:25 +01:00
*/
protected $runtime;
/**
* Set the Runtime configuration
2016-12-31 07:52:25 +01:00
*
2017-01-01 05:33:34 +01:00
* @param Runtime $runtime Runtime container
2016-12-31 07:52:25 +01:00
* @return AbstractCommand
*/
2017-01-01 05:33:34 +01:00
public function setRuntime(Runtime $runtime)
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
*
* @param string $message
* @param string $level
*/
public function log($message, $level = LogLevel::DEBUG)
{
$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
*
* @return string
*/
protected function getStageName()
{
$utils = new Utils();
return $utils->getStageName($this->runtime->getStage());
2017-01-07 06:28:46 +01:00
}
2016-12-31 07:52:25 +01:00
}