You are here

final class SimpleOauthCommands in Simple OAuth (OAuth2) & OpenID Connect 8.4

Same name and namespace in other branches
  1. 8.3 src/Commands/SimpleOauthCommands.php \Drupal\simple_oauth\Commands\SimpleOauthCommands
  2. 5.x src/Commands/SimpleOauthCommands.php \Drupal\simple_oauth\Commands\SimpleOauthCommands

Drush commands for Simple OAuth.

Hierarchy

Expanded class hierarchy of SimpleOauthCommands

File

src/Commands/SimpleOauthCommands.php, line 14

Namespace

Drupal\simple_oauth\Commands
View source
final class SimpleOauthCommands extends DrushCommands {

  /**
   * The key generator.
   *
   * @var \Drupal\simple_oauth\Service\KeyGeneratorService
   */
  private $keygen;

  /**
   * The file system.
   *
   * @var \Drupal\Core\File\FileSystemInterface
   */
  private $fileSystem;

  /**
   * SimpleOauthCommands constructor.
   */
  public function __construct(KeyGeneratorService $keygen, FileSystemInterface $file_system) {
    $this->keygen = $keygen;
    $this->fileSystem = $file_system;
  }

  /**
   * Checks whether the give uri is a directory, without throwing errors.
   *
   * @param string $uri
   *   The uri to check.
   *
   * @return bool
   *   TRUE if it's a directory. FALSE otherwise.
   */
  private function isDirectory($uri) {
    return @is_dir($uri);
  }

  /**
   * Generate Oauth2 Keys.
   *
   * @param string $keypath
   *   The full path were the key files will be saved.
   *
   * @usage simple-oauth:generate-keys /var/www/drupal-example.org/keys
   *   Creates the keys in the /var/www/drupal-example.org/keys directory.
   *
   * @command simple-oauth:generate-keys
   * @aliases so:generate-keys, sogk
   *
   * @validate-module-enabled simple_oauth
   */
  public function generateKeys($keypath) {
    if (!$this
      ->isDirectory($keypath)) {
      $this->fileSystem
        ->mkdir($keypath);
    }
    $keys_path = $this->fileSystem
      ->realpath($keypath);
    try {
      $this->keygen
        ->generateKeys($keys_path);
      $this
        ->logger()
        ->notice('Keys successfully generated at {path}.', [
        'path' => $keypath,
      ]);
    } catch (FilesystemValidationException $e) {
      $this
        ->logger()
        ->error($e
        ->getMessage());
    } catch (ExtensionNotLoadedException $e) {
      $this
        ->logger()
        ->error($e
        ->getMessage());
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SimpleOauthCommands::$fileSystem private property The file system.
SimpleOauthCommands::$keygen private property The key generator.
SimpleOauthCommands::generateKeys public function Generate Oauth2 Keys.
SimpleOauthCommands::isDirectory private function Checks whether the give uri is a directory, without throwing errors.
SimpleOauthCommands::__construct public function SimpleOauthCommands constructor.