name = $catalog['name']??null; $this->info = $catalog['info']??null; foreach ($catalog['props']??[] as $k=>$v) { $this->properties[$k] = $v; } foreach ($catalog['methods']??[] as $k=>$v) { $this->methods[$k] = new Method($v); } } public static function createFromFile(string $filename): Catalog { $json = file_get_contents($filename); $catalog = json_decode($json, true); $catalog['name'] = basename($filename, ".json"); return new Catalog($catalog); } public function getName(): ?string { return $this->name; } public function getInfo(): ?string { return $this->info; } public function getProperties(): array { return $this->properties; } public function applyProperties(array $props) { $this->properties = array_merge($this->properties, $props); } public function addMethod(string $name, Method $method) { $this->methods[$name] = $method; } public function getMethod(string $method): ?Method { return $this->methods[$method]??null; } public function getMethods(): array { return $this->methods; } public function jsonSerialize(): mixed { return [ 'catalog' => [ 'name' => $this->name, 'info' => $this->info, 'props' => $this->properties, 'methods' => $this->methods, ] ]; } }