You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
46 lines
1.2 KiB
<?php
|
|
|
|
namespace IQBall\Api\Controller;
|
|
|
|
use IQBall\Core\Http\HttpResponse;
|
|
use IQBall\Core\Http\JsonHttpResponse;
|
|
|
|
class APIServerController {
|
|
private string $basePath;
|
|
private \PDO $pdo;
|
|
|
|
/**
|
|
* @param string $basePath
|
|
* @param \PDO $pdo
|
|
*/
|
|
public function __construct(string $basePath, \PDO $pdo) {
|
|
$this->basePath = $basePath;
|
|
$this->pdo = $pdo;
|
|
}
|
|
|
|
private function countLines(string $table): int {
|
|
$stmnt = $this->pdo->prepare("SELECT count(*) FROM $table");
|
|
$stmnt->execute();
|
|
$res = $stmnt->fetch(\PDO::FETCH_BOTH);
|
|
return $res[0];
|
|
}
|
|
|
|
|
|
/**
|
|
* @return HttpResponse some (useless) information about the server
|
|
*/
|
|
public function getServerInfo(): HttpResponse {
|
|
|
|
return new JsonHttpResponse([
|
|
'base_path' => $this->basePath,
|
|
'date' => (int) gettimeofday(true) * 1000,
|
|
'database' => [
|
|
'accounts' => $this->countLines("Account") . " line(s)",
|
|
'tactics' => $this->countLines("Tactic") . " line(s)",
|
|
'teams' => $this->countLines("Team") . " line(s)",
|
|
],
|
|
]);
|
|
}
|
|
|
|
}
|