Skip to content

Commit

Permalink
Merge pull request #12 from fd6130/patch
Browse files Browse the repository at this point in the history
Inject HelperSet in Context
  • Loading branch information
fd6130 authored Nov 12, 2021
2 parents c7d8d1b + 7780009 commit 42640af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Command/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output)
{
$logFilePath = sprintf('%s/deploy_%s.log', $this->logDir, $input->getArgument('stage'));
$context = new Context($input, $output, $this->projectDir, $logFilePath, true === $input->getOption('dry-run'), $output->isVerbose());
$context = new Context($input, $output, $this->projectDir, $logFilePath, true === $input->getOption('dry-run'), $output->isVerbose(), $this->getHelperSet());

$deployer = include $this->configFilePath;
$deployer->initialize($context);
Expand Down
14 changes: 13 additions & 1 deletion src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use EasyCorp\Bundle\EasyDeployBundle\Server\Property;
use EasyCorp\Bundle\EasyDeployBundle\Server\Server;
use Symfony\Component\Console\Helper\HelperInterface;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -29,15 +31,17 @@ class Context
private $output;
private $projectDir;
private $logFilePath;
private $helperSet;

public function __construct(InputInterface $input, OutputInterface $output, string $projectDir, string $logFilePath, bool $isDryRun, bool $isVerbose)
public function __construct(InputInterface $input, OutputInterface $output, string $projectDir, string $logFilePath, bool $isDryRun, bool $isVerbose, ?HelperSet $helperSet = null)
{
$this->input = $input;
$this->output = $output;
$this->projectDir = $projectDir;
$this->logFilePath = $logFilePath;
$this->dryRun = $isDryRun;
$this->debug = $isVerbose;
$this->helperSet = $helperSet;

$this->localHost = $this->createLocalHost();
}
Expand Down Expand Up @@ -87,6 +91,14 @@ public function getOutput(): OutputInterface
return $this->output;
}

public function getHelper(string $helperName): ?HelperInterface
{
if(!$this->helperSet){
return null;
}
return $this->helperSet->get($helperName);
}

private function createLocalHost(): Server
{
$localhost = new Server('localhost');
Expand Down

0 comments on commit 42640af

Please sign in to comment.