Implement commands

This commit is contained in:
Tim
2023-08-16 16:04:35 +02:00
parent 1ee5c1c992
commit f8d1c66934
17 changed files with 200 additions and 48 deletions

View File

@ -0,0 +1,17 @@
<?php
namespace App\Console;
use Ardent\Undercurrent\Attribute\Command;
use Ardent\Undercurrent\Console\BaseCommand;
use Ardent\Undercurrent\Console\Output;
#[Command('app:test')]
class TestCommand extends BaseCommand
{
protected function run(Output $output): void
{
$output->printLine('Hello, command!');
}
}

View File

@ -7,7 +7,7 @@ use App\View\RouteView;
use Ardent\Undercurrent\Attribute\Route;
use Ardent\Undercurrent\Http\GenericResponse;
use Ardent\Undercurrent\Http\ResponseInterface;
use Ardent\Undercurrent\Http\RouterConfig;
use Ardent\Undercurrent\Http\RoutesConfig;
use Ardent\Undercurrent\Http\StatusEnum;
use Ardent\Undercurrent\View\BaseView;
use Ardent\Undercurrent\View\ViewInterface;
@ -40,7 +40,7 @@ class HelloWorldController
}
#[Route('/routes')]
public function routes(RouterConfig $config): ViewInterface
public function routes(RoutesConfig $config): ViewInterface
{
return new RouteView($config);
}

View File

@ -10,4 +10,22 @@ class Book
{
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
private int $id;
#[ORM\Column]
private string $title;
public function getId(): int
{
return $this->id;
}
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): void
{
$this->title = $title;
}
}

View File

@ -2,16 +2,23 @@
namespace App;
use App\Console\TestCommand;
use App\Controller\HelloWorldController;
use Ardent\Undercurrent\Console\CommandsConfig;
use Ardent\Undercurrent\Container\ContainerInterface;
use Ardent\Undercurrent\Http\RoutesConfig;
use Ardent\Undercurrent\Kernel\BaseKernel;
class Kernel extends BaseKernel
{
protected function dependencies(ContainerInterface $container): void
{
$this->addControllers($container, [
HelloWorldController::class,
]);
$routes = new RoutesConfig();
$routes->add(HelloWorldController::class);
$this->addControllers($container, $routes);
$commands = new CommandsConfig();
$commands->add(TestCommand::class);
$this->addCommands($container, $commands);
}
}

View File

@ -2,12 +2,12 @@
namespace App\View;
use Ardent\Undercurrent\Http\RouterConfig;
use Ardent\Undercurrent\Http\RoutesConfig;
use Ardent\Undercurrent\View\BaseView;
class RouteView extends BaseView
{
public function __construct(protected readonly RouterConfig $routes)
public function __construct(protected readonly RoutesConfig $routes)
{
parent::__construct('/routes.php', extends: '/base');
}

View File

@ -3,9 +3,12 @@
use App\Kernel;
use Ardent\Undercurrent\Config\AppConfig;
use Ardent\Undercurrent\Console\Console;
require_once dirname(__DIR__) . '/vendor/autoload.php';
$kernel = new Kernel(new AppConfig(__DIR__ . '/../app'));
$container = $kernel->setup();
$console = new Console($container);
$console->run();