Last active
August 31, 2022 11:27
-
-
Save mikemix/cbb9709a2f2d0588d584e40e0d5530aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
final class UrlGenerateCommand extends Command | |
{ | |
private readonly RouterInterface $router; | |
public function __construct( | |
RouterInterface $router, | |
) { | |
parent::__construct(); | |
$this->router = $router; | |
} | |
protected function configure(): void | |
{ | |
$this->setName('dev:url') | |
->setDescription('Generates image link') | |
->addArgument('strategy', InputArgument::REQUIRED) | |
->addArgument('size', InputArgument::REQUIRED) | |
->addArgument('image-id', InputArgument::REQUIRED) | |
->addArgument('output-format', InputArgument::REQUIRED) | |
->addUsage('fixed 100x100 1/2/3.jpg webp'); | |
} | |
protected function execute(InputInterface $input, OutputInterface $output): int | |
{ | |
/** @var non-empty-string $strategy */ | |
$strategy = $input->getArgument('strategy'); | |
/** @var non-empty-string $size */ | |
$size = $input->getArgument('size'); | |
/** @var non-empty-string $imageId */ | |
$imageId = $input->getArgument('image-id'); | |
/** @var non-empty-string $format */ | |
$format = $input->getArgument('output-format'); | |
$url = $this->router->generate('thumbnail_serve', [ | |
'strategy' => $strategy, | |
'size' => $size, | |
'id' => $imageId, | |
'format' => $format, | |
]); | |
$output->writeln($url); | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment