Skip to content

GeneratorSupport

Shared validation/overwrite-guard helpers for the make:* generator commands, mirroring the checks NewCommand already applies to its own --namespace argument (see NewCommand::execute()).

final class GeneratorSupport

SourceConsole/Command/Scaffold/GeneratorSupport.php
MethodDescription
appDir(): stringReturns the application root directory the generators write into, from core.app_dir.
appNamespace(): stringReturns the root namespace for generated classes, from core.namespace_prefix and defaulting to App.
guardOverwrite(string $path, bool $force): void
requireString(mixed $value, string $label): stringSymfony Console’s getArgument()/getOption() are typed mixed; every caller here expects a scalar string.
validateClassNameSegment(string $name): void
writeFile(string $path, string $content): voidWrites a generated file, creating its parent directory tree if needed.

public static function appDir(): string

Returns the application root directory the generators write into, from core.app_dir.

Returns string

public static function appNamespace(): string

Returns the root namespace for generated classes, from core.namespace_prefix and defaulting to App.

Surrounding backslashes are trimmed, so the result is always usable as a namespace segment that callers can concatenate to.

Returns string

public static function guardOverwrite(string $path, bool $force): void

ParameterTypeDescription
$pathstring
$forcebool
ThrowsWhen
ConfigurationExceptionif $path exists and $force is false

public static function requireString(mixed $value, string $label): string

Symfony Console’s getArgument()/getOption() are typed mixed; every caller here expects a scalar string.

ParameterTypeDescription
$valuemixed
$labelstring

Returns string

public static function validateClassNameSegment(string $name): void

ParameterTypeDescription
$namestring
ThrowsWhen
ConfigurationExceptionif $name is not a valid PHP class-name segment

public static function writeFile(string $path, string $content): void

Writes a generated file, creating its parent directory tree if needed.

Overwrites unconditionally — call GeneratorSupport::guardOverwrite() first if the command honours a --force flag. Both the directory creation and the write are error-suppressed so the generator reports one clear exception instead of a raw PHP warning followed by it.

ParameterTypeDescription
$pathstring
$contentstring
ThrowsWhen
ConfigurationExceptionIf the directory cannot be created or the file cannot be written.