Skip to content

Instantly share code, notes, and snippets.

@boscho87
Created April 24, 2018 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boscho87/6ae78d42cb63ae0da3860b0408f2c73c to your computer and use it in GitHub Desktop.
Save boscho87/6ae78d42cb63ae0da3860b0408f2c73c to your computer and use it in GitHub Desktop.
Command to Debug parsed env vars
<?php
namespace App\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class AppDebugEnvvarCommand extends ContainerAwareCommand
{
protected static $defaultName = 'app:debug:envvar';
protected function configure()
{
$this
->setDescription('Add a short description for your command')
->addArgument('parameter', InputArgument::REQUIRED, 'configures parameter');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$parameter = $input->getArgument('parameter');
$io->note(sprintf('You passed an argument: %s', $parameter));
try {
$value = $this->getContainer()->getParameter($parameter);
} catch (\Exception $e) {
$value = '';
}
if (empty($value)) {
$io->error('parameter: ' . $parameter . ' not found');
return 1;
}
$io->success('parameter: ' . $parameter . ' has value: \'' . $value . '\'' . ' and is of type: ' . gettype($value));
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment