Overview

WPZylos CLI Core provides the foundation for building code generators and CLI tools.

Architecture

+-----------------+
—    Generator    — ? Your custom generator
+-----------------+
         — uses
    +---------+
    —         —
+---?----+ +---?---+
—Compiler— —Writer —
+--------+ +-------+
    —          —
+---?----------?---+
—   Stub Files     —
+------------------+

Components

StubCompiler

Reads .stub template files and replaces {{token}} placeholders with provided values.

$compiler = new StubCompiler('/path/to/stubs');
$content = $compiler->compile('controller', [
    'class' => 'ProductController',
]);

FileWriter

Safely writes content to files, creating directories as needed.

$writer = new FileWriter(overwrite: false);
$writer->write('/path/to/File.php', $content);

Generator

Abstract base class for building custom generators that combine compilation and file writing.

class MyGenerator extends Generator
{
    public function generate(string $name, array $options = []): array
    {
        $content = $this->compiler->compile($this->getStubName(), [...]);
        $this->writer->write($this->getOutputPath($name), $content);
        return [$this->getOutputPath($name)];
    }
}

Use Cases

  • Plugin scaffolding — Generate plugin boilerplate
  • Code generators — Create controllers, models, services
  • Migration generators — Database migration templates
  • Custom templates — Any file generation need