value => $id, SearchTable::QUERY->value => $query, SearchTable::TYPE->value => $type->name, SearchTable::TITLE->value => $title, SearchTable::TEXT->value => null, SearchTable::HREF->value => null ])) { throw new Exception("Failed to create Search entity"); } return new Search($id); } final public static function query(string $query, ?int $limit = null): array { return array_map(fn(array $search): Search => new Search($search[SearchTable::ID->value]), new Database() ->from(SearchTable::TABLE) ->where([SearchTable::QUERY->value => [ Operators::LIKE->value => "%{$query}%" ]]) ->limit($limit) ->select(SearchTable::ID->value) ->fetch_all(MYSQLI_ASSOC) ); } public function __construct(public readonly string $id) { parent::__construct(SearchTable::TABLE, SearchTable::values(), [ SearchTable::ID->value => $this->id ]); } final public string $title { get => $this->get(SearchTable::TITLE->value); set (string $title) => $this->set(SearchTable::TITLE->value, $title); } final public ?string $text { get => $this->get(SearchTable::TEXT->value); set (?string $text) => $this->set(SearchTable::TEXT->value, $text); } final public SearchTypeEnum $type { get => SearchTypeEnum::fromName($this->get(SearchTable::TYPE->value)); set (SearchTypeEnum $type) => $this->set(SearchTable::TYPE->value, $type->name); } final public string $href { get => $this->get(SearchTable::HREF->value); set (string $href) => $this->set(SearchTable::HREF->value, $href); } }