* @license http://opensource.org/licenses/MIT MIT */ namespace Rhumsaa\Uuid\Console\Command; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\TableHelper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Rhumsaa\Uuid\Console\Exception; use Rhumsaa\Uuid\Uuid; use Rhumsaa\Uuid\Console\Util\UuidFormatter; use Symfony\Component\Console\Helper\Table; /** * Provides the console command to decode UUIDs and dump information about them */ class DecodeCommand extends Command { /** * {@inheritDoc} */ protected function configure() { parent::configure(); $this->setName('decode') ->setDescription('Decode a UUID and dump information about it') ->addArgument( 'uuid', InputArgument::REQUIRED, 'The UUID to decode.' ); } /** * {@inheritDoc} * * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { if (!Uuid::isValid($input->getArgument('uuid'))) { throw new Exception('Invalid UUID (' . $input->getArgument('uuid') . ')'); } $uuid = Uuid::fromString($input->getArgument('uuid')); $table = $this->getHelperSet()->get('table'); $table->setLayout(TableHelper::LAYOUT_BORDERLESS); (new UuidFormatter())->write($table, $uuid); $table->render($output); } }