Skip to content

Internals Cli Commands RoutesCommand

Stefan Crkvenjakov edited this page Oct 7, 2026 · 1 revision

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.

Imports and dependencies

use cli\interfaces\CLICommand;
use object\ObjectFactory;

RoutesCommand

Declaration and architectural role

class RoutesCommand implements CLICommand

Constants, enum cases, traits and properties

Declarations 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 index

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

addRoutes

Source line 14

public function addRoutes(array $routes): void

Parameters

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;
    }

getCommand

Source line 19

public function getCommand(): string

Return expressions (including local callbacks): 'routes'.

Implementation, validation guards and interaction order
public function getCommand(): string
    {
        return 'routes';
    }

getHelp

Source line 24

public function getHelp(): string

Return expressions (including local callbacks): "Displays all registered routes".

Implementation, validation guards and interaction order
public function getHelp(): string
    {
        return "Displays all registered routes";
    }

getArguments

Source line 29

public function getArguments(): array

Return expressions (including local callbacks): ["No arguments"].

Implementation, validation guards and interaction order
public function getArguments(): array
    {
        return ["No arguments"];
    }

execute

Source line 34

public function execute(string $command, array $args = []): void

Parameters

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']
                );
            }
        }
    }

result

Source line 85

public function result(): string

Return expressions (including local callbacks): $this->lastResult.

Implementation, validation guards and interaction order
/**
     * @inheritDoc
     */
    public function result(): string
    {
        return $this->lastResult;
    }

Related types

Clone this wiki locally