Skip to content

Customize The Application

Bertie2011 edited this page Aug 29, 2021 · 2 revisions

Global Behavior

The global behaviour can be modified as follows:

  • $this->enableCommandAutoload() to enable command autoloading.
  • Creating a new CLIFramework\ServiceContainer, overriding known fields with custom implementations and passing it to the CLIFramework\Application constructor.
  • runWithTry($argv) catches some exceptions (like malformatted commands) and prints them nicely, while run($argv) does not catch any exceptions.

Options

Application options are registered the same as command options. The default implementation has quite a few useful built-in options. To keep these options enabled, make sure to call parent::options($opts) in the overridden options($opts): void method.

Commands

Application commands are registered the same as subcommands. The default implemenation has several built-in commands. Call parent::init() in the overriden init(): void method to keep these commands active. Even without calling the parent implementation, you probably always want to register the built-in help command using $this->command('help', \CLIFramework\Command\HelpCommand::class).

Lifecycle Hooks

Application lifecycle hooks are the same as the command lifecycle hooks, but you cannot implement the execute method.