$type, 'Value' => $value]; return $id; } public static function child(int $parent, string $ident, int $type = 2): int { if (!isset(self::$children[$parent][$ident])) { $id = self::$nextID++; self::$children[$parent][$ident] = $id; self::variable($id, $type === 3 ? '' : 0.0, $type); } return self::$children[$parent][$ident]; } } class IPSModule { public int $InstanceID; public array $testProperties = []; public array $testAttributes = []; public function __construct(int $instanceID) { $this->InstanceID = $instanceID; } public function Create(): void { } public function __call(string $method, array $arguments) { if (preg_match('/^(Register|Read|Write)(Property|Attribute)(Boolean|Integer|Float|String)$/', $method, $parts)) { $storage = $parts[2] === 'Property' ? 'testProperties' : 'testAttributes'; $ident = $arguments[0]; if ($parts[1] === 'Register') { $this->{$storage}[$ident] = $this->{$storage}[$ident] ?? $arguments[1]; return null; } if ($parts[1] === 'Write') { $this->{$storage}[$ident] = $arguments[1]; return null; } if (!array_key_exists($ident, $this->{$storage})) { throw new RuntimeException('Unregistered test property or attribute: ' . $ident); } return $this->{$storage}[$ident]; } if (preg_match('/^RegisterVariable(Boolean|Integer|Float|String)$/', $method, $parts)) { $types = ['Boolean' => 0, 'Integer' => 1, 'Float' => 2, 'String' => 3]; return ManagerSDLRuntime::child($this->InstanceID, $arguments[0], $types[$parts[1]]); } throw new BadMethodCallException('Unsupported Symcon test call: ' . $method); } public function EnableAction(string $ident): void { } public function RegisterTimer(string $ident, int $interval, string $script): void { } public function GetIDForIdent(string $ident): int { if (!isset(ManagerSDLRuntime::$children[$this->InstanceID][$ident])) { throw new RuntimeException('Unknown test child: ' . $ident); } return ManagerSDLRuntime::$children[$this->InstanceID][$ident]; } public function SetValue(string $ident, $value): void { ManagerSDLRuntime::$variables[$this->GetIDForIdent($ident)]['Value'] = $value; } public function GetValue(string $ident) { return GetValue($this->GetIDForIdent($ident)); } } function IPS_VariableExists(int $variableID): bool { return isset(ManagerSDLRuntime::$variables[$variableID]); } function IPS_GetVariable(int $variableID): array { if (!IPS_VariableExists($variableID)) { throw new RuntimeException('Unknown test variable: ' . $variableID); } return ManagerSDLRuntime::$variables[$variableID]; } function GetValue(int $variableID) { return IPS_GetVariable($variableID)['Value']; } function IPS_GetObjectIDByIdent(string $ident, int $parentID) { return ManagerSDLRuntime::$children[$parentID][$ident] ?? false; } function IPS_GetProperty(int $instanceID, string $property) { return ManagerSDLRuntime::$properties[$instanceID][$property]; } function IPS_SetProperty(int $instanceID, string $property, $value): void { ManagerSDLRuntime::$properties[$instanceID][$property] = $value; ManagerSDLRuntime::$writes[] = ['property', $instanceID, $property]; } function IPS_ApplyChanges(int $instanceID): void { ManagerSDLRuntime::$writes[] = ['apply', $instanceID]; } function IPS_GetMediaContent(int $mediaID): string { return ManagerSDLRuntime::$media[$mediaID]; } function IPS_SetMediaContent(int $mediaID, string $content): void { ManagerSDLRuntime::$media[$mediaID] = $content; ManagerSDLRuntime::$writes[] = ['media', $mediaID]; } function IPS_SetHidden(int $objectID, bool $hidden): void { ManagerSDLRuntime::$hidden[$objectID] = $hidden; }