- md5
- 2cdff51b544d2929271dd1f3f50fd8e4
- sha1
- 6b54d03372fecf5e2a92b1f62d1707375a160255
- sha256
- a5e015dec280503214bbf0ef8e3cbf12a47c26669adbba93098a2e2fa52c1df5
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
<?php
declare(strict_types=1);
namespace Jose\Component\Console;
use InvalidArgumentException;
use Jose\Component\Core\JWK;
use Jose\Component\Core\JWKSet;
use Jose\Component\Core\Util\JsonConverter;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use function is_array;
use function is_string;
#[AsCommand(name: 'keyset:add:key', description: 'Add a key into a key set.',)]
final class AddKeyIntoKeysetCommand extends ObjectOutputCommand
{
protected static $defaultName = 'keyset:add:key';
protected static $defaultDescription = 'Add a key into a key set.';
protected function configure(): void
{
parent::configure();
$this->setHelp('This command adds a key at the end of a key set.')
->addArgument('jwkset', InputArgument::REQUIRED, 'The JWKSet object')
->addArgument('jwk', InputArgument::REQUIRED, 'The new JWK object');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$jwkset = $this->getKeyset($input);
$jwk = $this->getKey($input);
$jwkset = $jwkset->with($jwk);
$this->prepareJsonOutput($input, $output, $jwkset);
return self::SUCCESS;
}
private function getKeyset(InputInterface $input): JWKSet
{
$jwkset = $input->getArgument('jwkset');
if (! is_string($jwkset)) {
throw new InvalidArgumentException('The argument must be a valid JWKSet.');
}
$json = JsonConverter::decode($jwkset);
if (! is_array($json)) {
throw new InvalidArgumentException('The argument must be a valid JWKSet.');
}
return JWKSet::createFromKeyData($json);
}
private function getKey(InputInterface $input): JWK
{
$jwk = $input->getArgument('jwk');
if (! is_string($jwk)) {
throw new InvalidArgumentException('The argument must be a valid JWK.');
}
$json = JsonConverter::decode($jwk);
if (! is_array($json)) {
throw new InvalidArgumentException('The argument must be a valid JWK.');
}
return new JWK($json);
}
}
The same content is in 136 releases, Joomla 5.1.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.