Refactor Runtime to allow custom implementation

This commit is contained in:
Andrés Montañez
2016-12-31 22:53:01 -03:00
parent 05130cb7bc
commit 74c60f55ef
8 changed files with 278 additions and 80 deletions
+8 -32
View File
@@ -10,7 +10,7 @@
namespace Mage\Command;
use Mage\Runtime\Runtime;
use Mage\Runtime\RuntimeInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Symfony\Component\Console\Command\Command;
@@ -23,55 +23,31 @@ use Symfony\Component\Console\Command\Command;
abstract class AbstractCommand extends Command
{
/**
* @var Runtime Current Runtime instance
* @var RuntimeInterface Current Runtime instance
*/
protected $runtime;
/**
* @var LoggerInterface|null The instance of the logger, it's optional
*/
private $logger = null;
/**
* Configure the Command and create the Runtime configuration
* Set the Runtime configuration
*
* @param array $configuration Magallanes configuration
* @param RuntimeInterface $runtime Runtime container
* @return AbstractCommand
*/
public function setConfiguration($configuration)
public function setRuntime(RuntimeInterface $runtime)
{
$this->runtime = new Runtime();
$this->runtime->setConfiguration($configuration);
$this->runtime->setLogger($this->logger);
$this->runtime = $runtime;
return $this;
}
/**
* Sets the logger
*
* @param LoggerInterface $logger
* @return AbstractCommand
*/
public function setLogger(LoggerInterface $logger = null)
{
$this->logger = $logger;
return $this;
}
/**
* Logs a message, if logger is valid instance
* Logs a message
*
* @param string $message
* @param string $level
* @return AbstractCommand
*/
public function log($message, $level = LogLevel::DEBUG)
{
if ($this->logger instanceof LoggerInterface) {
$this->logger->log($level, $message);
}
return $this;
$this->runtime->log($message, $level);
}
}