Implement commands
This commit is contained in:
17
app/Console/TestCommand.php
Normal file
17
app/Console/TestCommand.php
Normal 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!');
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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');
|
||||
}
|
||||
|
@ -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();
|
Reference in New Issue
Block a user