Skip to content

Internals Runtime RuntimeOrchestrator

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

runtime\RuntimeOrchestrator

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/runtime/RuntimeOrchestrator.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 runtime\enums\ERuntimeStatus;
use runtime\interface\IRuntime;
use runtime\interface\IRuntimeExecutor;
use runtime\interface\IRuntimeOrchestrator;

RuntimeOrchestrator

Declaration and architectural role

final class RuntimeOrchestrator implements IRuntimeOrchestrator

Source description (behavioral corrections are recorded in Known discrepancies):

Validates the installed dependency graph before running any package code.

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
$byName private array $byName = []; Used by __construct(), run(), validate(), runPackage().
$stack private array $stack = []; Used by runPackage().
$loaded private array $loaded = []; Used by run(), runPackage().
Constructor-promoted public function __construct(private IRuntimeExecutor $runtimeExecutor Initialized from the constructor argument; default expression is evaluated when the argument is omitted.
Constructor-promoted private array $runtimes Initialized from the constructor argument; default expression is evaluated when the argument is omitted.
Constructor-promoted private array $installed = []) Initialized from the constructor argument; default expression is evaluated when the argument is omitted.

Method index

Method Signature
__construct public function __construct(private IRuntimeExecutor $runtimeExecutor, private array $runtimes, private array $installed = [])
getRuntimes public function getRuntimes(): array
run public function run(): array
validate private function validate(): void
runPackage private function runPackage(string $name): void

__construct

Source line 16

public function __construct(private IRuntimeExecutor $runtimeExecutor, private array $runtimes, private array $installed = [])

Parameters

Parameter Type, modifiers and default Purpose
$runtimeExecutor private IRuntimeExecutor $runtimeExecutor Operation input; the exact use, validation and propagation are shown in the implementation trace.
$runtimes private array $runtimes Operation input; the exact use, validation and propagation are shown in the implementation trace.
$installed private array $installed = [] Operation input; the exact use, validation and propagation are shown in the implementation trace.

State writes: $this->byName[$name], $this->installed.

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 __construct(private IRuntimeExecutor $runtimeExecutor, private array $runtimes, private array $installed = [])
    {
        foreach ($runtimes as $runtime) {
            $name = $runtime->getRuntimeName();
            if (isset($this->byName[$name])) throw new \runtime\exceptions\RuntimeException("Duplicate runtime package: {$name}");
            $this->byName[$name] = $runtime;
        }
        if ($installed === []) {
            $this->installed = array_map(fn($runtime) => $runtime->getPackage(), $runtimes);
        }
        $this->runtimeExecutor->setDependencyRunner($this->runPackage(...));
    }

getRuntimes

Source line 29

public function getRuntimes(): array

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

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

run

Source line 30

public function run(): array

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

Implementation, validation guards and interaction order
public function run(): array
    {
        $this->validate();
        foreach (array_keys($this->byName) as $name) $this->runPackage($name);
        return $this->loaded;
    }

validate

Source line 37

private function validate(): void

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
private function validate(): void
    {
        $installed = [];
        foreach ($this->installed as $package) $installed[$package->getName()] = $package;
        foreach ($this->byName as $name => $runtime) {
            $package = $runtime->getPackage();
            if (!is_file($runtime->getRootPath() . 'main.php')) {
                throw new \runtime\exceptions\RuntimeException("Package {$name} has no main.php entry point.");
            }
            if (defined('AWT_VERSION') && (version_compare(AWT_VERSION, $package->minimum_awt_version, '<')
                || ($package->maximum_awt_version !== null && version_compare(AWT_VERSION, $package->maximum_awt_version, '>')))) {
                throw new \runtime\exceptions\RuntimeException("Package {$name} is incompatible with AWT " . AWT_VERSION);
            }
            foreach ($package->getDependencies() as $dependency) {
                $target = $installed[$dependency['name']] ?? null;
                if ($target === null) throw new \runtime\exceptions\RuntimeException("Package {$name} requires missing package {$dependency['name']}.");
                if (!$target->getStatus()) throw new \runtime\exceptions\RuntimeException("Package {$name} requires disabled package {$dependency['name']}.");
                if (!\package\dependency\Dependency::matchesVersion($target->getVersion(), $dependency['version'])) {
                    throw new \runtime\exceptions\RuntimeException("Package {$name} requires {$dependency['name']} {$dependency['version']}; installed {$target->version}.");
                }
                if ($target->type !== 0 && !isset($this->byName[$target->name])) {
                    throw new \runtime\exceptions\RuntimeException("Dependency {$target->name} has no executable runtime.");
                }
            }
        }
        $visited = [];
        $visiting = [];
        $visit = function (string $name) use (&$visit, &$visited, &$visiting): void {
            if (isset($visiting[$name])) throw new \runtime\exceptions\RuntimeException('Circular manifest dependency: ' . implode(' -> ', array_keys($visiting)) . ' -> ' . $name);
            if (isset($visited[$name])) return;
            $visiting[$name] = true;
            foreach ($this->byName[$name]->getPackage()->getDependencies() as $dep) {
                if (isset($this->byName[$dep['name']])) $visit($dep['name']);
            }
            unset($visiting[$name]);
            $visited[$name] = true;
        };
        foreach (array_keys($this->byName) as $name) $visit($name);
    }

runPackage

Source line 77

private function runPackage(string $name): 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.

State writes: $this->stack[$name], $this->loaded[$name].

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

Failure handling catches \Throwable.

Implementation, validation guards and interaction order
private function runPackage(string $name): void
    {
        if (isset($this->loaded[$name])) return;
        $runtime = $this->byName[$name] ?? throw new \runtime\exceptions\RuntimeException("Cannot wait for missing, disabled, or non-runtime package {$name}.");
        if (isset($this->stack[$name])) throw new \runtime\exceptions\RuntimeException('Circular runtime wait: ' . implode(' -> ', array_keys($this->stack)) . ' -> ' . $name);
        $this->stack[$name] = true;
        $runtime->setRuntimeStatus(ERuntimeStatus::RUNNING);
        try {
            foreach ($runtime->getPackage()->getDependencies() as $dep) {
                if (isset($this->byName[$dep['name']])) $this->runPackage($dep['name']);
            }
            $this->runtimeExecutor->run($runtime);
            $runtime->setRuntimeStatus(ERuntimeStatus::EXECUTED);
            $this->loaded[$name] = $runtime;
        } catch (\Throwable $e) {
            $runtime->setRuntimeStatus(ERuntimeStatus::STOPPED);
            throw $e;
        } finally {
            unset($this->stack[$name]);
        }
    }

Related types

Clone this wiki locally