Files
php-auth/src/Cli/Commands/OAuth/AddScope.php
Ron Rise b5b6caa400
Some checks failed
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m25s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m35s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Failing after 2m45s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m36s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Failing after 2m25s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Failing after 1m10s
more updates
2026-01-02 13:57:41 -05:00

47 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Siteworxpro\App\Cli\Commands\OAuth;
use Siteworxpro\App\Cli\Commands\Command;
use Siteworxpro\App\OAuth\Entities\Scope;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command as SympCommand;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
#[AsCommand('oauth:scope:add', 'Add a new OAuth scope')]
class AddScope extends Command
{
protected function configure(): void
{
$this
->addArgument('name', InputArgument::REQUIRED, 'The name of the scope')
->addArgument('description', InputArgument::OPTIONAL, 'The description of the scope');
}
public function __invoke(ArgvInput | InputInterface $input, $output): int
{
$name = $input->getArgument('name');
$description = $input->getArgument('description') ?? '';
$scope = Scope::where('name', $name)->first();
if ($scope) {
$output->error("Scope with name '$name' already exists.");
return SympCommand::FAILURE;
}
$scope = new Scope();
$scope->name = $name;
$scope->description = $description;
$scope->save();
$output->green("Scope '$name' added successfully.");
return SympCommand::SUCCESS;
}
}