Skip to content

Internals Runtime Api RuntimeAPI

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

runtime\api\RuntimeAPI

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/runtime/api/RuntimeAPI.php · Snapshot 8411f4287706.

Runtime state, package API classes, loader, executor and orchestrator have separate responsibilities. Dependency validation precedes package code and nested execution restores context.

Imports and dependencies

use cli\CLIHandler;
use cli\interfaces\CLICommand;
use event\EventDispatcher;
use object\ObjectHandler;
use package\model\InstalledPackage;
use runtime\enums\ERuntimeFlags;
use runtime\interface\api\IRuntimeAPI;
use runtime\interface\api\IRuntimeBaseCapabilities;
use runtime\interface\IRuntime;

RuntimeAPI

Declaration and architectural role

abstract class RuntimeAPI implements IRuntimeAPI, IRuntimeBaseCapabilities

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
$id protected int $id; Used by setInfo(), getId().
$name protected string $name; Used by setInfo(), setShared(), getPassable(), getName().
$rootPath protected string $rootPath; Used by setInfo(), getLocalObject().
$runtimePath protected string $runtimePath; Used by setInfo().
$package protected InstalledPackage $package; Used by setInfo(), getPackage(), getInfo().
$runtime protected IRuntime $runtime; Used by setInfo(), getRuntime(), setRuntimeFlag(), waitForPackage(), setShared(), getShared(), hasFlags(), setSharable(), getPassable().
$eventDispatcher public EventDispatcher $eventDispatcher; Used by setInfo().
$CLIHandler public CLIHandler $CLIHandler; Used by addCommand().

Method index

Method Signature
setInfo public function setInfo(IRuntime $runtime): void
getRuntime public function getRuntime(): IRuntime
environmentSetup public function environmentSetup(): void
setup public function setup(): void
main abstract public function main(): void
setRuntimeFlag public function setRuntimeFlag(ERuntimeFlags $flag): void
waitForPackage public function waitForPackage(string $package): void
waitForRuntime public function waitForRuntime(string $package): void
setShared public function setShared(string $name, mixed $share): void
getShared public function getShared(string $name, string $shared, ?string $expectedType = null): mixed
hasFlags public function hasFlags(bool $hasFlags = false): bool
addShared public function addShared(string $name, object $instance): void
setSharable public function setSharable(array $shared): void
getPassable public function getPassable(string $runtimeName, ?string $className = null, ?string $type = null): ?object
getPackage public function getPackage(): InstalledPackage
getId public function getId(): int
getName public function getName(): string
getInfo public function getInfo(): array
getLocalObject public function getLocalObject(string $pathFromRoot): ?object
addCommand public function addCommand(CLICommand $command): void

setInfo

Source line 25

public function setInfo(IRuntime $runtime): void

Parameters

Parameter Type, modifiers and default Purpose
$runtime IRuntime $runtime Runtime state carrying package metadata, flags and request registries.

State writes: $this->runtime, $this->package, $this->id, $this->name, $this->rootPath, $this->runtimePath, $this->eventDispatcher.

Implementation, validation guards and interaction order
public function setInfo(IRuntime $runtime): void
    {
        $this->runtime = $runtime;
        $this->package = $runtime->getPackage();
        $this->id = $runtime->getRuntimeId();
        $this->name = $runtime->getRuntimeName();
        $this->rootPath = rtrim($runtime->getRootPath(), DIRECTORY_SEPARATOR);
        $this->runtimePath = $this->rootPath;
        $this->eventDispatcher = $runtime->getEventDispatcher();
    }

getRuntime

Source line 35

public function getRuntime(): IRuntime

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

Implementation, validation guards and interaction order
public function getRuntime(): IRuntime { return $this->runtime; }

environmentSetup

Source line 36

public function environmentSetup(): void;

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

setup

Source line 37

public function setup(): void;

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

main

Source line 38

abstract public function main(): void;

Contract only: implementations supply the behavior. Parameter and return types are enforced by PHP; caller and implementation constraints follow the subsystem overview.

setRuntimeFlag

Source line 39

public function setRuntimeFlag(ERuntimeFlags $flag): void

Parameters

Parameter Type, modifiers and default Purpose
$flag ERuntimeFlags $flag Native ERuntimeFlags case; normalized/deduplicated before execution.

Computes or delegates the operation shown below; no explicit receiver property assignment or throw occurs in this method.

Implementation, validation guards and interaction order
public function setRuntimeFlag(ERuntimeFlags $flag): void { $this->runtime->setFlags([...$this->runtime->getFlags(), $flag]); }

waitForPackage

Source line 40

public function waitForPackage(string $package): void

Parameters

Parameter Type, modifiers and default Purpose
$package string $package Package identifier or InstalledPackage metadata as indicated by the declared type.

Computes or delegates the operation shown below; no explicit receiver property assignment or throw occurs in this method.

Implementation, validation guards and interaction order
public function waitForPackage(string $package): void { $this->runtime->setWaitFor([...$this->runtime->getWaitFor(), $package]); }

waitForRuntime

Source line 41

public function waitForRuntime(string $package): void

Parameters

Parameter Type, modifiers and default Purpose
$package string $package Package identifier or InstalledPackage metadata as indicated by the declared type.

Delegates to waitForPackage().

Implementation, validation guards and interaction order
public function waitForRuntime(string $package): void { $this->waitForPackage($package); }

setShared

Source line 42

public function setShared(string $name, mixed $share): void

Parameters

Parameter Type, modifiers and default Purpose
$name string $name Named key/label selected by this API; its exact scope is shown by the implementation trace.
$share mixed $share Operation input; the exact use, validation and propagation are shown in the implementation trace.

