Repository navigation
Internals Runtime RuntimeExecutor
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/runtime/RuntimeExecutor.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.
use cli\CLIHandler;
use context\Context;
use context\events\RespondContextEvent;
use object\ObjectHandler;
use runtime\enums\ERuntimeFlags;
use runtime\interface\api\IRuntimeAPI;
use runtime\interface\IRuntime;
use runtime\interface\IRuntimeExecutor;
use vfs\resource\event\ContextSwitchEvent;final class RuntimeExecutor implements IRuntimeExecutorSource description (behavioral corrections are recorded in Known discrepancies):
Runs package APIs through one lifecycle and one request-wide registry.
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 |
|---|---|---|
| $sharedObjects | public array $sharedObjects = []; |
Used by inject(), capture(), executeMain(). |
| $passableInstances | public array $passableInstances = []; |
Used by inject(), executeMain(). |
| $routers | public array $routers = []; |
Used by executeMain(). |
| $CLIHandler | public ?CLIHandler $CLIHandler = null; |
Used by inject(). |
| $eventDispatcher | public ?\event\EventDispatcher $eventDispatcher = null; |
Used by activateContext(), inject(), waitForDependencies(), capture(), executeMain(). |
| $runtime | private IRuntime $runtime; |
Used by setRuntime(), initRuntime(), setupEnvironment(), setup(), execute(). |
| $api | private IRuntimeAPI $api; |
Used by initRuntime(), setupEnvironment(), setup(), execute(). |
| $linkStack | private array $linkStack = []; |
Used by executeMain(). |
| $dependencyRunner | private ?\Closure $dependencyRunner = null; |
Used by setDependencyRunner(), waitForDependencies(). |
| Constructor-promoted | public function __construct(private readonly \runtime\interface\IRuntimeFlagHandler $flagHandler = new RuntimeFlagHandler()) |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Method | Signature |
|---|---|
| __construct | public function __construct(private readonly \runtime\interface\IRuntimeFlagHandler $flagHandler = new RuntimeFlagHandler()) |
| setDependencyRunner | public function setDependencyRunner(callable $runner): void |
| setRuntime | public function setRuntime(IRuntime $runtime): void |
| initRuntime | public function initRuntime(): void |
| setupEnvironment | public function setupEnvironment(): void |
| setup | public function setup(): void |
| execute | public function execute(): void |
| run | public function run(IRuntime $runtime): void |
| loadAPI | private function loadAPI(string $file): IRuntimeAPI |
| activateContext | private function activateContext(IRuntime $runtime): void |
| initialize | private function initialize(IRuntimeAPI $api, IRuntime $runtime): void |
| inject | private function inject(IRuntimeAPI $api, IRuntime $runtime): void |
| waitForDependencies | private function waitForDependencies(IRuntimeAPI $api, IRuntime $runtime): void |
| prepareAPI | public function prepareAPI(IRuntimeAPI $api, IRuntime $runtime): void |
| capture | private function capture(IRuntimeAPI $api, IRuntime $runtime): void |
| runComponent | private function runComponent(IRuntimeAPI $api, IRuntime $runtime): void |
| executeAPI | public function executeAPI(IRuntimeAPI $api, IRuntime $runtime): void |
| executeMain | private function executeMain(IRuntimeAPI $api, IRuntime $runtime): void |
public function __construct(private readonly \runtime\interface\IRuntimeFlagHandler $flagHandler = new RuntimeFlagHandler());| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$flagHandler |
private readonly \runtime\interface\IRuntimeFlagHandler $flagHandler = new RuntimeFlagHandler() |
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 setDependencyRunner(callable $runner): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$runner |
callable $runner |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->dependencyRunner.
Implementation, validation guards and interaction order
public function setDependencyRunner(callable $runner): void { $this->dependencyRunner = \Closure::fromCallable($runner); }public function setRuntime(IRuntime $runtime): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$runtime |
IRuntime $runtime |
Runtime state carrying package metadata, flags and request registries. |
State writes: $this->runtime.
Implementation, validation guards and interaction order
public function setRuntime(IRuntime $runtime): void { $this->runtime = $runtime; }public function initRuntime(): voidState writes: $this->api.
Implementation, validation guards and interaction order
public function initRuntime(): void
{
$this->activateContext($this->runtime);
$this->api = $this->loadAPI($this->runtime->getRootPath() . 'main.php');
$this->initialize($this->api, $this->runtime);
}public function setupEnvironment(): voidDelegates to capture(), waitForDependencies().
Implementation, validation guards and interaction order
public function setupEnvironment(): void
{
$this->api->environmentSetup();
$this->capture($this->api, $this->runtime);
$this->waitForDependencies($this->api, $this->runtime);
}public function setup(): voidDelegates to inject(), capture(), waitForDependencies().
Implementation, validation guards and interaction order
public function setup(): void
{
$this->inject($this->api, $this->runtime);
$this->api->setup();
$this->capture($this->api, $this->runtime);
$this->waitForDependencies($this->api, $this->runtime);
}public function execute(): voidDelegates to executeMain().
Implementation, validation guards and interaction order
public function execute(): void { $this->executeMain($this->api, $this->runtime); }public function run(IRuntime $runtime): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$runtime |
IRuntime $runtime |
Runtime state carrying package metadata, flags and request registries. |
Delegates to activateContext(), loadAPI(), runComponent().
Implementation, validation guards and interaction order
public function run(IRuntime $runtime): void
{
// Local variables survive nested dependency executions on this executor.
$this->activateContext($runtime);
$api = $this->loadAPI($runtime->getRootPath() . 'main.php');
$this->runComponent($api, $runtime);
}private function loadAPI(string $file): IRuntimeAPI| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$file |
string $file |
Uploaded file array, file object or path according to the declared contract. |
Return expressions (including local callbacks): $api.
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 loadAPI(string $file): IRuntimeAPI
{
$api = ObjectHandler::createObjectFromFile($file);
if (!$api instanceof IRuntimeAPI) {
throw new \runtime\exceptions\RuntimeException("Runtime file must declare a package RuntimeAPI: {$file}");
}
return $api;
}private function activateContext(IRuntime $runtime): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$runtime |
IRuntime $runtime |
Runtime state carrying package metadata, flags and request registries. |
State writes: $this->eventDispatcher.
Implementation, validation guards and interaction order
private function activateContext(IRuntime $runtime): void
{
$this->eventDispatcher ??= $runtime->getEventDispatcher();
$runtime->setEventDispatcher($this->eventDispatcher);
$dispatcher = $runtime->getEventDispatcher();
$dispatcher->removeListeners('context.get');
$dispatcher->addListener('context.get', new RespondContextEvent(
new Context($runtime->getRootPath(), $runtime->getRuntimeName(), (string) $runtime->getRuntimeId())
));
}private function initialize(IRuntimeAPI $api, IRuntime $runtime): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$api |
IRuntimeAPI $api |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$runtime |
IRuntime $runtime |
Runtime state carrying package metadata, flags and request registries. |
Delegates to activateContext(), inject().
Implementation, validation guards and interaction order
private function initialize(IRuntimeAPI $api, IRuntime $runtime): void
{
$this->activateContext($runtime);
$api->setInfo($runtime);
// Each component owns its flags; they must not leak from its linker.
$runtime->setFlags([]);
$runtime->setWaitFor([]);
$this->inject($api, $runtime);
}private function inject(IRuntimeAPI $api, IRuntime $runtime): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$api |
IRuntimeAPI $api |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$runtime |
IRuntime $runtime |
Runtime state carrying package metadata, flags and request registries. |
Computes or delegates the operation shown below; no explicit receiver property assignment or throw occurs in this method.
Implementation, validation guards and interaction order
private function inject(IRuntimeAPI $api, IRuntime $runtime): void
{
if ($this->eventDispatcher !== null) $runtime->setEventDispatcher($this->eventDispatcher);
$runtime->setSharedRegistry($this->sharedObjects);
$runtime->setPassable($this->passableInstances);
if (property_exists($api, 'eventDispatcher')) {
$api->eventDispatcher = $runtime->getEventDispatcher();
}
if ($this->CLIHandler !== null && property_exists($api, 'CLIHandler')) {
$api->CLIHandler = $this->CLIHandler;
}
}private function waitForDependencies(IRuntimeAPI $api, IRuntime $runtime): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$api |
IRuntimeAPI $api |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$runtime |
IRuntime $runtime |
Runtime state carrying package metadata, flags and request registries. |
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 waitForDependencies(IRuntimeAPI $api, IRuntime $runtime): void
{
$waits = $runtime->getWaitFor();
foreach (array_unique($waits) as $name) {
if ($this->dependencyRunner === null) {
throw new \runtime\exceptions\RuntimeException("No dependency scheduler available for {$name}.");
}
($this->dependencyRunner)($name);
}
// A dependency may have changed the context and request registries.
if ($this->eventDispatcher !== null) $runtime->setEventDispatcher($this->eventDispatcher);
$dispatcher = $runtime->getEventDispatcher();
$dispatcher->removeListeners('context.get');
$dispatcher->addListener('context.get', new RespondContextEvent(
new Context($runtime->getRootPath(), $runtime->getRuntimeName(), (string) $runtime->getRuntimeId())
));
$this->inject($api, $runtime);
}public function prepareAPI(IRuntimeAPI $api, IRuntime $runtime): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$api |
IRuntimeAPI $api |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$runtime |
IRuntime $runtime |
Runtime state carrying package metadata, flags and request registries. |
Delegates to initialize(), capture(), waitForDependencies().
Implementation, validation guards and interaction order
public function prepareAPI(IRuntimeAPI $api, IRuntime $runtime): void
{
$this->initialize($api, $runtime);
$api->environmentSetup();
$this->capture($api, $runtime);
$this->waitForDependencies($api, $runtime);
$api->setup();
$this->capture($api, $runtime);
$this->waitForDependencies($api, $runtime);
}private function capture(IRuntimeAPI $api, IRuntime $runtime): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$api |
IRuntimeAPI $api |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$runtime |
IRuntime $runtime |
Runtime state carrying package metadata, flags and request registries. |
State writes: $this->sharedObjects, $this->eventDispatcher.
Implementation, validation guards and interaction order
private function capture(IRuntimeAPI $api, IRuntime $runtime): void
{
$runtime->setFlags($this->flagHandler->normalize($runtime->getFlags()));
$this->sharedObjects = $runtime->getSharedRegistry();
if (isset($api->eventDispatcher)) {
$this->eventDispatcher = $api->eventDispatcher;
$runtime->setEventDispatcher($this->eventDispatcher);
}
}private function runComponent(IRuntimeAPI $api, IRuntime $runtime): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$api |
IRuntimeAPI $api |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$runtime |
IRuntime $runtime |
Runtime state carrying package metadata, flags and request registries. |
Delegates to prepareAPI(), executeAPI().
Implementation, validation guards and interaction order
private function runComponent(IRuntimeAPI $api, IRuntime $runtime): void
{
$this->prepareAPI($api, $runtime);
$this->executeAPI($api, $runtime);
}public function executeAPI(IRuntimeAPI $api, IRuntime $runtime): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$api |
IRuntimeAPI $api |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$runtime |
IRuntime $runtime |
Runtime state carrying package metadata, flags and request registries. |
Delegates to executeMain().
Implementation, validation guards and interaction order
public function executeAPI(IRuntimeAPI $api, IRuntime $runtime): void
{
$this->executeMain($api, $runtime);
}private function executeMain(IRuntimeAPI $api, IRuntime $runtime): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$api |
IRuntimeAPI $api |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$runtime |
IRuntime $runtime |
Runtime state carrying package metadata, flags and request registries. |
State writes: $this->sharedObjects, $this->eventDispatcher, $this->passableInstances[$runtime->getRuntimeName()][get_class($api)], $this->routers[], $this->linkStack[$path].
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 executeMain(IRuntimeAPI $api, IRuntime $runtime): void
{
$this->activateContext($runtime);
$this->inject($api, $runtime);
$switch = new ContextSwitchEvent();
$switch->contextName = $runtime->getRuntimeName();
$dispatcher = $runtime->getEventDispatcher();
$dispatcher->removeListeners('vfs.context.request');
$dispatcher->addListener('vfs.context.request', $switch);
$api->main();
$flags = $this->flagHandler->normalize($runtime->getFlags());
$this->sharedObjects = $runtime->getSharedRegistry();
if (isset($api->eventDispatcher)) {
$this->eventDispatcher = $api->eventDispatcher;
$runtime->setEventDispatcher($this->eventDispatcher);
$dispatcher = $this->eventDispatcher;
}
if (in_array(ERuntimeFlags::CreatePassable, $flags, true)) {
$this->passableInstances[$runtime->getRuntimeName()][get_class($api)] = $api;
}
if (in_array(ERuntimeFlags::Router, $flags, true)) {
if (!method_exists($api, 'getRouters')) {
throw new \runtime\exceptions\RuntimeException('Router runtimes must provide getRouters().');
}
$this->routers[] = $api;
}
if (in_array(ERuntimeFlags::RuntimeLinker, $flags, true)) {
if (!$api instanceof \runtime\interface\api\IRuntimeLinkerCapabilities) {
throw new \runtime\exceptions\RuntimeException('Linker runtimes must implement IRuntimeLinkerCapabilities.');
}
foreach ($api->getLinks() as $file) {
$path = realpath($file);
if ($path === false || !str_starts_with($path, realpath($runtime->getRootPath()) . DIRECTORY_SEPARATOR)) {
throw new \runtime\exceptions\RuntimeException("Linked runtime must be inside its package: {$file}");
}
if (isset($this->linkStack[$path])) {
throw new \runtime\exceptions\RuntimeException("Circular runtime link: {$file}");
}
$this->linkStack[$path] = true;
try {
// A separate state prevents child flags/waits from overwriting its parent.
$child = Runtime::create($runtime->getPackage());
$child->rootPath = $runtime->getRootPath();
$child->setEventDispatcher($dispatcher);
$this->runComponent($this->loadAPI($path), $child);
} finally {
unset($this->linkStack[$path]);
$this->activateContext($runtime);
$this->inject($api, $runtime);
}
}
}
}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