GenerateKey
extends BaseCommand
in package
Generates a new encryption key.
Table of Contents
- $arguments : array<string|int, mixed>
- $commands : Commands
- $description : string
- $group : string
- $logger : LoggerInterface
- $name : string
- $options : array<string|int, mixed>
- $usage : string
- $arguments : array<string|int, mixed>
- the Command's Arguments description
- $commands : Commands
- Instance of Commands so commands can call other commands.
- $description : string
- The Command's short description.
- $group : string
- The Command's group.
- $logger : LoggerInterface
- The Logger to use for a command
- $name : string
- The Command's name.
- $options : array<string|int, mixed>
- The command's options
- $usage : string
- The Command's usage.
- __construct() : mixed
- BaseCommand constructor.
- __get() : mixed
- Makes it simple to access our protected properties.
- __isset() : bool
- Makes it simple to check our protected properties.
- getPad() : int
- Get pad for $key => $value array output
- run() : void
- Actually execute the command.
- setPad() : string
- Pads our string out so that all titles are the same length to nicely line up descriptions.
- showHelp() : mixed
- Show Help includes (Usage, Arguments, Description, Options).
- call() : mixed
- Can be used by a command to run other commands.
- confirmOverwrite() : bool
- Checks whether to overwrite existing encryption key.
- generateRandomKey() : string
- Generates a key and encodes it.
- keyPattern() : string
- Get the regex of the current encryption key.
- setNewEncryptionKey() : bool
- Sets the new encryption key in your .env file.
- showError() : mixed
- A simple method to display an error with line/file, in child commands.
- writeNewEncryptionKeyToFile() : bool
- Writes the new encryption key to .env file.
Properties
$arguments
public
array<string|int, mixed>
$arguments
$commands
public
Commands
$commands
$description
public
string
$description
$group
public
string
$group
$logger
public
LoggerInterface
$logger
$name
public
string
$name
$options
public
array<string|int, mixed>
$options
$usage
public
string
$usage
$arguments
the Command's Arguments description
protected
array<string|int, mixed>
$arguments
= []
$commands
Instance of Commands so commands can call other commands.
protected
Commands
$commands
$description
The Command's short description.
protected
string
$description
= 'Generates a new encryption key and writes it in an `.env` file.'
$group
The Command's group.
protected
string
$group
= 'Encryption'
$logger
The Logger to use for a command
protected
LoggerInterface
$logger
$name
The Command's name.
protected
string
$name
= 'key:generate'
$options
The command's options
protected
array<string|int, mixed>
$options
= ['--force' => 'Force overwrite existing key in `.env` file.', '--length' => 'The length of the random string that should be returned in bytes. Defaults to 32.', '--prefix' => 'Prefix to prepend to encoded key (either hex2bin or base64). Defaults to hex2bin.', '--show' => 'Shows the generated key in the terminal instead of storing in the `.env` file.']
$usage
The Command's usage.
protected
string
$usage
= 'key:generate [options]'
Methods
__construct()
BaseCommand constructor.
public
__construct(LoggerInterface $logger, Commands $commands) : mixed
Parameters
- $logger : LoggerInterface
- $commands : Commands
Return values
mixed —__get()
Makes it simple to access our protected properties.
public
__get(string $key) : mixed
Parameters
- $key : string
Return values
mixed —__isset()
Makes it simple to check our protected properties.
public
__isset(string $key) : bool
Parameters
- $key : string
Return values
bool —getPad()
Get pad for $key => $value array output
public
getPad(array<string|int, mixed> $array, int $pad) : int
Parameters
- $array : array<string|int, mixed>
- $pad : int
Tags
Return values
int —run()
Actually execute the command.
public
run(array<string|int, mixed> $params) : void
Parameters
- $params : array<string|int, mixed>
Return values
void —setPad()
Pads our string out so that all titles are the same length to nicely line up descriptions.
public
setPad(string $item, int $max[, int $extra = 2 ], int $indent) : string
Parameters
- $item : string
- $max : int
- $extra : int = 2
-
How many extra spaces to add at the end
- $indent : int
Return values
string —showHelp()
Show Help includes (Usage, Arguments, Description, Options).
public
showHelp() : mixed
Return values
mixed —call()
Can be used by a command to run other commands.
protected
call(string $command[, array<string|int, mixed> $params = [] ]) : mixed
Parameters
- $command : string
- $params : array<string|int, mixed> = []
Tags
Return values
mixed —confirmOverwrite()
Checks whether to overwrite existing encryption key.
protected
confirmOverwrite(array<string|int, mixed> $params) : bool
Parameters
- $params : array<string|int, mixed>
Return values
bool —generateRandomKey()
Generates a key and encodes it.
protected
generateRandomKey(string $prefix, int $length) : string
Parameters
- $prefix : string
- $length : int
Return values
string —keyPattern()
Get the regex of the current encryption key.
protected
keyPattern(string $oldKey) : string
Parameters
- $oldKey : string
Return values
string —setNewEncryptionKey()
Sets the new encryption key in your .env file.
protected
setNewEncryptionKey(string $key, array<string|int, mixed> $params) : bool
Parameters
- $key : string
- $params : array<string|int, mixed>
Return values
bool —showError()
A simple method to display an error with line/file, in child commands.
protected
showError(Throwable $e) : mixed
Parameters
- $e : Throwable
Return values
mixed —writeNewEncryptionKeyToFile()
Writes the new encryption key to .env file.
protected
writeNewEncryptionKeyToFile(string $oldKey, string $newKey) : bool
Parameters
- $oldKey : string
- $newKey : string