Console Application Workflow
Table of Contents
Introduction
Apex uses a single point of entry for console applications. When typing php apex
into the console, the apex
bash file is executed, which instantiates the application and handles the request. Here's a breakdown of the workflow of a typical Apex console application:
Workflow
- User types
php apex foo bar --baz=blah
apex
bash script loads bootstrap/console/start.php, which instantiates anApplication
object- Various configs are read, and bootstrappers are registered
- Pre-start tasks are run
- Bootstrappers' bindings are registered by the bootstrapper
Dispatcher
- Bootstrappers are run by the bootstrapper
Dispatcher
- Bootstrappers' bindings are registered by the bootstrapper
- The application is started
- A console
Kernel
is instantiated with a request parser, the raw string input, and the response to write output to - The
Kernel
uses the request parser to parse the input into aRequest
object- This contains the command name ("foo") and any arguments ("bar") and options ("--baz=blah")
- The command class whose
name
property matches the input command name is instantiated - A command compiler compiles the command with the
Request
- The command is executed
- A response compiler compiles any output produced by the command
- A lexer lexes the raw response into a stream of tokens
- A parser converts the tokens into an abstract syntax tree
- The compiler compiles the abstract syntax tree into ANSI codes used to style the output
- Output is written to the kernel's
Response
, and the command's status code is returned - Post-start tasks are run
- Pre-shutdown tasks are run
- The application is shut down
- Post-shutdown tasks are run