GeneratorTrait
GeneratorTrait contains a collection of methods to build the commands that generates a file.
Table of Contents
- $classNameLang : string
- Language string key for required class names.
- $component : string
- Component Name
- $directory : string
- File directory
- $template : string
- View template name
- 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.
- 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.
Properties
$classNameLang
Language string key for required class names.
protected
string
$classNameLang
= ''
$component
Component Name
protected
string
$component
$directory
File directory
protected
string
$directory
$template
View template name
protected
string
$template
Methods
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 —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