$values */ private function __construct(private readonly array $values) {} /** * @param array $defaults keyed by file: world, economy, buildings * @param array $overrides the same shape, e.g. ['world' => ['speed' => 100]] */ public static function make(array $defaults, array $overrides = []): self { return new self(array_replace_recursive($defaults, $overrides)); } public function get(string $key, mixed $default = null): mixed { return Arr::get($this->values, $key, $default); } public function speed(): float { return (float) $this->get('world.speed', 1.0); } /** @return list */ public function buildingTypes(): array { return array_keys($this->get('buildings', [])); } public function hasBuilding(string $type): bool { return array_key_exists($type, $this->get('buildings', [])); } /** @return array */ public function building(string $type): array { return $this->get("buildings.$type") ?? throw new \InvalidArgumentException("Unknown building type [$type]."); } /** @return array */ public function toArray(): array { return $this->values; } }