mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
more type hints
This commit is contained in:
parent
b3fbc1be3c
commit
807c8c9a26
7 changed files with 23 additions and 21 deletions
|
|
@ -10,11 +10,11 @@ class DemoStore {
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $root;
|
private $root;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $webroot;
|
private $webRoot;
|
||||||
|
|
||||||
public function __construct(string $root, string $webroot) {
|
public function __construct(string $root, string $webRoot) {
|
||||||
$this->root = $root;
|
$this->root = $root;
|
||||||
$this->webroot = $webroot;
|
$this->webRoot = $webRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(string $sourcePath, string $name): StoredDemo {
|
public function store(string $sourcePath, string $name): StoredDemo {
|
||||||
|
|
@ -32,11 +32,11 @@ class DemoStore {
|
||||||
return $this->root . $this->getPrefix($name) . $name;
|
return $this->root . $this->getPrefix($name) . $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPrefix(string $name) {
|
private function getPrefix(string $name): string {
|
||||||
return '/' . substr($name, 0, 2) . '/' . substr($name, 2, 2) . '/';
|
return '/' . substr($name, 0, 2) . '/' . substr($name, 2, 2) . '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getUrl(string $name): string {
|
private function getUrl(string $name): string {
|
||||||
return 'https://' . $this->webroot . $this->getPrefix($name) . $name;
|
return 'https://' . $this->webRoot . $this->getPrefix($name) . $name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ class Parser {
|
||||||
*
|
*
|
||||||
* @return string The converted 64bit numeric SteamID
|
* @return string The converted 64bit numeric SteamID
|
||||||
*/
|
*/
|
||||||
public function convertSteamIdToCommunityId($steamId) {
|
public function convertSteamIdToCommunityId(string $steamId): string {
|
||||||
if ($steamId === 'STEAM_ID_LAN' || $steamId === 'BOT') {
|
if ($steamId === 'STEAM_ID_LAN' || $steamId === 'BOT') {
|
||||||
throw new \InvalidArgumentException("Cannot convert SteamID \"$steamId\" to a community ID.");
|
throw new \InvalidArgumentException("Cannot convert SteamID \"$steamId\" to a community ID.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,11 @@ class AuthProvider extends BaseProvider {
|
||||||
$this->generator = $generator;
|
$this->generator = $generator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateToken() {
|
public function generateToken(): string {
|
||||||
return $this->generator->generateString(32, Generator::CHAR_ALNUM);
|
return $this->generator->generateString(32, Generator::CHAR_ALNUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUser($token, \SteamId $steamid, $key) {
|
public function setUser(string $token, \SteamId $steamid, string $key) {
|
||||||
apcu_store($token, [
|
apcu_store($token, [
|
||||||
'name' => $steamid->getNickname(),
|
'name' => $steamid->getNickname(),
|
||||||
'steamid' => $steamid->getSteamId64(),
|
'steamid' => $steamid->getSteamId64(),
|
||||||
|
|
@ -30,7 +30,7 @@ class AuthProvider extends BaseProvider {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUser($token) {
|
public function getUser(string $token) {
|
||||||
$found = true;
|
$found = true;
|
||||||
$result = apcu_fetch($token, $found);
|
$result = apcu_fetch($token, $found);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ class BaseProvider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function query($sql, array $params = []) {
|
protected function query(string $sql, array $params = []) {
|
||||||
$delimiter = $this->db->getIdentifierDelimiter();
|
$delimiter = $this->db->getIdentifierDelimiter();
|
||||||
$platform = $this->connection->getDatabasePlatform();
|
$platform = $this->connection->getDatabasePlatform();
|
||||||
$sql = str_replace('`', $delimiter, $sql);
|
$sql = str_replace('`', $delimiter, $sql);
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ use Demostf\API\Demo\Demo;
|
||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
|
|
||||||
class DemoListProvider extends BaseProvider {
|
class DemoListProvider extends BaseProvider {
|
||||||
public function listUploads(string $steamid, int $page, array $where = []) {
|
public function listUploads(string $steamId, int $page, array $where = []) {
|
||||||
$user = $this->db->user()->where('steamid', $steamid);
|
$user = $this->db->user()->where('steamid', $steamId);
|
||||||
$where['uploader'] = $user->fetch()->id;
|
$where['uploader'] = $user->fetch()->id;
|
||||||
|
|
||||||
return $this->listDemos($page, $where);
|
return $this->listDemos($page, $where);
|
||||||
|
|
@ -47,7 +47,7 @@ class DemoListProvider extends BaseProvider {
|
||||||
*
|
*
|
||||||
* @return Demo[]
|
* @return Demo[]
|
||||||
*/
|
*/
|
||||||
public function listDemos(int $page, array $where = [], $order = 'DESC') {
|
public function listDemos(int $page, array $where = [], string $order = 'DESC') {
|
||||||
if (isset($where['players']) and is_array($where['players']) and count($where['players']) > 0) {
|
if (isset($where['players']) and is_array($where['players']) and count($where['players']) > 0) {
|
||||||
return $this->listProfile($page, $where);
|
return $this->listProfile($page, $where);
|
||||||
}
|
}
|
||||||
|
|
@ -63,10 +63,12 @@ class DemoListProvider extends BaseProvider {
|
||||||
$query->where($query->expr()->eq('map', $query->createNamedParameter($where['map'])));
|
$query->where($query->expr()->eq('map', $query->createNamedParameter($where['map'])));
|
||||||
}
|
}
|
||||||
if (isset($where['playerCount'])) {
|
if (isset($where['playerCount'])) {
|
||||||
$query->where($query->expr()->in('"playerCount"', $query->createNamedParameter($where['playerCount'], Connection::PARAM_INT_ARRAY)));
|
$query->where($query->expr()->in('"playerCount"',
|
||||||
|
$query->createNamedParameter($where['playerCount'], Connection::PARAM_INT_ARRAY)));
|
||||||
}
|
}
|
||||||
if (isset($where['uploader'])) {
|
if (isset($where['uploader'])) {
|
||||||
$query->where($query->expr()->in('uploader', $query->createNamedParameter($where['uploader'], \PDO::PARAM_INT)));
|
$query->where($query->expr()->in('uploader',
|
||||||
|
$query->createNamedParameter($where['uploader'], \PDO::PARAM_INT)));
|
||||||
}
|
}
|
||||||
$query->orderBy('d.id', $order)
|
$query->orderBy('d.id', $order)
|
||||||
->setMaxResults(50)
|
->setMaxResults(50)
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class DemoProvider extends BaseProvider {
|
||||||
return $formattedDemo;
|
return $formattedDemo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function demoIdByHash($hash): int {
|
public function demoIdByHash(string $hash): int {
|
||||||
$query = $this->getQueryBuilder();
|
$query = $this->getQueryBuilder();
|
||||||
$query->select('id')
|
$query->select('id')
|
||||||
->from('demos')
|
->from('demos')
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ class UserProvider extends BaseProvider {
|
||||||
return array_values($result);
|
return array_values($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function byKey($key): ?User {
|
public function byKey(string $key): ?User {
|
||||||
$query = $this->getQueryBuilder();
|
$query = $this->getQueryBuilder();
|
||||||
$query->select(['id', 'steamid', 'name', 'avatar', 'token'])
|
$query->select(['id', 'steamid', 'name', 'avatar', 'token'])
|
||||||
->from('users')
|
->from('users')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue