This commit is contained in:
2025-10-22 20:08:22 +05:00
commit 736e3bef18
2573 changed files with 120385 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
<?php
namespace App\Modules\IpStack;
use App\Modules\Core\ModulePackage;
use App\Modules\Core\ModulePackageType;
use App\Modules\Makeable;
use App\Modules\ModuleContract;
class IpStackModule implements ModuleContract
{
use Makeable;
/**
* Module is enabled
*/
protected bool $enabled = true;
/**
* Check if is module enabled
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Disable module
*/
public function disable(): void
{
$this->enabled = false;
}
/**
* Enable module
*/
public function enable(): void
{
$this->enabled = true;
}
/**
* Check if module has a filament resource
*/
public function hasFilamentResource(): bool
{
return false;
}
/**
* Get module composer requirements
*/
public function getComposerRequirements(): array
{
return [
new ModulePackage(
type: ModulePackageType::PACKAGE,
name: 'stevebauman/location',
message: 'Required for IP-based geolocation services.',
),
];
}
/**
* Get module composer suggestions
*/
public function getComposerSuggestions(): array
{
return [];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Modules\IpStack\Repositories;
use Stevebauman\Location\Facades\Location;
class IpStackRepository
{
/**
* Get ip stack
*/
public static function isLocalIp(string $ip): bool
{
return ! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
}
/**
* Get country code from ip
*/
public static function getCountryCodeFromIp(?string $ip): string
{
if (is_null($ip)) {
return 'TM';
}
return self::isLocalIp($ip) ? 'TM' : Location::get($ip)->countryCode ?? 'TM';
}
}

View File

@@ -0,0 +1,19 @@
<?php
use App\Modules\IpStack\Repositories\IpStackRepository;
/**
* Check if a client IP is in our Server subnet
*/
function isLocalIp(string $ip = ''): bool
{
return IpStackRepository::isLocalIp($ip);
}
/**
* Get country code from ip
*/
function getCountryCodeFromIp(?string $ip = ''): string
{
return IpStackRepository::getCountryCodeFromIp($ip);
}