Files
php-qml/framework/php/src/Maker/templates/Entity.tpl.php

72 lines
1.2 KiB
PHP
Raw Normal View History

Phase 2 sub-commit 4: make:bridge:resource maker Bundle picks up symfony/maker-bundle as require-dev. New BridgeResourceMaker under PhpQml\Bridge\Maker generates three files for a named resource: - src/Entity/<Name>.php — Doctrine entity with #[BridgeResource] and a UUIDv7 id by default. --int-id flips to auto-incrementing int IDs. - src/Controller/<Name>Controller.php — CRUD on /api/{plural} (list, create, update, delete) with serializer- normalised JSON responses. - {qml_path}/<Name>List.qml — starter ListView wrapped around a ReactiveListModel bound to the right topic and source URL. The Doctrine subscriber from sub-commit 2 picks the entity up automatically — no per-resource listener generated. The QML snippet target defaults to '../qml/' (relative to the Symfony project root) and is overridable via the maker's $qmlPath constructor arg. Templates live under src/Maker/templates/ as .tpl.php files using short-echo and alternative-syntax control structures by convention. PHPStan and php-cs-fixer skip them — the maker's Generator binds the template variables at render time. Skeleton picks up MakerBundle as a `dev` bundle and require-dev'd symfony/maker-bundle, so `bin/console make:bridge:resource Todo` works out-of-the-box. Verified: maker runs end-to-end against `Todo` and emits readable, syntactically valid output. composer quality (16 tests, 45 assertions, PHPStan clean, cs-fixer clean) stays green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 02:45:42 +02:00
<?= "<?php\n" ?>
declare(strict_types=1);
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use PhpQml\Bridge\Attribute\BridgeResource;
<?php if ($use_uuid): ?>
use Symfony\Component\Uid\Uuid;
<?php endif; ?>
#[ORM\Entity]
#[BridgeResource(name: '<?= $resource ?>')]
class <?= $entity_short ?>
{
<?php if ($use_uuid): ?>
#[ORM\Id]
#[ORM\Column(type: 'uuid', unique: true)]
private Uuid $id;
<?php else: ?>
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
<?php endif; ?>
#[ORM\Column(length: 255)]
private string $title = '';
#[ORM\Column]
private bool $done = false;
<?php if ($use_uuid): ?>
public function __construct()
{
$this->id = Uuid::v7();
}
public function getId(): Uuid
{
return $this->id;
}
<?php else: ?>
public function getId(): ?int
{
return $this->id;
}
<?php endif; ?>
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): void
{
$this->title = $title;
}
public function isDone(): bool
{
return $this->done;
}
public function setDone(bool $done): void
{
$this->done = $done;
}
}