title = array_key_exists($user_language, $title) ? $title[$user_language] : (array_key_exists($default_language, $title) ? $title[$default_language] : $title[0]); $this->description = array_key_exists($user_language, $description) ? $description[$user_language] : (array_key_exists($default_language, $description) ? $description[$default_language] : $description[0]); $this->type = $type; $this->url = $url; $this->image = $image; $this->image_type = $image_type; } static function from_json(array $json_data): ?OpenGraphData { foreach(["title", "description", "type", "url", "image", "image_type"] as $wantedKey) { if(!key_exists($wantedKey, $json_data)) { return null; } } return new OpenGraphData( $json_data["title"], $json_data["description"], $json_data["type"], $json_data["url"], $json_data["image"], $json_data["image_type"] ); } } ?>