create implicit Curl property for GeoIP ctor

This commit is contained in:
Spine
2025-05-31 04:02:08 +00:00
parent b516c2b906
commit 277fcf7e3a
6 changed files with 14 additions and 14 deletions

View File

@@ -8,7 +8,7 @@ class Error403 extends Error {
public static function error(string $message = ''): never {
$who = static::$requestContext->viewer()->label();
$ipaddr = static::$requestContext->viewer()->ipaddr();
$geoip = new Util\GeoIP(new Util\Curl());
$geoip = new Util\GeoIP();
Util\Irc::sendMessage(
IRC_CHAN_STATUS,
"$who ($ipaddr [{$geoip->countryISO($ipaddr)}]) on {$_SERVER['REQUEST_METHOD']} {$_SERVER['REQUEST_URI']}"

View File

@@ -2,7 +2,8 @@
namespace Gazelle\Manager;
use Gazelle\User as User;
use Gazelle\User as User;
use Gazelle\Util\GeoIP as GeoIP;
/**
* This class handles both the user IP site history as well as
@@ -44,7 +45,7 @@ class IPv4 extends \Gazelle\Base {
);
$affected = self::$db->affected_rows();
$user->setField('IP', $ipv4)
->setField('ipcc', new \Gazelle\Util\GeoIP(new \Gazelle\Util\Curl())->countryISO($ipv4))
->setField('ipcc', new GeoIP()->countryISO($ipv4))
->modify();
self::$cache->delete_value(sprintf('ipv4_dup_' . str_replace('-', '_', $ipv4)));
$this->flush();

View File

@@ -118,8 +118,7 @@ class UserCreator extends Base {
? UserStatus::enabled->value
: UserStatus::unconfirmed->value,
STARTING_INVITES,
new \Gazelle\Util\GeoIP(new \Gazelle\Util\Curl())
->countryISO($ipaddr),
new Util\GeoIP()->countryISO($ipaddr),
authKey()
];

View File

@@ -5,7 +5,9 @@ declare(strict_types=1);
namespace Gazelle\Util;
class GeoIP {
public function __construct(protected Curl $curl) {
public function __construct(
protected Curl $curl = new Curl(),
) {
// server is running on the local network
if (defined('HTTP_PROXY')) {
$this->curl->setUseProxy(false);

View File

@@ -1,11 +1,13 @@
#! /usr/bin/env php
<?php
namespace Gazelle;
require_once(__DIR__ . '/../lib/bootstrap.php');
$db = Gazelle\DB::DB();
$geoip = new Gazelle\Util\GeoIP(new Gazelle\Util\Curl());
$userMan = new Gazelle\Manager\User();
$db = DB::DB();
$geoip = new Util\GeoIP();
$userMan = new Manager\User();
$db->prepared_query("
SELECT ID FROM users_main

View File

@@ -16,8 +16,4 @@ if (isset($_SERVER['http_if_modified_since'])) {
header('Expires: ' . date('D, d-M-Y H:i:s \U\T\C', time() + 3600 * 24 * 120)); //120 days
header('Last-Modified: ' . date('D, d-M-Y H:i:s \U\T\C', time()));
die(
new \Gazelle\Util\GeoIP(new \Gazelle\Util\Curl())
->countryISO($_GET['ip'])
);
echo new Util\GeoIP()->countryISO($_GET['ip']);