Console
Installation and usage
Tempest's console component can be used standalone. You simply need to require the tempest/console package:
composer require tempest/console
Once installed, you may boot a console application as follows.
#!/usr/bin/env php <?php use Tempest\Console\ConsoleApplication; require_once __DIR__ . '/vendor/autoload.php'; ConsoleApplication::boot()->run();
Registering commands
tempest/console relies on 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.
You may read more about building commands in the dedicated documentation.
Configuring discovery
Tempest will automatically discover all console commands from multiple sources:
- Core Tempest packages — Built-in commands from Tempest itself
- Vendor packages — Third-party packages that require
tempest/frameworkortempest/core - App namespaces — All namespaces configured as PSR-4 autoload paths in your
composer.json
{ "autoload": { "psr-4": { "App\\": "app/" } } }
In case you need more fine-grained control over which directories to discover, you may provide additional discovery locations to the ConsoleApplication::boot() method:
use Tempest\Console\ConsoleApplication; use Tempest\Discovery\DiscoveryLocation; ConsoleApplication::boot( discoveryLocations: [ new DiscoveryLocation( namespace: 'MyApp\\', path: __DIR__ . '/src', ), ], )->run();
The boot() method accepts the following parameters:
$name— The application name (default:'Tempest')$root— The root directory (default: current working directory)$discoveryLocations— Additional discovery locations to append to the auto-discovered ones