Getting Started
tempest/console
is a standalone package used to build console applications. Give it a ⭐️ on GitHub!
You can install tempest/console
like so:
composer require tempest/console:1.0-alpha.4
And run it like so:
#!/usr/bin/env php <?php use Tempest\Console\ConsoleApplication; require_once __DIR__ . '/vendor/autoload.php'; ConsoleApplication::boot()->run();
Configuration
tempest/console
uses on Tempest's discovery to find and register console commands. That means you don't have to register any commands manually, and any method within your codebase using the #[ConsoleCommand]
attribute will automatically be discovered by your console application.
// app/InteractiveCommand.php use Tempest\Console\Console; use Tempest\Console\ConsoleCommand; final readonly class InteractiveCommand { public function __construct( private Console $console, ) {} #[ConsoleCommand('hello:world')] public function __invoke(): void { $this->console->writeln('Hello World!'); } }
Tempest will discover all console commands within namespaces configured as composer PSR-4 autoload namespaces, as well as all third-party packages that require Tempest.
"autoload": { "psr-4": { "App\\": "app/" } },
In case you need more fine-grained control over which directories to discover, you can provide a custom AppConfig
instance to the ConsoleApplication::boot()
method:
use Tempest\AppConfig; use Tempest\Core\DiscoveryLocation; use Tempest\Console\ConsoleApplication; $appConfig = new AppConfig( discoveryLocations: [ new DiscoveryLocation( namespace: 'App\\', path: __DIR__ . '/app/', ), ], ); ConsoleApplication::boot(appConfig: $appConfig)->run();