scedel/codegen-symfony

Symfony class generator for Scedel schemas

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/scedel/codegen-symfony

0.2.1 2026-02-18 16:30 UTC

This package is auto-updated.

Last update: 2026-02-18 16:37:32 UTC


README

logo

Generates Symfony-ready PHP classes from Scedel schemas (SchemaRepository) with symfony/validator attributes.

RFC support

What it does

  • Builds DTO-like classes for custom record-like Scedel types.
  • Maps many builtin Scedel constraints to Symfony Assert\* attributes.
  • Understands control annotations under php.* and php.symfony.*.
  • Returns warnings for unsupported/ambiguous constructs.

API usage

use Scedel\Codegen\Symfony\SymfonyCodeGenerator;
use Scedel\Codegen\Symfony\SymfonyCodegenOptions;

$generator = new SymfonyCodeGenerator();
$result = $generator->generate(
    $repository,
    new SymfonyCodegenOptions(
        outputDir: 'src/Dto/Scedel',
        defaultNamespace: 'App\\Dto\\Scedel',
    ),
);

foreach ($result->files as $file) {
    file_put_contents($file->path, $file->contents);
}

CLI

php scedel-codegen-symfony/bin/generate-symfony.php \
  --output-dir src/Dto/Scedel \
  --namespace App\\Dto\\Scedel \
  /absolute/path/schema.scedel

Supported control annotations

Type-level:

  • @php.codegen.namespace = "App\\Dto"
  • @php.codegen.dir = "src/Dto"
  • @php.codegen.class = "PostDto"
  • @php.codegen.file = "PostDto.php"
  • @php.symfony.ignore = "true"
  • @php.symfony.validation.groups = "create,update"
  • @php.symfony.constraint... = "..."

Field-level:

  • @php.codegen.property = "authorEmail"
  • @php.symfony.ignore = "true"
  • @php.symfony.type = "?string"
  • @php.symfony.not_blank = "true"
  • @php.symfony.validation.groups = "create"
  • @php.symfony.constraint... = "..."

Custom constraint injection:

  • @php.symfony.constraint = "Length(min: 3, max: 255)"
  • @php.symfony.constraint.primary = "NotBlank"
  • @php.symfony.constraint.secondary = "Regex(pattern: '/^[A-Z]+$/')"

If the value does not start with Assert\, generator prepends it automatically.

Notes

  • Non-record-like custom types are skipped with warnings.
  • Inline record fields are generated as array with warnings.
  • Conditional types are simplified (best-effort mapping + warnings).
  • Unsupported Scedel validators/arguments are reported in warnings.