Skip to content

Instantly share code, notes, and snippets.

@mikemix
Last active August 31, 2022 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikemix/cbb9709a2f2d0588d584e40e0d5530aa to your computer and use it in GitHub Desktop.
Save mikemix/cbb9709a2f2d0588d584e40e0d5530aa to your computer and use it in GitHub Desktop.
<?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