SymfonyCommandIntegrator.php 1011 Bytes
<?php

namespace FootyRoom\Console;

use Symfony\Component\Console\Helper\HelperInterface;

trait SymfonyCommandIntegrator
{
    public function __construct()
    {
        $this->originalCommand = new $this->symfonyCommand();

        $this->name = $this->originalCommand->getName();
        $this->description = $this->originalCommand->getDescription();
        $this->hidden = $this->originalCommand->isHidden();
        
        parent::__construct();
        
        $this->setHelp($this->originalCommand->getHelp());
        $this->setDefinition($this->originalCommand->getDefinition());
    }

    protected function executeSymfonyCommand(): ?int
    {
        $this->originalCommand->setApplication($this->getApplication());

        return $this->originalCommand->execute($this->input, $this->output);
    }

    protected function setHelper(string $key, HelperInterface $value): void
    {
        $helperSet = $this->getApplication()->getHelperSet();

        $helperSet->set($value, $key);
    }
}