mini-fair-repo/inc/plc/class-command.php
Joost de Valk d527f95815
Do plugin rename (#78)
Signed-off-by: Joost de Valk <joost@altha.nl>
Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
2025-11-24 12:58:34 -08:00

129 lines
2.5 KiB
PHP

<?php
/**
* Command.
*
* @package FAIR\Beacon
*/
namespace FAIR\Beacon\PLC;
use WP_CLI;
use WP_CLI_Command;
/**
* Command class.
*/
class Command extends WP_CLI_Command {
/**
* Generate a new DID.
*
* @param array $args The command line arguments.
* @param array $assoc_args The associative command line arguments.
* @return void
*/
public function generate( $args, $assoc_args ) {
$did = DID::create();
printf(
"DID: %s\n",
esc_html( $did->id )
);
$rot_keys = $did->get_rotation_keys();
foreach ( $rot_keys as $key ) {
$encoded = $key->encode_public();
printf(
"Rotation key: %s\n",
esc_html( $encoded )
);
}
$verif_keys = $did->get_verification_keys();
foreach ( $verif_keys as $key ) {
$encoded = $key->encode_public();
printf(
"Verification key: %s\n",
esc_html( $encoded )
);
}
exit;
}
/**
* Get a DID.
*
* @param array $args The command line arguments.
* @param array $assoc_args The associative command line arguments.
* @return void
*/
public function get( $args, $assoc_args ) {
$did = DID::get( $args[0] );
var_dump( $did );
printf(
"DID: %s\n",
esc_html( $did->id )
);
$rot_keys = $did->get_rotation_keys();
foreach ( $rot_keys as $key ) {
$encoded = $key->encode_public();
printf(
"Rotation key: %s\n",
esc_html( $encoded )
);
}
$verif_keys = $did->get_verification_keys();
foreach ( $verif_keys as $key ) {
$encoded = $key->encode_public();
printf(
"Verification key: %s\n",
esc_html( $encoded )
);
}
}
/**
* Update a DID.
*
* ## OPTIONS
* <did>
* : The DID to update
*
* @param array $args The command line arguments.
* @param array $assoc_args The associative command line arguments.
* @return void
*/
public function update( $args, $assoc_args ) {
$did = DID::get( $args[0] );
if ( ! $did ) {
WP_CLI::error( 'DID not found' );
}
$res = $did->update();
var_dump( $res );
}
/**
* Import a DID.
*
* ## OPTIONS
* <did>
* : The DID to import.
*
* <rotation_keys>
* : The rotation keys for the DID.
*
* <verification_keys>
* : The verification keys for the DID.
*
* @param array $args The command line arguments.
* @param array $assoc_args The associative command line arguments.
*/
public function import( $args, $assoc_args ) {
$did = new DID();
// $did->set_id( $args[0] );.
// $did->set_rotation_keys( $args[1] );.
// $did->set_verification_keys( $args[2] );.
$did->save();
}
}