Implement doctrine orm as command

This commit is contained in:
Tim 2023-08-17 15:41:25 +02:00
parent f8d1c66934
commit 7a4a9257c3
3 changed files with 36 additions and 1 deletions

View File

@ -0,0 +1,33 @@
<?php
namespace App\Console;
use Ardent\Undercurrent\Attribute\Command;
use Ardent\Undercurrent\Console\BaseCommand;
use Ardent\Undercurrent\Console\Output;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
use Symfony\Component\Console\Input\ArgvInput;
#[Command('orm')]
class OrmCommand extends BaseCommand
{
public function __construct(
private readonly EntityManager $entityManager,
)
{
}
protected function run(Output $output): void
{
// strip out the 'orm' part to pass it on naturally
$argv = $_SERVER['argv'];
unset($argv[1]);
$argv = array_values($argv);
$cli = ConsoleRunner::createApplication(new SingleManagerProvider($this->entityManager));
$cli->run(new ArgvInput($argv));
}
}

View File

@ -2,6 +2,7 @@
namespace App;
use App\Console\OrmCommand;
use App\Console\TestCommand;
use App\Controller\HelloWorldController;
use Ardent\Undercurrent\Console\CommandsConfig;
@ -19,6 +20,7 @@ class Kernel extends BaseKernel
$commands = new CommandsConfig();
$commands->add(TestCommand::class);
$commands->add(OrmCommand::class);
$this->addCommands($container, $commands);
}
}