Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Inject HelperSet in Context #12

Merged
merged 1 commit into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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