Skip to content

Internals Cli Commands InstallCommand

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

cli\commands\InstallCommand

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/cli/commands/InstallCommand.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 installer\framework\FrameworkInstallService;

InstallCommand

Declaration and architectural role

class InstallCommand 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
$result private string $result = ''; Used by execute(), result().
$installationArguments private array $installationArguments = []; @var array<string, string>
Constructor-promoted public function __construct(private FrameworkInstallService $installer = new FrameworkInstallService()) Initialized from the constructor argument; default expression is evaluated when the argument is omitted.

Method index

Method Signature
__construct public function __construct(private FrameworkInstallService $installer = new FrameworkInstallService())
getCommand public function getCommand(): string
getHelp public function getHelp(): string
getArguments public function getArguments(): array
execute public function execute(string $command, array $args = []): void
getInstallationArguments public function getInstallationArguments(): array
configAdmin private function configAdmin(): void
installPackage private function installPackage(): void
result public function result(): string

__construct

Source line 15

public function __construct(private FrameworkInstallService $installer = new FrameworkInstallService());

Parameters

Parameter Type, modifiers and default Purpose
$installer private FrameworkInstallService $installer = new FrameworkInstallService() Operation input; the exact use, validation and propagation are shown in the implementation trace.

Concrete no-op/default hook: this method performs no work. Override it where the lifecycle or extension contract calls for behavior.

getCommand

Source line 17

public function getCommand(): string

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

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

getHelp

Source line 22

public function getHelp(): string

Return expressions (including local callbacks): 'Installation of the framework is available only when DB_TYPE is empty. Supply all seven arguments in order.' . PHP_EOL . 'Use "" or two single quotes for an empty argument.

Implementation, validation guards and interaction order
public function getHelp(): string
    {
        return 'Installation of the framework is available only when DB_TYPE is empty. Supply all seven arguments in order.'
            . PHP_EOL . 'Use "" or two single quotes for an empty argument; quote values containing spaces.'
            . PHP_EOL . 'Example: install mysql awt "" root "" "My Website" ""';
    }

getArguments

Source line 29

public function getArguments(): array

Return expressions (including local callbacks): [ "<database_type>" => "Database type. Valid options are mysql, postgresql, sqlite", "<database_name>" => "Database name", "<host>" => "Database host. Leave empty if you want to use the default host which is 'localhost'.", "<username>" => "Database username", "<password>" => "Database password. Can be empty but not suggested for security reasons.", "<website_name>" => "Website name", "<host_path>" => "Host path. Leave empty if you want to use the default path which is '/'." ].

Implementation, validation guards and interaction order
public function getArguments(): array
    {
        return [
            "<database_type>" => "Database type. Valid options are mysql, postgresql, sqlite",
            "<database_name>" => "Database name",
            "<host>" => "Database host. Leave empty if you want to use the default host which is 'localhost'.",
            "<username>" => "Database username",
            "<password>" => "Database password. Can be empty but not suggested for security reasons.",
            "<website_name>" => "Website name",
            "<host_path>" => "Host path. Leave empty if you want to use the default path which is '/'."
        ];
    }

execute

Source line 42

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->result, $this->installationArguments.

Failure handling catches \InvalidArgumentException | \RuntimeException.

Implementation, validation guards and interaction order
public function execute(string $command, array $args = []): void
    {
        $this->result = '';
        $this->installationArguments = [];

        if (count($args) !== count($this->getArguments())) {
            $this->result = 'Invalid number of arguments. Type `help install` for help.';
            return;
        }

        $configuration = array_combine(
            ['database_type', 'database_name', 'host', 'username', 'password', 'website_name', 'host_path'],
            array_values($args)
        );

        try {
            $this->installationArguments = $this->installer->validateConfiguration($configuration);
            $this->installer->install($this->installationArguments);
            $this->configAdmin();
            $this->installPackage();
            $this->result = 'Installation completed.';
        } catch (\InvalidArgumentException | \RuntimeException $exception) {
            $this->result = $exception->getMessage();
        }
    }

getInstallationArguments

Source line 69

public function getInstallationArguments(): array

@return array<string, string> Validated arguments, or an empty array after validation fails.

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

Implementation, validation guards and interaction order
/** @return array<string, string> Validated arguments, or an empty array after validation fails. */
    public function getInstallationArguments(): array
    {
        return $this->installationArguments;
    }

configAdmin

Source line 74

private function configAdmin(): void

External effects include readline.

Implementation, validation guards and interaction order
private function configAdmin(): void
    {
        print("Do you want to create an admin account? Y/n" . PHP_EOL);
        $input = readline();

        if(strtolower($input) === "n") {
            print("Admin account creation skipped" . PHP_EOL);
            return;
        }

        $email = readline("Enter email: ");
        $password = readline("Enter password: ");
        $username = readline("Enter username: ");
        $firstname = readline("Enter firstname: ");
        $lastname = readline("Enter lastname: ");

        $this->installer->createAdmin(compact('email', 'password', 'username', 'firstname', 'lastname'));

        print("Admin account created" . PHP_EOL);
    }

installPackage

Source line 95

private function installPackage(): void

External effects include readline.

Implementation, validation guards and interaction order
private function installPackage(): void
    {
        global $cliHandler;

        print("Do you want to install packages? Y/n" . PHP_EOL);
        $input = readline();

        if(strtolower($input) === "n") {
            print("Package installation skipped");
            return;
        }

        $cliHandler->addCommand(new PackageManagerCommand());

        print("Package manager command registered. After completion of this installation, you can run the package manager command to install packages. Type 'help pm' to list all commands. " . PHP_EOL);
    }

result

Source line 115

public function result(): string

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

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

Related types

Clone this wiki locally