Computes or delegates the operation shown below; no explicit receiver property assignment or throw occurs in this method.

Implementation, validation guards and interaction order
public function setShared(string $name, mixed $share): void
    {
        $shared = $this->runtime->getSharedRegistry();
        $shared[$this->name][$name] = $share;
        $this->runtime->setSharedRegistry($shared);
    }

getShared

Source line 48

public function getShared(string $name, string $shared, ?string $expectedType = null): mixed

Parameters

Parameter Type, modifiers and default Purpose
$name string $name Named key/label selected by this API; its exact scope is shown by the implementation trace.
$shared string $shared Operation input; the exact use, validation and propagation are shown in the implementation trace.
$expectedType ?string $expectedType = null Operation input; the exact use, validation and propagation are shown in the implementation trace.

Return expressions (including local callbacks): $value.

Explicit exceptions: \runtime\exceptions\RuntimeException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.

Implementation, validation guards and interaction order
public function getShared(string $name, string $shared, ?string $expectedType = null): mixed
    {
        $value = $this->runtime->getSharedRegistry()[$name][$shared] ?? null;
        if ($value !== null && $expectedType !== null && !$value instanceof $expectedType) {
            throw new \runtime\exceptions\RuntimeException('Unexpected shared type ' . get_debug_type($value) . "; expected {$expectedType}.");
        }
        return $value;
    }

hasFlags

Source line 56

public function hasFlags(bool $hasFlags = false): bool

Parameters

Parameter Type, modifiers and default Purpose
$hasFlags bool $hasFlags = false Operation input; the exact use, validation and propagation are shown in the implementation trace.

Return expressions (including local callbacks): $this->runtime->getFlags() !== [].

Implementation, validation guards and interaction order
public function hasFlags(bool $hasFlags = false): bool { return $this->runtime->getFlags() !== []; }

addShared

Source line 57

public function addShared(string $name, object $instance): void

Parameters

Parameter Type, modifiers and default Purpose
$name string $name Named key/label selected by this API; its exact scope is shown by the implementation trace.
$instance object $instance Operation input; the exact use, validation and propagation are shown in the implementation trace.

Delegates to setShared().

Implementation, validation guards and interaction order
public function addShared(string $name, object $instance): void { $this->setShared($name, $instance); }

setSharable

Source line 58

public function setSharable(array $shared): void

Parameters

Parameter Type, modifiers and default Purpose
$shared array $shared Operation input; the exact use, validation and propagation are shown in the implementation trace.

Computes or delegates the operation shown below; no explicit receiver property assignment or throw occurs in this method.

Implementation, validation guards and interaction order
public function setSharable(array $shared): void { $this->runtime->setSharedRegistry($shared); }

getPassable

Source line 61

public function getPassable(string $runtimeName, ?string $className = null, ?string $type = null): ?object

Parameters

Parameter Type, modifiers and default Purpose
$runtimeName string $runtimeName Operation input; the exact use, validation and propagation are shown in the implementation trace.
$className ?string $className = null Operation input; the exact use, validation and propagation are shown in the implementation trace.
$type ?string $type = null Expected class/type or enum selection according to the signature.

One argument looks within this package; two arguments select another package.

Return expressions (including local callbacks): $instance !== null && ($type === null || $instance instanceof $type) ? $instance : null.

Implementation, validation guards and interaction order
/** One argument looks within this package; two arguments select another package. */
    public function getPassable(string $runtimeName, ?string $className = null, ?string $type = null): ?object
    {
        $instance = $className === null
            ? ($this->runtime->getPassable($this->name)[$runtimeName] ?? null)
            : ($this->runtime->getPassable($runtimeName)[$className] ?? null);
        return $instance !== null && ($type === null || $instance instanceof $type) ? $instance : null;
    }

getPackage

Source line 69

public function getPackage(): InstalledPackage

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

Implementation, validation guards and interaction order
public function getPackage(): InstalledPackage { return $this->package; }

getId

Source line 70

public function getId(): int

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

Implementation, validation guards and interaction order
public function getId(): int { return $this->id; }

getName

Source line 71

public function getName(): string

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

Implementation, validation guards and interaction order
public function getName(): string { return $this->name; }

getInfo

Source line 72

public function getInfo(): array

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

Implementation, validation guards and interaction order
public function getInfo(): array { return $this->package->getInfo(); }

getLocalObject

Source line 73

public function getLocalObject(string $pathFromRoot): ?object

Parameters

Parameter Type, modifiers and default Purpose
$pathFromRoot string $pathFromRoot Operation input; the exact use, validation and propagation are shown in the implementation trace.

Return expressions (including local callbacks): ObjectHandler::createObjectFromFile($this->rootPath . '/' . ltrim($pathFromRoot, '/')).

Implementation, validation guards and interaction order
public function getLocalObject(string $pathFromRoot): ?object
    {
        return ObjectHandler::createObjectFromFile($this->rootPath . '/' . ltrim($pathFromRoot, '/'));
    }

addCommand

Source line 77

public function addCommand(CLICommand $command): void

Parameters

Parameter Type, modifiers and default Purpose
$command CLICommand $command Operation input; the exact use, validation and propagation are shown in the implementation trace.

Explicit exceptions: \LogicException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.

Implementation, validation guards and interaction order
public function addCommand(CLICommand $command): void
    {
        if (PHP_SAPI === 'cli') {
            if (!isset($this->CLIHandler)) throw new \LogicException('CLI handler is unavailable.');
            $this->CLIHandler->addCommand($command);
        }
    }

Related types

Clone this wiki locally