class SimpleOauthCommands in Simple OAuth (OAuth2) & OpenID Connect 5.x
Same name and namespace in other branches
- 8.4 src/Commands/SimpleOauthCommands.php \Drupal\simple_oauth\Commands\SimpleOauthCommands
- 8.3 src/Commands/SimpleOauthCommands.php \Drupal\simple_oauth\Commands\SimpleOauthCommands
Drush commands for Simple OAuth.
Hierarchy
- class \Drupal\simple_oauth\Commands\SimpleOauthCommands extends \Drush\Commands\DrushCommands
Expanded class hierarchy of SimpleOauthCommands
File
- src/
Commands/ SimpleOauthCommands.php, line 14
Namespace
Drupal\simple_oauth\CommandsView source
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SimpleOauthCommands:: |
private | property | The file system. | |
SimpleOauthCommands:: |
private | property | The key generator. | |
SimpleOauthCommands:: |
public | function | Generate Oauth2 Keys. | |
SimpleOauthCommands:: |
private | function | Checks whether the give uri is a directory, without throwing errors. | |
SimpleOauthCommands:: |
public | function | SimpleOauthCommands constructor. |