1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the ramsey/uuid-console application |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright Copyright (c) Ben Ramsey <[email protected]> |
9
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
10
|
|
|
* @link https://packagist.org/packages/ramsey/uuid-console Packagist |
11
|
|
|
* @link https://github.com/ramsey/uuid-console GitHub |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Ramsey\Uuid\Console\Command; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Console\Command\Command; |
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
use Ramsey\Uuid\Console\Exception; |
21
|
|
|
use Ramsey\Uuid\Uuid; |
22
|
|
|
use Ramsey\Uuid\Console\Util\UuidFormatter; |
23
|
|
|
use Symfony\Component\Console\Helper\Table; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Provides the console command to decode UUIDs and dump information about them |
27
|
|
|
*/ |
28
|
|
|
class DecodeCommand extends Command |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* {@inheritDoc} |
32
|
|
|
*/ |
33
|
|
|
protected function configure() |
34
|
|
|
{ |
35
|
|
|
parent::configure(); |
36
|
|
|
|
37
|
|
|
$this->setName('decode') |
38
|
|
|
->setDescription('Decode a UUID and dump information about it') |
39
|
|
|
->addArgument( |
40
|
|
|
'uuid', |
41
|
|
|
InputArgument::REQUIRED, |
42
|
|
|
'The UUID to decode.' |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritDoc} |
48
|
|
|
* |
49
|
|
|
* @param InputInterface $input |
50
|
|
|
* @param OutputInterface $output |
51
|
|
|
*/ |
52
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
53
|
|
|
{ |
54
|
|
|
if (!Uuid::isValid($input->getArgument('uuid'))) { |
55
|
|
|
throw new Exception('Invalid UUID (' . $input->getArgument('uuid') . ')'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$uuid = Uuid::fromString($input->getArgument('uuid')); |
59
|
|
|
|
60
|
|
|
$table = $this->createTable($output); |
61
|
|
|
$this->setTableLayout($table); |
62
|
|
|
|
63
|
|
|
(new UuidFormatter())->write($table, $uuid); |
64
|
|
|
|
65
|
|
|
$table->render($output); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
protected function createTable(OutputInterface $output) |
69
|
|
|
{ |
70
|
|
|
return new Table($output); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param object $table |
75
|
|
|
*/ |
76
|
|
|
protected function setTableLayout($table) |
77
|
|
|
{ |
78
|
|
|
$table->setStyle('borderless'); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|