Skip to content

Instantly share code, notes, and snippets.

@mikemix
Last active August 31, 2022 11:27
Show Gist options
  • Save mikemix/cbb9709a2f2d0588d584e40e0d5530aa to your computer and use it in GitHub Desktop.
Save mikemix/cbb9709a2f2d0588d584e40e0d5530aa to your computer and use it in GitHub Desktop.

Revisions

  1. mikemix revised this gist Aug 31, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion thumbgun-cli.php
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ public function __construct(
    protected function configure(): void
    {
    $this->setName('dev:url')
    ->setDescription('Generates image link with a valid checksum')
    ->setDescription('Generates image link')
    ->addArgument('strategy', InputArgument::REQUIRED)
    ->addArgument('size', InputArgument::REQUIRED)
    ->addArgument('image-id', InputArgument::REQUIRED)
  2. mikemix created this gist Aug 31, 2022.
    50 changes: 50 additions & 0 deletions thumbgun-cli.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    <?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 with a valid checksum')
    ->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;
    }
    }