GeneratorTools
in package
Uses
ConsoleOutputTrait
Generator tools.
Tags
Table of Contents
- $config : array<string|int, mixed>
- Laminas configuration
- $outputInterface : OutputInterface
- Output interface.
- __construct() : mixed
- Constructor.
- backUpFile() : void
- Create a backup of a file.
- createPlugin() : bool
- Create a plugin class.
- extendClass() : bool
- Extend a class defined somewhere in the service manager or its child plugin managers.
- extendService() : bool
- Extend a service defined in module.config.php.
- getModuleConfigPath() : string
- Get the path to the module configuration; throw an exception if it is missing.
- setOutputInterface() : mixed
- Set the output interface. Implements a fluent interface.
- writeln() : mixed
- Write a line to the output (if available). Implements a fluent interface.
- writeModuleConfig() : void
- Write a module configuration.
- applySettingToConfig() : void
- Apply a single setting to a configuration array.
- cloneFactory() : string
- Create a new subclass and factory to override a factory-generated service.
- createClassInModule() : void
- Extend a specified class within a specified module. Return the name of the new subclass.
- createSubclassInModule() : string
- Extend a specified class within a specified module. Return the name of the new subclass.
- createTree() : void
- Create a directory tree.
- generateFactory() : void
- Generate a factory class.
- generateLocalClassName() : string
- Determine the name of a local replacement class within the specified module.
- getAllDelegatorsFromContainer() : array<string|int, mixed>
- Get a list of delegators in the provided container.
- getAllFactoriesFromContainer() : array<string|int, mixed>
- Get a list of factories in the provided container.
- getConfigPathForClass() : array<string|int, mixed>
- Given a plugin manager class name, return the configuration path for that plugin manager.
- getDelegatorsFromContainer() : array<string|int, mixed>
- Get delegators from the provided container (or empty array if undefined).
- getExpectedInterfaceFromPluginManager() : string
- Given a plugin manager object, return the interface plugins of that type must implement.
- getFactoryFromContainer() : string
- Get a factory from the provided container (or null if undefined).
- getPluginManagerContainingClass() : ContainerInterface
- Search all plugin managers for one containing the requested class (or return null if none found).
- getPluginManagerForClassParts() : ContainerInterface
- Given appropriate inputs, figure out which plugin manager or service manager to use during plugin generation.
- getPluginManagerForNamespace() : string
- Determine a plugin manager name within the specified namespace.
- getPluginManagerFromExplodedClassName() : string
- Given a class name exploded into an array, figure out the appropriate plugin manager to use.
- getShortNameFromExplodedClassName() : string
- Given a class name exploded into an array, figure out the appropriate short name to use as an alias in the service manager configuration.
- getVuFindExtendedModules() : array<string|int, mixed>
- Get a list of VuFind modules (only those with names beginning with VuFind, and not including the core VuFind module itself).
- retrieveConfig() : mixed
- Retrieve a value from the application configuration (or return false if the path is not found).
- updateFactory() : void
- Given a factory method, extend the class being constructed and create a new factory for the subclass.
- writeClass() : void
- Write a class to disk.
- writeNewConfig() : void
- Update the configuration of a target module with a single setting.
- writeNewConfigs() : void
- Update the configuration of a target module with multiple settings.
Properties
$config
Laminas configuration
protected
array<string|int, mixed>
$config
$outputInterface
Output interface.
protected
OutputInterface
$outputInterface
= null
Methods
__construct()
Constructor.
public
__construct(array<string|int, mixed> $config) : mixed
Parameters
- $config : array<string|int, mixed>
-
Laminas configuration
Return values
mixed —backUpFile()
Create a backup of a file.
public
backUpFile(string $filename) : void
Parameters
- $filename : string
-
File to back up
Tags
Return values
void —createPlugin()
Create a plugin class.
public
createPlugin(ContainerInterface $container, string $class[, string $factory = null ][, bool $topLevelService = false ]) : bool
Parameters
- $container : ContainerInterface
-
Service manager
- $class : string
-
Class name to create
- $factory : string = null
-
Existing factory to use (null to generate a new one)
- $topLevelService : bool = false
-
Set to true to build a service in the top-level container rather than a plugin in a subsidiary plugin manager
Tags
Return values
bool —extendClass()
Extend a class defined somewhere in the service manager or its child plugin managers.
public
extendClass(ContainerInterface $container, string $class, string $target[, bool $extendFactory = false ]) : bool
Parameters
- $container : ContainerInterface
-
Service manager
- $class : string
-
Class name to extend
- $target : string
-
Target module in which to create new service
- $extendFactory : bool = false
-
Should we extend the factory?
Tags
Return values
bool —extendService()
Extend a service defined in module.config.php.
public
extendService(string $source, string $target) : bool
Parameters
- $source : string
-
Configuration path to use as source
- $target : string
-
Target module in which to create new service
Tags
Return values
bool —getModuleConfigPath()
Get the path to the module configuration; throw an exception if it is missing.
public
getModuleConfigPath(string $module) : string
Parameters
- $module : string
-
Module name
Tags
Return values
string —setOutputInterface()
Set the output interface. Implements a fluent interface.
public
setOutputInterface(OutputInterface $output) : mixed
Parameters
- $output : OutputInterface
-
Output interface
Return values
mixed —writeln()
Write a line to the output (if available). Implements a fluent interface.
public
writeln(string $output) : mixed
Parameters
- $output : string
-
Line to output.
Return values
mixed —writeModuleConfig()
Write a module configuration.
public
writeModuleConfig(string $configPath, string $config) : void
Parameters
- $configPath : string
-
Path to write to
- $config : string
-
Configuration array to write
Tags
Return values
void —applySettingToConfig()
Apply a single setting to a configuration array.
protected
applySettingToConfig(array<string|int, mixed> $path, string|array<string|int, mixed> $setting, array<string|int, mixed> &$config) : void
Parameters
- $path : array<string|int, mixed>
-
Representation of path in config array
- $setting : string|array<string|int, mixed>
-
New setting to write into config
- $config : array<string|int, mixed>
-
Configuration array (passed by reference)
Return values
void —cloneFactory()
Create a new subclass and factory to override a factory-generated service.
protected
cloneFactory(mixed $factory, string $module) : string
Parameters
- $factory : mixed
-
Factory configuration for class to extend
- $module : string
-
Module in which to create the new factory
Tags
Return values
string —createClassInModule()
Extend a specified class within a specified module. Return the name of the new subclass.
protected
createClassInModule(string $class, string $module[, string $parent = null ][, array<string|int, string> $interfaces = [] ][, callable $callback = null ]) : void
Parameters
- $class : string
-
Name of class to create
- $module : string
-
Module in which to create the new class
- $parent : string = null
-
Parent class (null for no parent)
- $interfaces : array<string|int, string> = []
-
Interfaces for class to implement
- $callback : callable = null
-
Callback to set up class generator
Tags
Return values
void —createSubclassInModule()
Extend a specified class within a specified module. Return the name of the new subclass.
protected
createSubclassInModule(string $class, string $module) : string
Parameters
- $class : string
-
Name of class to extend
- $module : string
-
Module in which to create the new class
Tags
Return values
string —createTree()
Create a directory tree.
protected
createTree(array<string|int, mixed> $path) : void
Parameters
- $path : array<string|int, mixed>
-
Array of subdirectories to create relative to APPLICATION_PATH
Tags
Return values
void —generateFactory()
Generate a factory class.
protected
generateFactory(string $factory, string $module) : void
Parameters
- $factory : string
-
Name of factory to generate
- $module : string
-
Name of module to generate factory within
Return values
void —generateLocalClassName()
Determine the name of a local replacement class within the specified module.
protected
generateLocalClassName(string $class, string $module) : string
Parameters
- $class : string
-
Name of class to extend/replace
- $module : string
-
Module in which to create the new class
Tags
Return values
string —getAllDelegatorsFromContainer()
Get a list of delegators in the provided container.
protected
getAllDelegatorsFromContainer(ContainerInterface $container) : array<string|int, mixed>
Parameters
- $container : ContainerInterface
-
Container to inspect
Return values
array<string|int, mixed> —getAllFactoriesFromContainer()
Get a list of factories in the provided container.
protected
getAllFactoriesFromContainer(ContainerInterface $container) : array<string|int, mixed>
Parameters
- $container : ContainerInterface
-
Container to inspect
Return values
array<string|int, mixed> —getConfigPathForClass()
Given a plugin manager class name, return the configuration path for that plugin manager.
protected
getConfigPathForClass(string $class) : array<string|int, mixed>
Parameters
- $class : string
-
Class name
Return values
array<string|int, mixed> —getDelegatorsFromContainer()
Get delegators from the provided container (or empty array if undefined).
protected
getDelegatorsFromContainer(ContainerInterface $container, string $class) : array<string|int, mixed>
Parameters
- $container : ContainerInterface
-
Container to inspect
- $class : string
-
Class whose delegators we want
Return values
array<string|int, mixed> —getExpectedInterfaceFromPluginManager()
Given a plugin manager object, return the interface plugins of that type must implement.
protected
getExpectedInterfaceFromPluginManager(ContainerInterface $pm) : string
Parameters
- $pm : ContainerInterface
-
Plugin manager
Return values
string —getFactoryFromContainer()
Get a factory from the provided container (or null if undefined).
protected
getFactoryFromContainer(ContainerInterface $container, string $class) : string
Parameters
- $container : ContainerInterface
-
Container to inspect
- $class : string
-
Class whose factory we want
Return values
string —getPluginManagerContainingClass()
Search all plugin managers for one containing the requested class (or return null if none found).
protected
getPluginManagerContainingClass(ContainerInterface $container, string $class) : ContainerInterface
Parameters
- $container : ContainerInterface
-
Service manager
- $class : string
-
Class to search for
Return values
ContainerInterface —getPluginManagerForClassParts()
Given appropriate inputs, figure out which plugin manager or service manager to use during plugin generation.
protected
getPluginManagerForClassParts(ContainerInterface $container, array<string|int, mixed> $classParts, bool $topLevelService) : ContainerInterface
Parameters
- $container : ContainerInterface
-
Service manager
- $classParts : array<string|int, mixed>
-
Exploded class name array
- $topLevelService : bool
-
Set to true to build a service in the top-level container rather than a plugin in a subsidiary plugin manager
Return values
ContainerInterface —getPluginManagerForNamespace()
Determine a plugin manager name within the specified namespace.
protected
getPluginManagerForNamespace(array<string|int, mixed> $classParts, string $namespace) : string
Parameters
- $classParts : array<string|int, mixed>
-
Exploded class name array
- $namespace : string
-
Namespace to try for plugin manager
Return values
string —getPluginManagerFromExplodedClassName()
Given a class name exploded into an array, figure out the appropriate plugin manager to use.
protected
getPluginManagerFromExplodedClassName(array<string|int, mixed> $classParts) : string
Parameters
- $classParts : array<string|int, mixed>
-
Exploded class name array
Return values
string —getShortNameFromExplodedClassName()
Given a class name exploded into an array, figure out the appropriate short name to use as an alias in the service manager configuration.
protected
getShortNameFromExplodedClassName(array<string|int, mixed> $classParts) : string
Parameters
- $classParts : array<string|int, mixed>
-
Exploded class name array
Return values
string —getVuFindExtendedModules()
Get a list of VuFind modules (only those with names beginning with VuFind, and not including the core VuFind module itself).
protected
getVuFindExtendedModules() : array<string|int, mixed>
Return values
array<string|int, mixed> —retrieveConfig()
Retrieve a value from the application configuration (or return false if the path is not found).
protected
retrieveConfig(array<string|int, mixed> $path) : mixed
Parameters
- $path : array<string|int, mixed>
-
Path to walk through configuration
Return values
mixed —updateFactory()
Given a factory method, extend the class being constructed and create a new factory for the subclass.
protected
updateFactory(MethodGenerator $method, string $ns, string $module) : void
Parameters
- $method : MethodGenerator
-
Method to modify
- $ns : string
-
Namespace of old factory
- $module : string
-
Module in which to make changes
Tags
Return values
void —writeClass()
Write a class to disk.
protected
writeClass(ClassGenerator $classGenerator, string $module[, bool $allowOverwrite = false ][, bool $skipBackup = false ]) : void
Parameters
- $classGenerator : ClassGenerator
-
Representation of class to write
- $module : string
-
Module in which to write class
- $allowOverwrite : bool = false
-
Allow overwrite of existing file?
- $skipBackup : bool = false
-
Should we skip backing up the file?
Tags
Return values
void —writeNewConfig()
Update the configuration of a target module with a single setting.
protected
writeNewConfig(array<string|int, mixed> $path, string|array<string|int, mixed> $setting, string $module[, bool $backup = true ]) : void
Parameters
- $path : array<string|int, mixed>
-
Representation of path in config array
- $setting : string|array<string|int, mixed>
-
New setting to write into config
- $module : string
-
Module in which to write the configuration
- $backup : bool = true
-
Should we back up the existing config?
Tags
Return values
void —writeNewConfigs()
Update the configuration of a target module with multiple settings.
protected
writeNewConfigs(array<string|int, mixed> $newValues, string $module[, bool $backup = true ]) : void
Parameters
- $newValues : array<string|int, mixed>
-
An array of arrays containing 'path' and 'setting' keys to specify changes to the configuration.
- $module : string
-
Module in which to write the configuration
- $backup : bool = true
-
Should we back up the existing config?