Created
July 19, 2019 06:46
-
-
Save dracony/9f4a36c5d6f7179f477714587b3f4061 to your computer and use it in GitHub Desktop.
This file contains 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 | |
require __DIR__.'/vendor/autoload.php'; | |
use Symfony\Component\Console\Application; | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use GuzzleHttp\Client; | |
$application = new Application(); | |
class RegisterUserCommand extends Command | |
{ | |
protected static $defaultName = 'register'; | |
private $client; | |
public function __construct() { | |
$this->client = new Client([ | |
'base_uri' => 'http://127.0.0.1' | |
]); | |
parent::__construct(); | |
} | |
protected function configure() | |
{ | |
$this->setDescription('Registers a user.'); | |
$this->addArgument('username', InputArgument::REQUIRED); | |
$this->addArgument('publicKey', InputArgument::REQUIRED); | |
} | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
$this->client->post('/register', [ | |
'json' => [ | |
'username' => $input->getArgument('username'), | |
'publicKey' => file_get_contents($input->getArgument('publicKey')) | |
] | |
]); | |
} | |
} | |
$application->add(new RegisterUserCommand()); | |
$application->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment