mirror of
https://github.com/openvk/openvk
synced 2024-12-24 01:21:07 +03:00
8265dc0fc6
* Логи * Update DBEntity.updated.php * Сбор IP и UserAgent + фикс логирования в IPs * Fixes * Совместимость с новыми логами * Update Logs.xml * Logs i18n * Update Logs.xml * Update AdminPresenter.php
34 lines
798 B
PHP
34 lines
798 B
PHP
<?php declare(strict_types=1);
|
|
namespace openvk\Web\Models\Repositories;
|
|
use Chandler\Database\DatabaseConnection;
|
|
use openvk\Web\Models\Entities\IP;
|
|
|
|
class IPs
|
|
{
|
|
private $context;
|
|
private $ips;
|
|
|
|
function __construct()
|
|
{
|
|
$this->context = DatabaseConnection::i()->getContext();
|
|
$this->ips = $this->context->table("ip");
|
|
}
|
|
|
|
function get(string $ip): ?IP
|
|
{
|
|
$bip = inet_pton($ip);
|
|
if(!$bip)
|
|
throw new \UnexpectedValueException("Malformed IP address");
|
|
|
|
$res = $this->ips->where("ip", $bip)->fetch();
|
|
if(!$res) {
|
|
$res = new IP;
|
|
$res->setIp($ip);
|
|
$res->save(false);
|
|
|
|
return $res;
|
|
}
|
|
|
|
return new IP($res);
|
|
}
|
|
}
|