Skip to content

Developer Guide Configuration and CLI

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

Configuration, CLI, sessions and administration

Developer Guide · Installation

Internals: Bootstrap, CLI, Identity, Setting Config, Settings.

Configuration layers

Layer Purpose
awt_data/config/awt_dirMap.php ROOT, source/package/data/storage/cache/temp/public path constants and directory creation.
awt_data/config/awt_config.php AWT_VERSION, DEBUG, PACKAGE_MAX_LOAD_TRY and development/upload settings.
awt_data/config/awt_db.php DB_TYPE/DB_HOSTNAME/DB_NAME/DB_USERNAME/DB_PASSWORD.
awt_setting database records Per-package named settings loaded by Settings and exposed as SettingModel objects.

There is no automatic .env loader. Treat constants as process configuration; changing files does not redefine constants within an already running CLI session. Bootstrap establishes WEB_NAME and HOSTNAME from AWT settings and the request. Package code should use paths/metadata supplied by its runtime and public Config APIs.

Excerpt in an initialized package runtime or service:

$website = \setting\Config::getConfig('AWT', 'Website Name');
$name = $website?->getValue() ?? 'My Website';
$website?->setValue('Example Website');

getConfig() returns a SettingModel or null; setValue() writes the awt_setting row and updates the object. Settings::createSetting(packageId, name, value, permission, valueType, category) creates a unique package/name pair and returns 0 when it already exists. Use the install hook's package ID when creating package settings. fetchSettings()->initSettings() loads and defines object constants; getSettings()/getSetting() inspect them.

Constant names use uppercase SETT_package_setting with spaces replaced by underscores. Config additionally normalizes hyphens while SettingModel's producer does not, so avoid hyphens in setting/package names for these lookups. Values are not automatically converted using value_type; boolean settings currently use strings such as 'true'. required_permission_level and category are metadata; these methods do not enforce caller permissions.

AWT command loop

Either OS, repository root:

php awt

Use help, help install, help pm, version, routes, hello, clear and pm actions. install is registered even after installation but its service rejects configured DB_TYPE. clear clears the terminal, not the cache. php awt <command> [args...] executes the first command and then enters the same loop; EOF or Ctrl+C ends it. Interactive quoting supports single/double quotes and escapes, but does not expand variables or run shell commands. Quote Windows paths with single quotes at the AWT prompt to preserve backslashes.

Register a package command

Complete DemoSite/commands/CountMessages.php:

<?php
namespace DemoSite\commands;

use cli\interfaces\CLICommand;
use database\DatabaseManager;

final class CountMessages implements CLICommand
{
    private string $output = '';
    public function getCommand(): string { return 'demo-count'; }
    public function getHelp(): string { return 'Count demo messages'; }
    public function getArguments(): array { return []; }
    public function execute(string $command, array $args = []): void
    {
        $row = (new DatabaseManager())->table('demo_message')
            ->select(['COUNT(*) AS total'])->first();
        $this->output = (string) ($row['total'] ?? 0);
    }
    public function result(): string { return $this->output; }
}

Excerpt in a RuntimeAPI main(), with the schema example already installed:

$this->addCommand(new \DemoSite\commands\CountMessages());

addCommand() is a no-op outside CLI. In current installed bootstrap the handler injected into runtimes is replaced by a fresh handler in bootstrap/cli/handler.php afterward, so package commands registered this way do not survive to the final prompt. The API exists, but that integration is currently broken. The command class itself can be tested using CLIHandler directly. See discrepancies; do not document a fictitious successful package-command workflow.

Sessions and admin features

(new \session\SessionHandler())->SessionHandler() explicitly starts/manages the configured PHP session. Construction alone does not start it. The security settings control SameSite, Secure and HttpOnly cookies. Session expiry/regeneration behavior is described in Identity internals; some comments promise IP binding/custom session storage that the class does not implement.

AdminAuthentication(username, password)->authenticate() queries awt_admin, starts the configured session and populates $_SESSION['admin'] with id, username, permission and token. AdminModel supports registration, setters, token creation and password change. Admin::checkPermission(level) uses current permission <= level; checkAuthentication() compares the loaded token with the session; logout() removes the admin session entry. Do not interpret these as a complete user/role system or automatic route protection. Guard route actions with middleware/application checks.

Passwords currently use unsalted SHA-512 in the supplied admin implementation, and some methods assume populated session/token state. This is a code limitation recorded in discrepancies, not a recommended password design. The optional CLI admin creation does not install a dashboard UI; the local application package supplies its own dashboard routes.

Remote development package upload is attempted by bootstrap/dev.php when DEBUG/REMOTE_INSTALL_FOR_DEVS are true and the request matches /dev/install with the development secret. Bootstrap also gates including that file on a defined DEV constant, which the supplied config does not define. Keep this off in deployment; use the verified local ZIP workflow for development. There is no implemented task scheduler, queue worker or asynchronous server command in this checkout.

Clone this wiki locally