Repository navigation
Internals 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.
use cli\interfaces\CLICommand;
use installer\framework\FrameworkInstallService;class InstallCommand 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 |
|---|---|---|
| $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 | 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 |
public function __construct(private FrameworkInstallService $installer = new FrameworkInstallService());| 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.
public function getCommand(): stringReturn expressions (including local callbacks): 'install'.
Implementation, validation guards and interaction order
public function getCommand(): string
{
return 'install';
}public function getHelp(): stringReturn 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" ""';
}public function getArguments(): arrayReturn 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 '/'."
];
}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->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();
}
}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;
}private function configAdmin(): voidExternal 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);
}private function installPackage(): voidExternal 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);
}public function result(): stringReturn expressions (including local callbacks): $this->result.
Implementation, validation guards and interaction order
/**
* @inheritDoc
*/
public function result(): string
{
return $this->result;
}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