is_valid = false; //throw new \Exception('[Module] module.package not exists: ' . $file); // @ToDo Exception return; } $content = file_get_contents($file); if(empty($file)) { $this->is_valid = false; // throw new \Exception('[Module] module.package is empty: ' . $path); // @ToDo Exception return; } $data = json_decode($content, false); if(json_last_error() !== JSON_ERROR_NONE) { $this->is_valid = false; // throw new \Exception('[Module] module.package is broken: ' . $path); // @ToDo Exception return; } if(!empty($data->name)) { $this->name = $data->name; } if(!empty($data->version)) { $this->version = $data->version; } // @ToDo check Enum if(!empty($data->category)) { $this->category = $data->category; } if(!empty($data->icon)) { $this->icon = $data->icon; } if(!empty($data->order)) { $this->order = $data->order; } if(!empty($data->permissions)) { $this->permissions = $data->permissions; } if(!empty($data->description)) { $this->description = $data->description; } if(!empty($data->author)) { $this->author = new ModuleAuthor($data->author); } if(!empty($data->repository)) { $this->repository = $data->repository; } if(!empty($data->depencies)) { $this->depencies = $data->depencies; } $this->is_valid = true; } public function isValid() : bool { return $this->is_valid; } public function getName() : ?string { return $this->name; } public function getVersion() : ?string { return $this->version; } public function getCategory() : ?string { return $this->category; } public function getOrder() : int { return $this->order; } public function getPermissions() : array { if($this->permissions === null) { return []; } return $this->permissions; } public function getIcon(bool $raw = false) : ?string { if($raw) { return $this->icon; } /* When the Icon is an URL or an embedded Image (Base64) */ if(preg_match('/^(http|https|data):/', $this->icon)) { return sprintf('Icon', $this->icon); } // @ToDo check if its an local file if(str_starts_with($this->icon, '/')) { return sprintf('Icon', $this->icon); } return sprintf('', $this->icon); } public function getDescription() : ?string { return $this->description; } public function getAuthor() : ?ModuleAuthor { return $this->author; } public function getRepository() : ?string { return $this->repository; } public function getDepencies() : object { if($this->depencies === null) { return (object) []; } return $this->depencies; } } ?>