"business", self::ENTERTAINMENT => "entertainment", self::GENERAL => "general", self::HEALTH => "health", self::SCIENCE => "science", self::SPORTS => "sports", self::TECHNOLOGY => "technology", self::SOCIAL => "social" ]; public function __construct(int $category) { $this->category = $category; } /** * Get the category as an int corresponding to one of the constants. * @return int */ public function get(): int { return $this->category; } /** * Get a string representation of the category. * @return string */ public function toString(): string { switch ($this->category) { case self::BUSINESS: return "business"; case self::ENTERTAINMENT: return "entertainment"; case self::GENERAL: return "general"; case self::HEALTH: return "health"; case self::SCIENCE: return "science"; case self::SPORTS: return "sports"; case self::TECHNOLOGY: return "technology"; case self::SOCIAL: return "social"; default: return ""; } } public static function fromString(string $category): NewsCategory { $cat = self::NONE_ALL; switch (strtolower($category)) { case "business": $cat = self::BUSINESS; break; case "entertainment": $cat = self::ENTERTAINMENT; break; case "general": $cat = self::GENERAL; break; case "health": $cat = self::HEALTH; break; case "science": $cat = self::SCIENCE; break; case "sports": $cat = self::SPORTS; break; case "technology": case "tech": $cat = self::TECHNOLOGY; break; case "social": $cat = self::SOCIAL; break; } return new NewsCategory($cat); } /** * Get a suitable FontAwesome 5 icon for the category. * @return string CSS classes, such as "fas fa-icon". */ public function getIcon(): string { switch ($this->category) { case self::BUSINESS: return "fas fa-briefcase"; case self::ENTERTAINMENT: return "fas fa-tv"; case self::GENERAL: return "fas fa-info-circle"; case self::HEALTH: return "fas fa-heartbeat"; case self::SCIENCE: return "fas fa-atom"; case self::SPORTS: return "fas fa-futbol"; case self::TECHNOLOGY: return "fas fa-laptop"; case self::SOCIAL: return "fas fa-share-alt"; default: return "fas fa-newspaper"; } } }