Packages

Console

The console component can be used as a standalone package to build console applications.

Installation and usage

Tempest's console component can be used standalone. You simply need to require the tempest/console package:

composer require tempest/console:1.0-beta.1

Once installed, you may boot a console application as follows.

./my-cli
#!/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 discover all console commands within namespaces configured as valid PSR-4 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 may provide a custom Tempest\Core\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();