Derafu: Console - Symfony Console integration for the Derafu Kernel.
What this package provides
Derafu\Console\DependencyInjection\CommandCompilerPass: collects every service taggedconsole.commandinto aconsole.command_idscontainer parameter.Derafu\Console\ConsoleKernelTrait: adds command auto-discovery and arun(): intmethod to any class extendingDerafu\Kernel\MicroKernel(or providing an equivalentgetContainer(): ContainerInterface).Derafu\Console\Kernel: a ready-to-use console Kernel for projects that do not need to compose console support into an existing Kernel.
This package does not depend on derafu/http or any HTTP-related package.
It has no opinion on whether a project reuses its main application Kernel,
a dedicated console-only subclass of it, or a fresh one — that decision
belongs entirely to each project.
Usage
A project with no other Kernel (simplest case)
// bin/console
use Derafu\Console\Kernel;
require dirname(__DIR__) . '/vendor/autoload.php';
$kernel = new Kernel($_ENV['APP_ENV'] ?? 'dev', (bool) ($_ENV['APP_DEBUG'] ?? true));
exit($kernel->run());
Kernel reads services.yaml from the environment’s configuration
directory. Any service in it whose class extends
Symfony\Component\Console\Command\Command is discovered automatically.
A project that already has its own Kernel
Use ConsoleKernelTrait directly on a dedicated subclass, so the main
Kernel is not forced to carry console-specific wiring it may rarely need:
use Derafu\Console\ConsoleKernelTrait;
class ConsoleApplication extends Application // your project's own Kernel.
{
use ConsoleKernelTrait;
protected function configure(
ContainerConfigurator $configurator,
ContainerBuilder $container
): void {
parent::configure($configurator, $container);
$this->configureConsole($container);
}
}
// bin/console
use App\ConsoleApplication;
require dirname(__DIR__) . '/vendor/autoload.php';
$kernel = new ConsoleApplication($_ENV['APP_ENV'] ?? 'dev', (bool) ($_ENV['APP_DEBUG'] ?? true));
exit($kernel->run());
The same applies if the console needs to share the exact same
services.yaml as, e.g., an HTTP Kernel: extend that Kernel instead of
Derafu\Console\Kernel and use ConsoleKernelTrait the same way.
Customizing the application name and version
Set these as container parameters (e.g. in services.yaml) and they will
be picked up automatically:
parameters:
kernel.app_name: 'My CLI'
kernel.app_version: '1.0.0'