DumpCommand
extends Command
in package
CLI command for exporting database data in various formats Supports SQL, JSON, CSV, and YAML output formats
Table of Contents
Properties
- $arguments : array<string|int, mixed>
- $input : Input
- $inputReader : IInputReader|null
- $options : array<string|int, mixed>
- $output : Output
Methods
- configure() : void
- Configure the command (add arguments and options) Override this method to define command parameters
- execute() : int
- Execute the command
- getArguments() : array<string|int, mixed>
- Get all configured arguments
- getDescription() : string
- Get the command description
- getHelp() : string
- Get the help text for this command
- getName() : string
- Get the command name
- getOptions() : array<string|int, mixed>
- Get all configured options
- hasArgument() : bool
- Check if the command has a specific argument
- hasOption() : bool
- Check if the command has a specific option
- setInput() : self
- Set the input instance
- setInputReader() : self
- Set the input reader (for dependency injection, especially in tests).
- setOutput() : self
- Set the output instance
- validate() : void
- Validate that required arguments are present
- addArgument() : self
- Add an argument to the command
- addOption() : self
- Add an option to the command
- choice() : string
- Prompt user to select from a list of options.
- confirm() : bool
- Ask user for yes/no confirmation.
- getInputReader() : IInputReader
- Get the input reader instance.
- prompt() : string
- Prompt user for input.
- secret() : string
- Prompt for sensitive input without echoing to console.
- determineOutputPath() : string
- Determine output path based on format
- exportCsv() : int
- Export to CSV format (directory)
- findConfigPath() : string|null
- Try to find the configuration directory
- formatFileSize() : string
- Format file size for display
- getTableList() : array<string|int, mixed>
- Get list of tables that will be exported
- loadSettings() : Yaml|null
- Load settings from config directory
- normalizePath() : string
- Normalize a file path by resolving . and .. components
- parseExportOptions() : array<string|int, mixed>
- Parse export options from command input
- performDryRun() : int
- Perform dry run
- showExportProgress() : void
- Show export progress
Properties
$arguments
protected
array<string|int, mixed>
$arguments
= []
$input
protected
Input
$input
$inputReader
protected
IInputReader|null
$inputReader
= null
$options
protected
array<string|int, mixed>
$options
= []
$output
protected
Output
$output
Methods
configure()
Configure the command (add arguments and options) Override this method to define command parameters
public
configure() : void
Tags
execute()
Execute the command
public
execute() : int
Tags
Return values
int —Exit code (0 for success)
getArguments()
Get all configured arguments
public
getArguments() : array<string|int, mixed>
Return values
array<string|int, mixed>getDescription()
Get the command description
public
getDescription() : string
Tags
Return values
stringgetHelp()
Get the help text for this command
public
getHelp() : string
Return values
stringgetName()
Get the command name
public
getName() : string
Tags
Return values
stringgetOptions()
Get all configured options
public
getOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>hasArgument()
Check if the command has a specific argument
public
hasArgument(string $name) : bool
Parameters
- $name : string
Return values
boolhasOption()
Check if the command has a specific option
public
hasOption(string $name) : bool
Parameters
- $name : string
Return values
boolsetInput()
Set the input instance
public
setInput(Input $input) : self
Parameters
- $input : Input
Return values
selfsetInputReader()
Set the input reader (for dependency injection, especially in tests).
public
setInputReader(IInputReader $inputReader) : self
This allows tests to inject a TestInputReader with pre-programmed responses instead of requiring actual user input.
Parameters
- $inputReader : IInputReader
Return values
selfsetOutput()
Set the output instance
public
setOutput(Output $output) : self
Parameters
- $output : Output
Return values
selfvalidate()
Validate that required arguments are present
public
validate() : void
Tags
addArgument()
Add an argument to the command
protected
addArgument(string $name[, bool $required = false ][, string $description = '' ][, mixed $default = null ]) : self
Parameters
- $name : string
-
Argument name
- $required : bool = false
-
Whether the argument is required
- $description : string = ''
-
Description of the argument
- $default : mixed = null
-
Default value if not provided
Return values
selfaddOption()
Add an option to the command
protected
addOption(string $name[, string|null $shortcut = null ][, bool $hasValue = false ][, string $description = '' ][, mixed $default = null ]) : self
Parameters
- $name : string
-
Option name (long form)
- $shortcut : string|null = null
-
Option shortcut (single character)
- $hasValue : bool = false
-
Whether the option accepts a value
- $description : string = ''
-
Description of the option
- $default : mixed = null
-
Default value if not provided
Return values
selfchoice()
Prompt user to select from a list of options.
protected
choice(string $message, array<string|int, string> $options[, string|null $default = null ]) : string
Convenience method that delegates to the input reader. Users can select by entering either the option index (numeric) or the exact option text.
Example:
$env = $this->choice(
"Select environment:",
['development', 'staging', 'production'],
'development'
);
Parameters
- $message : string
-
The prompt message
- $options : array<string|int, string>
-
Available options
- $default : string|null = null
-
Default option (will be marked with *)
Return values
string —The selected option
confirm()
Ask user for yes/no confirmation.
protected
confirm(string $message[, bool $default = false ]) : bool
Convenience method that delegates to the input reader. Accepts: y, yes, true, 1 (case-insensitive) as positive responses.
Example:
if( $this->confirm( "Delete all files?" ) ) {
// User confirmed
}
Parameters
- $message : string
-
The confirmation message
- $default : bool = false
-
Default value if user just presses enter
Return values
bool —True if user confirms, false otherwise
getInputReader()
Get the input reader instance.
protected
getInputReader() : IInputReader
Creates a default StdinInputReader if not already set. This enables testable CLI commands by abstracting user input.
If output hasn't been set, a default Output instance will be created automatically.
Return values
IInputReaderprompt()
Prompt user for input.
protected
prompt(string $message) : string
Convenience method that delegates to the input reader.
Example:
$name = $this->prompt( "Enter your name: " );
Parameters
- $message : string
-
The prompt message to display
Return values
string —The user's response (trimmed)
secret()
Prompt for sensitive input without echoing to console.
protected
secret(string $message) : string
Convenience method that delegates to the input reader. Note: Secret input hiding only works on Unix-like systems.
Example:
$password = $this->secret( "Enter password: " );
Parameters
- $message : string
-
The prompt message
Return values
string —The user's input (trimmed)
determineOutputPath()
Determine output path based on format
private
determineOutputPath(string $basePath, string $format) : string
Validates that the output path is within the allowed base directory to prevent path traversal attacks (e.g., --output ../../../etc/passwd)
Parameters
- $basePath : string
-
Base path
- $format : string
-
Output format
Tags
Return values
stringexportCsv()
Export to CSV format (directory)
private
exportCsv(DataExporter $exporter, string $outputPath) : int
Parameters
- $exporter : DataExporter
- $outputPath : string
Return values
intfindConfigPath()
Try to find the configuration directory
private
findConfigPath() : string|null
Return values
string|nullformatFileSize()
Format file size for display
private
formatFileSize(int $bytes) : string
Parameters
- $bytes : int
Return values
stringgetTableList()
Get list of tables that will be exported
private
getTableList(DataExporter $exporter) : array<string|int, mixed>
Parameters
- $exporter : DataExporter
Return values
array<string|int, mixed>loadSettings()
Load settings from config directory
private
loadSettings(string $configPath) : Yaml|null
Parameters
- $configPath : string
Return values
Yaml|nullnormalizePath()
Normalize a file path by resolving . and .. components
private
normalizePath(string $path) : string
This allows path validation without requiring the path to exist on disk. Critical for preventing directory creation before security validation.
Parameters
- $path : string
-
Absolute path to normalize
Return values
string —Normalized absolute path
parseExportOptions()
Parse export options from command input
private
parseExportOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>performDryRun()
Perform dry run
private
performDryRun(string $basePath, Yaml|null $settings, array<string|int, mixed> $exportOptions) : int
Parameters
- $basePath : string
-
Base path
- $settings : Yaml|null
-
Settings
- $exportOptions : array<string|int, mixed>
-
Export options
Return values
intshowExportProgress()
Show export progress
private
showExportProgress(array<string|int, mixed> $tables) : void
Parameters
- $tables : array<string|int, mixed>