ConfigGenerator
extends BaseCommand
in package
Uses
GeneratorTrait
Generates a skeleton config file.
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
- $classNameLang : string
- Language string key for required class names.
- $commands : Commands
- Instance of Commands so commands can call other commands.
- $component : string
- Component Name
- $description : string
- The Command's Description
- $directory : string
- File directory
- $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
- $template : string
- View template name
- $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() : mixed
- Actually execute a 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).
- basename() : string
- Change file basename before saving.
- buildContent() : string
- Builds the contents for class being generated, doing all the replacements necessary, and alphabetically sorts the imports for a given template.
- buildPath() : string
- Builds the file path from the class name.
- call() : mixed
- Can be used by a command to run other commands.
- execute() : void
- Execute the command.
- getOption() : mixed
- Gets a single command-line option. Returns TRUE if the option exists, but doesn't have a value, and is simply acting as a flag.
- parseTemplate() : string
- Performs pseudo-variables contained within view file.
- prepare() : string
- Prepare options and do the necessary replacements.
- qualifyClassName() : string
- Parses the class name and checks if it is already qualified.
- renderTemplate() : string
- Gets the generator view as defined in the `Config\Generators::$views`, with fallback to `$template` when the defined view does not exist.
- setEnabledSuffixing() : $this
- Allows child generators to modify the internal `$enabledSuffixing` flag.
- setHasClassName() : $this
- Allows child generators to modify the internal `$hasClassName` flag.
- setSortImports() : $this
- Allows child generators to modify the internal `$sortImports` flag.
- showError() : mixed
- A simple method to display an error with line/file, in child commands.
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
protected
array<string|int, mixed>
$arguments
= ['name' => 'The config class name.']
$classNameLang
Language string key for required class names.
protected
string
$classNameLang
= ''
$commands
Instance of Commands so commands can call other commands.
protected
Commands
$commands
$component
Component Name
protected
string
$component
$description
The Command's Description
protected
string
$description
= 'Generates a new config file.'
$directory
File directory
protected
string
$directory
$group
The Command's Group
protected
string
$group
= 'Generators'
$logger
The Logger to use for a command
protected
LoggerInterface
$logger
$name
The Command's Name
protected
string
$name
= 'make:config'
$options
The Command's Options
protected
array<string|int, mixed>
$options
= ['--namespace' => 'Set root namespace. Default: "APP_NAMESPACE".', '--suffix' => 'Append the component title to the class name (e.g. User => UserConfig).', '--force' => 'Force overwrite existing file.']
$template
View template name
protected
string
$template
$usage
The Command's Usage
protected
string
$usage
= 'make:config <name> [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 a command.
public
run(array<string|int, mixed> $params) : mixed
Parameters
- $params : array<string|int, mixed>
Return values
mixed —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 —basename()
Change file basename before saving.
protected
basename(string $filename) : string
Useful for components where the file name has a date.
Parameters
- $filename : string
Return values
string —buildContent()
Builds the contents for class being generated, doing all the replacements necessary, and alphabetically sorts the imports for a given template.
protected
buildContent(string $class) : string
Parameters
- $class : string
Return values
string —buildPath()
Builds the file path from the class name.
protected
buildPath(string $class) : string
Parameters
- $class : string
Return values
string —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 —execute()
Execute the command.
protected
execute(array<string|int, mixed> $params) : void
Parameters
- $params : array<string|int, mixed>
Return values
void —getOption()
Gets a single command-line option. Returns TRUE if the option exists, but doesn't have a value, and is simply acting as a flag.
protected
getOption(string $name) : mixed
Parameters
- $name : string
Return values
mixed —parseTemplate()
Performs pseudo-variables contained within view file.
protected
parseTemplate(string $class[, array<string|int, mixed> $search = [] ][, array<string|int, mixed> $replace = [] ][, array<string|int, mixed> $data = [] ]) : string
Parameters
- $class : string
- $search : array<string|int, mixed> = []
- $replace : array<string|int, mixed> = []
- $data : array<string|int, mixed> = []
Return values
string —prepare()
Prepare options and do the necessary replacements.
protected
prepare(string $class) : string
Parameters
- $class : string
Return values
string —qualifyClassName()
Parses the class name and checks if it is already qualified.
protected
qualifyClassName() : string
Return values
string —renderTemplate()
Gets the generator view as defined in the `Config\Generators::$views`, with fallback to `$template` when the defined view does not exist.
protected
renderTemplate([array<string|int, mixed> $data = [] ]) : string
Parameters
- $data : array<string|int, mixed> = []
-
Data to be passed to the view.
Return values
string —setEnabledSuffixing()
Allows child generators to modify the internal `$enabledSuffixing` flag.
protected
setEnabledSuffixing(bool $enabledSuffixing) : $this
Parameters
- $enabledSuffixing : bool
Return values
$this —setHasClassName()
Allows child generators to modify the internal `$hasClassName` flag.
protected
setHasClassName(bool $hasClassName) : $this
Parameters
- $hasClassName : bool
Return values
$this —setSortImports()
Allows child generators to modify the internal `$sortImports` flag.
protected
setSortImports(bool $sortImports) : $this
Parameters
- $sortImports : bool
Return values
$this —showError()
A simple method to display an error with line/file, in child commands.
protected
showError(Throwable $e) : mixed
Parameters
- $e : Throwable