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->get($bip); if(!$res) { $res = new IP; $res->setIp($ip); $res->save(); return $res; } return new IP($res); } }