mirror of
https://codeberg.org/vlw/vlw.se.git
synced 2025-09-13 21:13:40 +02:00
57 lines
No EOL
1.5 KiB
PHP
57 lines
No EOL
1.5 KiB
PHP
<?php
|
|
|
|
use Reflect\{Response, Path};
|
|
use ReflectRules\{Ruleset, Rules, Type};
|
|
|
|
use VLW\Database\Database;
|
|
use VLW\Database\Tables\Battlestation\Config\ConfigModel;
|
|
|
|
require_once Path::root("src/Database/Database.php");
|
|
require_once Path::root("src/Database/Models/Battlestation/Config/Config.php");
|
|
|
|
class GET_Battlestation extends Database {
|
|
protected Ruleset $ruleset;
|
|
|
|
private array $query;
|
|
private array $results = [];
|
|
|
|
public function __construct() {
|
|
$this->ruleset = new Ruleset(strict: true);
|
|
|
|
$this->ruleset->GET([
|
|
(new Rules(ConfigModel::REF_MB_ID->value))
|
|
->type(Type::STRING)
|
|
->min(parent::UUID_LENGTH)
|
|
->max(parent::UUID_LENGTH),
|
|
|
|
(new Rules(ConfigModel::FRIENDLY_NAME->value))
|
|
->type(Type::STRING)
|
|
->min(1)
|
|
->max(parent::MYSQL_VARCHAR_MAX_LENGTH)
|
|
]);
|
|
|
|
parent::__construct(Databases::BATTLESTATION, $this->ruleset);
|
|
|
|
// Use a copy of search parameters
|
|
$this->query = $_GET;
|
|
}
|
|
|
|
private function get_config(): array {
|
|
return $this->results = $this->db
|
|
->for(ConfigModel::NAME)
|
|
->where($this->query)
|
|
->order([ConfigModel::DATE_BUILT->value => "DESC"])
|
|
->select(ConfigModel::values())
|
|
->fetch_all(MYSQLI_ASSOC);
|
|
}
|
|
|
|
public function main(): Response {
|
|
// Set properties as "searchable"
|
|
parent::make_wildcard_search(ConfigModel::FRIENDLY_NAME->value, $this->query);
|
|
|
|
$this->get_config();
|
|
|
|
// Return 404 Not Found if response array is empty
|
|
return new Response($this->results, $this->results ? 200 : 404);
|
|
}
|
|
} |