Search by

adachsoft / codegen-core

Arkadiusz Adach

Composable code generation primitives for parsing plans and describing file changes.

Package info

gitlab.com/a.adach/codegen-core

Issues

pkg:composer/adachsoft/codegen-core

Statistics

Installs: 12

Dependents: 1

Suggesters: 0

Stars: 0

v0.1.0 2026-11-22 21:23 UTC

This package is auto-updated.

Last update: 2026-11-22 20:24:07 UTC


README

A domain-neutral PHP library for composing code-generation pipelines. It parses operation plans, routes contexts to sources, validates source data, and returns typed descriptions of file changes. It does not modify the filesystem; the consuming application applies the returned changes.

Features

  • Extensible SourceInterface strategies selected by a context identifier.
  • JSON and array operation-plan parsing with input and relative-path validation.
  • Built-in sources for writing, deleting, moving, and copying files.
  • Immutable DTOs and typed collections for contexts, plans, and file changes.
  • CodegenEngine support checks and execution of one or all matching sources.

Installation

composer require adachsoft/codegen-core

Requirements

Usage

Register the built-in sources with the engine, parse a plan, and execute each operation. The application is responsible for applying each returned FileChangeInterface to its target filesystem or other storage.

use AdachSoft\CodegenCore\Collection\CodegenSourceCollection;
use AdachSoft\CodegenCore\Engine\CodegenEngine;
use AdachSoft\CodegenCore\Plan\CodegenPlanContextFactory;
use AdachSoft\CodegenCore\Plan\CodegenPlanParser;
use AdachSoft\CodegenCore\Plan\PlanOperationDataReader;
use AdachSoft\CodegenCore\Source\CopyFileSource;
use AdachSoft\CodegenCore\Source\MoveFileSource;
use AdachSoft\CodegenCore\Source\NewFileSource;
use AdachSoft\CodegenCore\Source\RemoveFileSource;

$plan = (new CodegenPlanParser())->parseJson($planJson);
$dataReader = new PlanOperationDataReader();
$engine = new CodegenEngine(new CodegenSourceCollection([
    new RemoveFileSource($dataReader),
    new MoveFileSource($dataReader),
    new CopyFileSource($dataReader),
    new NewFileSource($dataReader),
]));
$contextFactory = new CodegenPlanContextFactory();

foreach ($plan->operations as $operation) {
    $context = $contextFactory->createForOperation($operation);

    if (!$engine->supports($context)) {
        throw new RuntimeException(sprintf('No source supports action "%s".', $context->identifier));
    }

    foreach ($engine->runOne($context) as $change) {
        // Apply the returned file change in your application.
    }
}

See the operation plan example for a complete plan and integration notes. Implement SourceInterface and register additional sources to support domain-specific operations.

Development

composer install
vendor/bin/phpunit --configuration phpunit.xml
composer stan
composer cs:check