Вход Регистрация
Файл: vendor/symfony/uid/Command/InspectUuidCommand.php
Строк: 152
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyComponentUidCommand;

use 
SymfonyComponentConsoleAttributeAsCommand;
use 
SymfonyComponentConsoleCommandCommand;
use 
SymfonyComponentConsoleHelperTableSeparator;
use 
SymfonyComponentConsoleInputInputArgument;
use 
SymfonyComponentConsoleInputInputInterface;
use 
SymfonyComponentConsoleOutputConsoleOutputInterface;
use 
SymfonyComponentConsoleOutputOutputInterface;
use 
SymfonyComponentConsoleStyleSymfonyStyle;
use 
SymfonyComponentUidUuid;
use 
SymfonyComponentUidUuidV1;
use 
SymfonyComponentUidUuidV6;

#[AsCommand(name: 'uuid:inspect', description: 'Inspect a UUID')]
class InspectUuidCommand extends Command
{
    
/**
     * {@inheritdoc}
     */
    
protected function configure(): void
    
{
        
$this
            
->setDefinition([
                new 
InputArgument('uuid'InputArgument::REQUIRED'The UUID to inspect'),
            ])
            ->
setHelp(<<<'EOF'
The <info>%command.name%</info> displays information about a UUID.

    <info>php %command.full_name% a7613e0a-5986-11eb-a861-2bf05af69e52</info>
    <info>php %command.full_name% MfnmaUvvQ1h8B14vTwt6dX</info>
    <info>php %command.full_name% 57C4Z0MPC627NTGR9BY1DFD7JJ</info>
EOF
            )
        ;
    }

    
/**
     * {@inheritdoc}
     */
    
protected function execute(InputInterface $inputOutputInterface $output): int
    
{
        
$io = new SymfonyStyle($input$output instanceof ConsoleOutputInterface $output->getErrorOutput() : $output);

        try {
            
/** @var Uuid $uuid */
            
$uuid Uuid::fromString($input->getArgument('uuid'));
        } catch (
InvalidArgumentException $e) {
            
$io->error($e->getMessage());

            return 
1;
        }

        if (-
=== $version uuid_type($uuid)) {
            
$version 'nil';
        } elseif (
=== $version || === $version || $version) {
            
$version 'unknown';
        }

        
$rows = [
            [
'Version'$version],
            [
'toRfc4122 (canonical)', (string) $uuid],
            [
'toBase58'$uuid->toBase58()],
            [
'toBase32'$uuid->toBase32()],
        ];

        if (
$uuid instanceof UuidV1 || $uuid instanceof UuidV6) {
            
$rows[] = new TableSeparator();
            
$rows[] = ['Time'$uuid->getDateTime()->format('Y-m-d H:i:s.u UTC')];
        }

        
$io->table(['Label''Value'], $rows);

        return 
0;
    }
}
Онлайн: 1
Реклама