feat(console): add bin/camelia-orm with seed and make commands
Tests / PHP 8.4 (push) Failing after 3m23s

A command line for the library, kept deliberately small: no console
component, no dependency added to the consumer's tree.

- Application/Command/Input/Output: parsing, dispatch, exit codes and
  capturable output. Commands return an exit code instead of calling exit(),
  so every one is testable.
- seed: runs the registered SeederRunner inside one transaction, with
  --list and --only=name[,name].
- doctor: one round-trip that fails loudly when the DSN is wrong.
- make:model and make:seeder: live scaffolding into the consumer's code,
  sharing name validation, the overwrite guard and directory creation
  through MakeCommand.

The binary ships an empty runner; an application composes SeedCommand into
its own Application to register its seeders.
This commit is contained in:
dgarcia committed 2026-11-15 13:31:14 -03:00
1 parent 2acf2cc099
commit a655a6f3ae
16 files changed
+1576

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
#!/usr/bin/env php
<?php
declare(strict_types=1);
/**
* camelia/orm command line.
*
* Ships the commands that need no knowledge of the consumer's code (seed, doctor). Scaffolding
* commands write into the current working directory, so run this from the project root.
*/
use Camelia\Orm\Console\Application;
use Camelia\Orm\Console\Command\DoctorCommand;
use Camelia\Orm\Console\Command\MakeModelCommand;
use Camelia\Orm\Console\Command\MakeSeederCommand;
use Camelia\Orm\Console\Command\SeedCommand;
use Camelia\Orm\Console\Output;
use Camelia\Orm\Orm;
use Camelia\Orm\Seeding\SeederRunner;
$autoload = __DIR__ . '/../vendor/autoload.php';
if (!is_file($autoload)) {
fwrite(STDERR, "Run composer install first.\n");
exit(1);
}
require $autoload;
// The consumer's own autoloader is loaded when the binary is invoked from their project, so their
// seeders and models resolve. Composer already registers it by way of vendor/bin.
$ormFactory = static fn(): Orm => Orm::fromEnv();
$application = (new Application('camelia-orm', '1.0.0'))->add(
new SeedCommand($ormFactory, static fn(Orm $orm): SeederRunner => new SeederRunner($orm)),
new DoctorCommand($ormFactory),
new MakeModelCommand(),
new MakeSeederCommand(),
);
$decorated = stream_isatty(STDOUT) && getenv('NO_COLOR') === false;
exit($application->run($_SERVER['argv'] ?? [], Output::toStream(STDOUT, $decorated)));