Návod
CLI
Commandy, registrace v YAML a předání delší práce do fronty.
Vytvoř command
Command implementuje CommandInterface s name(), description() a run(array $args): int. Třída commandu má zůstat jen orchestrace nad konkrétní úlohou.
<?php
declare(strict_types=1);
namespace App\Console;
use Lemonade\Framework\Cli\CommandInterface;
final class AboutCommand implements CommandInterface
{
public function name(): string
{
return 'about';
}
public function description(): string
{
return 'Display basic information about the application.';
}
public function run(array $args): int
{
unset($args);
fwrite(STDOUT, "Application is running\n");
return 0;
}
}Registruj a spusť command
Třídy commandů registruj v app/Config/Commands.yaml. Ve veřejné dokumentaci používej jednotný vstupní bod vendor/bin/lemonade, například vendor/bin/lemonade about.
module: commands
config:
commands:
- App\Console\AboutCommandCLI, úlohy a fronta
Commandy používej pro plánovanou nebo ručně spouštěnou práci. Delší navazující zpracování předej jako queue message a nech ho dokončit CLI workerem.
use Lemonade\Framework\Queue\QueueBusInterface;
final class PublishService
{
public function __construct(
private readonly QueueBusInterface $queue,
) {}
public function publish(int $articleId): void
{
$this->queue->dispatch(new PublishArticleMessage($articleId));
}
}