API Reference

Complete API reference for WPZylos CLI Core classes.

StubCompiler

Namespace: WPZylos\Framework\Cli\Core

Constructor

public function __construct(string $stubPath)
ParameterTypeDescription
$stubPathstringPath to stubs directory

Methods

compile()

public function compile(string $stubName, array $replacements = []): string

Compile a stub file with token replacements.

ParameterTypeDescription
$stubNamestringStub filename (without .stub)
$replacementsarray<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.

ParameterTypeDescription
$stubNamestringStub filename
$slugstringPlugin slug
$prefixstringDatabase prefix
$textDomainstringText domain
$namespacestringPHP namespace
$extraarray<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.

ParameterTypeDescription
$defaultsarray<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)
ParameterTypeDefaultDescription
$overwriteboolfalseOverwrite existing files
$dirPermissionsint0755Directory permissions

Methods

write()

public function write(string $path, string $content): bool

Write content to file.

ParameterTypeDescription
$pathstringFile path
$contentstringFile 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.

ParameterTypeDescription
$pathstringFile path
$contentstringFile content

Returns: bool — True if written, false if skipped


setOverwrite()

public function setOverwrite(bool $overwrite): static

Set overwrite mode.

ParameterTypeDescription
$overwriteboolOverwrite mode

Generator (Abstract)

Namespace: WPZylos\Framework\Cli\Core

Constructor

public function __construct(StubCompiler $compiler, FileWriter $writer, string $basePath)
ParameterTypeDescription
$compilerStubCompilerStub compiler instance
$writerFileWriterFile writer instance
$basePathstringPlugin base path

Abstract Methods

generate()

abstract public function generate(string $name, array $options = []): array

Generate files. Must be implemented by subclasses.

ParameterTypeDescription
$namestringItem name
$optionsarray<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'