2
0
Fork 0
forked from flashii/eeprom
eeprom-nabucco/src/Application.php

63 lines
1.6 KiB
PHP

<?php
namespace EEPROM;
use RuntimeException;
use Index\Data\IDbConnection;
final class Application {
public function __construct(
private int $id = 0,
private string $name = '',
private int $created = 0,
private int $sizeLimit = -1,
private bool $allowSizeMultiplier = false,
private int $expiry = -1,
) {}
public function getId(): int {
return $this->id;
}
public function getName(): string {
return $this->name;
}
public function getCreated(): int {
return $this->created;
}
public function getSizeLimit(): int {
return $this->sizeLimit;
}
public function allowSizeMultiplier(): bool {
return $this->allowSizeMultiplier;
}
public function getExpiry(): int {
return $this->expiry;
}
public static function byId(IDbConnection $conn, int $appId): self {
$get = $conn->prepare(
'SELECT `app_id`, `app_name`, `app_size_limit`, `app_expiry`, `app_allow_size_multiplier`,'
. ' UNIX_TIMESTAMP(`app_created`) AS `app_created` FROM `prm_applications` WHERE `app_id` = ?'
);
$get->addParameter(1, $appId);
$get->execute();
$result = $get->getResult();
if(!$result->next())
throw new RuntimeException('Application $appId not found.');
return new static(
$result->getInteger(0),
$result->getString(1),
$result->getInteger(5),
$result->getInteger(2),
$result->getInteger(4) !== 0,
$result->getInteger(3),
);
}
}