Repository navigation
Internals Cli Commands RoutesCommand
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/cli/commands/RoutesCommand.php · Snapshot 8411f4287706.
The CLI registers command objects and executes one command, then returns to a readline loop. Help and clear have special handling in the loop.
use cli\interfaces\CLICommand;
use object\ObjectFactory;class RoutesCommand implements CLICommandDeclarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.
| Member | Declaration | Purpose or source contract |
|---|---|---|
| $lastResult | private string $lastResult = ''; |
Used by execute(), result(). |
| $routes | private array $routes = []; |
Used by addRoutes(), execute(). |
| Method | Signature |
|---|---|
| addRoutes | public function addRoutes(array $routes): void |
| getCommand | public function getCommand(): string |
| getHelp | public function getHelp(): string |
| getArguments | public function getArguments(): array |
| execute | public function execute(string $command, array $args = []): void |
| result | public function result(): string |
public function addRoutes(array $routes): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$routes |
array $routes |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->routes[].
Implementation, validation guards and interaction order
public function addRoutes(array $routes): void
{
$this->routes[] = $routes;
}public function getCommand(): stringReturn expressions (including local callbacks): 'routes'.
Implementation, validation guards and interaction order
public function getCommand(): string
{
return 'routes';
}public function getHelp(): stringReturn expressions (including local callbacks): "Displays all registered routes".
Implementation, validation guards and interaction order
public function getHelp(): string
{
return "Displays all registered routes";
}public function getArguments(): arrayReturn expressions (including local callbacks): ["No arguments"].
Implementation, validation guards and interaction order
public function getArguments(): array
{
return ["No arguments"];
}public function execute(string $command, array $args = []): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$command |
string $command |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$args |
array $args = [] |
Ordered arguments passed to the command or method. |
State writes: $this->lastResult.
Implementation, validation guards and interaction order
public function execute(string $command, array $args = []): void
{
$colors = [
'name' => "\033[1;34m", // Blue
'path' => "\033[1;32m", // Green
'action' => "\033[1;33m", // Yellow
'controller' => "\033[1;35m", // Magenta
'lazy' => "\033[1;36m",
'reset' => "\033[0m"
];
$colWidths = [
'name' => 20,
'path' => 100,
'action' => 20,
'controller' => 25,
'lazy' => 25
];
$this->lastResult = sprintf(
"%-{$colWidths['name']}s %-{$colWidths['path']}s %-{$colWidths['action']}s %-{$colWidths['controller']}s %-{$colWidths['lazy']}s\n",
'Name', 'Path', 'Action', 'Controller', 'Lazy controller'
);
$this->lastResult .= str_repeat('-', array_sum($colWidths)) . PHP_EOL;
foreach ($this->routes as $router => $route) {
foreach ($route as $finalRoute) {
$lazyLoaded = false;
if($finalRoute->getController() instanceof ObjectFactory)
$lazyLoaded = true;
$this->lastResult .= sprintf(
"%s%-{$colWidths['name']}s%s %s%-{$colWidths['path']}s%s %s%-{$colWidths['action']}s%s %s%-{$colWidths['controller']}s%s %s%-{$colWidths['lazy']}s%s\n",
$colors['name'], $finalRoute->getName(), $colors['reset'],
$colors['path'], $finalRoute->getPath(), $colors['reset'],
$colors['action'], $finalRoute->getAction(), $colors['reset'],
$colors['controller'], $finalRoute->getController()->controllerName ?? "Unknown Controller", $colors['reset'],
$colors['lazy'], $lazyLoaded ? 'Yes' : 'No', $colors['reset']
);
}
}
}public function result(): stringReturn expressions (including local callbacks): $this->lastResult.
Implementation, validation guards and interaction order
/**
* @inheritDoc
*/
public function result(): string
{
return $this->lastResult;
}AWT Framework Wiki · Home · Installation Guide · Developer Guide · Framework Internals
Philosophy · Architecture · Known discrepancies · Verification
Installation Guide
Developer Guide
- Learning sequence
- First package
- Package structure
- Lifecycle
- Runtimes
- Events and objects
- Routing and controllers
- Views and resources
- Database and models
- Storage and caching
- Configuration and CLI
- Responses and errors
- Extension points
Framework Internals
- Architecture
- Bootstrap
- Packages
- Runtime
- Events and context
- Objects
- HTTP routing and controllers
- Rendering
- Blade integration
- Database
- Models
- Storage and caching
- Settings
- CLI
- Identity and sessions
- Responses
- Errors
- Complete source inventory
Documentation notes