Generator
in package
Tags
Table of Contents
Properties
- $fileManager : FileManager
- $generatedFiles : array<string|int, mixed>
- $namespacePrefix : string
- $pendingOperations : array<string|int, mixed>
- $templateComponentGenerator : TemplateComponentGenerator|null
- $twigHelper : GeneratorTwigHelper
Methods
- __construct() : mixed
- createClassNameDetails() : ClassNameDetails
- Creates a helper object to get data about a class name.
- dumpFile() : void
- generateClass() : string
- Generate a new file for a class from a template.
- generateController() : string
- generateFile() : void
- Generate a normal file from a template.
- generateTemplate() : void
- Generate a template file.
- getControllerBaseClass() : ClassNameDetails
- getFileContentsForPendingOperation() : string
- getGeneratedFiles() : array<string|int, mixed>
- Get the full path of each file created by the Generator.
- getRootDirectory() : string
- getRootNamespace() : string
- hasPendingOperations() : bool
- writeChanges() : void
- Actually writes and file changes that are pending.
- addOperation() : void
Properties
$fileManager
private
FileManager
$fileManager
$generatedFiles
private
array<string|int, mixed>
$generatedFiles
= []
$namespacePrefix
private
string
$namespacePrefix
$pendingOperations
private
array<string|int, mixed>
$pendingOperations
= []
$templateComponentGenerator
private
TemplateComponentGenerator|null
$templateComponentGenerator
$twigHelper
private
GeneratorTwigHelper
$twigHelper
Methods
__construct()
public
__construct(FileManager $fileManager, string $namespacePrefix[, PhpCompatUtil $phpCompatUtil = null ][, TemplateComponentGenerator $templateComponentGenerator = null ]) : mixed
Parameters
- $fileManager : FileManager
- $namespacePrefix : string
- $phpCompatUtil : PhpCompatUtil = null
- $templateComponentGenerator : TemplateComponentGenerator = null
createClassNameDetails()
Creates a helper object to get data about a class name.
public
createClassNameDetails(string $name, string $namespacePrefix[, string $suffix = '' ][, string $validationErrorMessage = '' ]) : ClassNameDetails
Examples:
// App\Entity\FeaturedProduct $gen->createClassNameDetails('FeaturedProduct', 'Entity'); $gen->createClassNameDetails('featured product', 'Entity');
// App\Controller\FooController $gen->createClassNameDetails('foo', 'Controller', 'Controller');
// App\Controller\Foo\AdminController $gen->createClassNameDetails('Foo\Admin', 'Controller', 'Controller');
// App\Security\Voter\CoolVoter $gen->createClassNameDetails('Cool', 'Security\Voter', 'Voter');
// Full class names can also be passed. Imagine the user has an autoload // rule where Cool\Stuff lives in a "lib/" directory // Cool\Stuff\BalloonController $gen->createClassNameDetails('Cool\Stuff\Balloon', 'Controller', 'Controller');
Parameters
- $name : string
-
The short "name" that will be turned into the class name
- $namespacePrefix : string
-
Recommended namespace where this class should live, but without the "App\" part
- $suffix : string = ''
-
Optional suffix to guarantee is on the end of the class
- $validationErrorMessage : string = ''
Return values
ClassNameDetailsdumpFile()
public
dumpFile(string $targetPath, string $contents) : void
Parameters
- $targetPath : string
- $contents : string
generateClass()
Generate a new file for a class from a template.
public
generateClass(string $className, string $templateName[, array<string|int, mixed> $variables = [] ]) : string
Parameters
- $className : string
-
The fully-qualified class name
- $templateName : string
-
Template name in Resources/skeleton to use
- $variables : array<string|int, mixed> = []
-
Array of variables to pass to the template
Tags
Return values
string —The path where the file will be created
generateController()
public
generateController(string $controllerClassName, string $controllerTemplatePath[, array<string|int, mixed> $parameters = [] ]) : string
Parameters
- $controllerClassName : string
- $controllerTemplatePath : string
- $parameters : array<string|int, mixed> = []
Return values
stringgenerateFile()
Generate a normal file from a template.
public
generateFile(string $targetPath, string $templateName[, array<string|int, mixed> $variables = [] ]) : void
Parameters
- $targetPath : string
- $templateName : string
- $variables : array<string|int, mixed> = []
generateTemplate()
Generate a template file.
public
generateTemplate(string $targetPath, string $templateName[, array<string|int, mixed> $variables = [] ]) : void
Parameters
- $targetPath : string
- $templateName : string
- $variables : array<string|int, mixed> = []
getControllerBaseClass()
public
static getControllerBaseClass() : ClassNameDetails
Tags
Return values
ClassNameDetailsgetFileContentsForPendingOperation()
public
getFileContentsForPendingOperation(string $targetPath) : string
Parameters
- $targetPath : string
Return values
stringgetGeneratedFiles()
Get the full path of each file created by the Generator.
public
getGeneratedFiles() : array<string|int, mixed>
Return values
array<string|int, mixed>getRootDirectory()
public
getRootDirectory() : string
Return values
stringgetRootNamespace()
public
getRootNamespace() : string
Return values
stringhasPendingOperations()
public
hasPendingOperations() : bool
Return values
boolwriteChanges()
Actually writes and file changes that are pending.
public
writeChanges() : void
addOperation()
private
addOperation(string $targetPath, string $templateName, array<string|int, mixed> $variables) : void
Parameters
- $targetPath : string
- $templateName : string
- $variables : array<string|int, mixed>