API Reference
Complete API reference for WPZylos CLI Core classes.
StubCompiler
Namespace: WPZylos\Framework\Cli\Core
Constructor
public function __construct(string $stubPath)
| Parameter | Type | Description |
|---|---|---|
$stubPath | string | Path to stubs directory |
Methods
compile()
public function compile(string $stubName, array $replacements = []): string
Compile a stub file with token replacements.
| Parameter | Type | Description |
|---|---|---|
$stubName | string | Stub filename (without .stub) |
$replacements | array<string, string> | Token => value pairs |
Returns: string — Compiled content
Throws: InvalidArgumentException if stub not found, RuntimeException if unreadable
compileForPlugin()
public function compileForPlugin(
string $stubName,
string $slug,
string $prefix,
string $textDomain,
string $namespace,
array $extra = []
): string
Compile with plugin context tokens.
| Parameter | Type | Description |
|---|---|---|
$stubName | string | Stub filename |
$slug | string | Plugin slug |
$prefix | string | Database prefix |
$textDomain | string | Text domain |
$namespace | string | PHP namespace |
$extra | array<string, string> | Additional replacements |
Auto-added tokens:
{{slug}}— Plugin slug{{prefix}}— Database prefix{{textDomain}}— Text domain{{namespace}}— PHP namespace{{Slug}}— PascalCase slug{{PREFIX}}— Uppercase prefix
setDefaults()
public function setDefaults(array $defaults): static
Set default replacements for all compilations.
| Parameter | Type | Description |
|---|---|---|
$defaults | array<string, string> | Default token values |
getAvailable()
public function getAvailable(): array
Get list of available stub names.
Returns: string[] — Array of stub names (without .stub extension)
FileWriter
Namespace: WPZylos\Framework\Cli\Core
Constructor
public function __construct(bool $overwrite = false, int $dirPermissions = 0755)
| Parameter | Type | Default | Description |
|---|---|---|---|
$overwrite | bool | false | Overwrite existing files |
$dirPermissions | int | 0755 | Directory permissions |
Methods
write()
public function write(string $path, string $content): bool
Write content to file.
| Parameter | Type | Description |
|---|---|---|
$path | string | File path |
$content | string | File content |
Returns: bool — True on success
Throws: RuntimeException if file exists and overwrite is false, or write fails
writeIfNotExists()
public function writeIfNotExists(string $path, string $content): bool
Write only if file doesn't exist.
| Parameter | Type | Description |
|---|---|---|
$path | string | File path |
$content | string | File content |
Returns: bool — True if written, false if skipped
setOverwrite()
public function setOverwrite(bool $overwrite): static
Set overwrite mode.
| Parameter | Type | Description |
|---|---|---|
$overwrite | bool | Overwrite mode |
Generator (Abstract)
Namespace: WPZylos\Framework\Cli\Core
Constructor
public function __construct(StubCompiler $compiler, FileWriter $writer, string $basePath)
| Parameter | Type | Description |
|---|---|---|
$compiler | StubCompiler | Stub compiler instance |
$writer | FileWriter | File writer instance |
$basePath | string | Plugin base path |
Abstract Methods
generate()
abstract public function generate(string $name, array $options = []): array
Generate files. Must be implemented by subclasses.
| Parameter | Type | Description |
|---|---|---|
$name | string | Item name |
$options | array<string, mixed> | Generation options |
Returns: string[] — Paths of generated files
getStubName()
abstract protected function getStubName(): string
Get stub name for this generator.
getOutputPath()
abstract protected function getOutputPath(string $name): string
Get output path for generated file.
Helper Methods
toClassName()
protected function toClassName(string $name): string
Convert name to PascalCase class name.
$this->toClassName('my-thing'); // 'MyThing'
$this->toClassName('my_thing'); // 'MyThing'
toVariableName()
protected function toVariableName(string $name): string
Convert name to camelCase variable name.
$this->toVariableName('my-thing'); // 'myThing'
Related
- Usage Guide — Practical usage examples
- Examples — Real-world examples
- wpzylos.com — Full documentation