ruleset = new Ruleset(strict: true); $this->ruleset->GET([ (new Rules(DramTable::ID->value)) ->type(Type::STRING) ->min(parent::UUID_LENGTH) ->max(parent::UUID_LENGTH), (new Rules(DramTable::CAPACITY->value)) ->type(Type::NUMBER) ->min(1), (new Rules(DramTable::SPEED->value)) ->type(Type::NUMBER) ->min(1), (new Rules(DramTable::FORMFACTOR->value)) ->type(Type::ENUM, DramFormfactorEnum::names()), (new Rules(DramTable::TECHNOLOGY->value)) ->type(Type::ENUM, DramTechnologyEnum::names()), (new Rules(DramTable::ECC->value)) ->type(Type::BOOLEAN), (new Rules(DramTable::BUFFERED->value)) ->type(Type::BOOLEAN), (new Rules(DramTable::VENDOR_NAME->value)) ->type(Type::STRING) ->min(1) ->max(parent::SIZE_VARCHAR), (new Rules(DramTable::VENDOR_MODEL->value)) ->type(Type::STRING) ->min(1) ->max(parent::SIZE_VARCHAR), (new Rules(DramTable::IS_RETIRED->value)) ->type(Type::BOOLEAN) ]); parent::__construct(Databases::BATTLESTATION, $this->ruleset); // Use a copy of search parameters $this->query = $_GET; } private function get_motherboards(): void { foreach ($this->results as &$result) { // Get motherboard id from relationship by chassis id $result[self::REL_MOTHERBOARDS] = $this->db ->for(MbDramTable::NAME) ->where([MbDramTable::REF_DRAM_ID->value => $result[DramTable::ID->value]]) ->select(MbDramTable::values()) ->fetch_all(MYSQLI_ASSOC); } } private function get_dram(): array { return $this->results = $this->db ->for(DramTable::NAME) ->where($this->query) ->order([DramTable::DATE_AQUIRED->value => "DESC"]) ->select(DramTable::values()) ->fetch_all(MYSQLI_ASSOC); } public function main(): Response { // Set properties as "searchable" parent::make_wildcard_search(DramTable::VENDOR_NAME->value, $this->query); parent::make_wildcard_search(DramTable::VENDOR_MODEL->value, $this->query); // Get hardware $this->get_dram(); // Resolve hardware relationships $this->get_motherboards(); // Return 404 Not Found if response array is empty return new Response($this->results, $this->results ? 200 : 404); } }