Created
April 24, 2018 19:11
-
-
Save boscho87/6ae78d42cb63ae0da3860b0408f2c73c to your computer and use it in GitHub Desktop.
Command to Debug parsed env vars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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