- Add comprehensive health check system with multiple endpoints - Add Prometheus metrics endpoint - Add production logging configurations (5 strategies) - Add complete deployment documentation suite: * QUICKSTART.md - 30-minute deployment guide * DEPLOYMENT_CHECKLIST.md - Printable verification checklist * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference * production-logging.md - Logging configuration guide * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation * README.md - Navigation hub * DEPLOYMENT_SUMMARY.md - Executive summary - Add deployment scripts and automation - Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment - Update README with production-ready features All production infrastructure is now complete and ready for deployment.
117 lines
2.9 KiB
PHP
117 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Http;
|
|
|
|
/**
|
|
* Value Object für IP-Adressen
|
|
*/
|
|
final readonly class IpAddress
|
|
{
|
|
public function __construct(
|
|
public string $value
|
|
) {
|
|
if (! filter_var($value, FILTER_VALIDATE_IP)) {
|
|
throw new \InvalidArgumentException("Invalid IP address: {$value}");
|
|
}
|
|
}
|
|
|
|
// Factory Methods
|
|
public static function from(string $ip): self
|
|
{
|
|
return new self($ip);
|
|
}
|
|
|
|
public static function fromRequest(ServerEnvironment $server): ?self
|
|
{
|
|
$keys = [
|
|
ServerKey::HTTP_CF_CONNECTING_IP, // Cloudflare
|
|
ServerKey::HTTP_CLIENT_IP, // Proxy
|
|
ServerKey::HTTP_X_FORWARDED_FOR, // Load balancer/proxy
|
|
ServerKey::HTTP_X_FORWARDED, // Proxy
|
|
ServerKey::HTTP_X_CLUSTER_CLIENT_IP, // Cluster
|
|
ServerKey::HTTP_FORWARDED_FOR, // Proxy
|
|
ServerKey::HTTP_FORWARDED, // Proxy
|
|
ServerKey::REMOTE_ADDR, // Standard
|
|
];
|
|
|
|
foreach ($keys as $key) {
|
|
$value = $server->get($key);
|
|
if ($value !== null && $value !== '') {
|
|
$ip = trim(explode(',', $value)[0]);
|
|
if (self::isValid($ip)) {
|
|
return new self($ip);
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static function localhost(): self
|
|
{
|
|
return new self('127.0.0.1');
|
|
}
|
|
|
|
// Validation
|
|
public static function isValid(string $ip): bool
|
|
{
|
|
return filter_var($ip, FILTER_VALIDATE_IP) !== false;
|
|
}
|
|
|
|
// Basic checks
|
|
public function isPrivate(): bool
|
|
{
|
|
return ! filter_var($this->value, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE);
|
|
}
|
|
|
|
public function isPublic(): bool
|
|
{
|
|
return ! $this->isPrivate() && ! $this->isReserved();
|
|
}
|
|
|
|
public function isReserved(): bool
|
|
{
|
|
return filter_var($this->value, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) === false;
|
|
}
|
|
|
|
public function isLoopback(): bool
|
|
{
|
|
if ($this->isV4()) {
|
|
return str_starts_with($this->value, '127.');
|
|
}
|
|
|
|
return $this->value === '::1';
|
|
}
|
|
|
|
/**
|
|
* Check if IP is considered local (private or loopback)
|
|
*/
|
|
public function isLocal(): bool
|
|
{
|
|
return $this->isPrivate() || $this->isLoopback();
|
|
}
|
|
|
|
public function isV4(): bool
|
|
{
|
|
return filter_var($this->value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false;
|
|
}
|
|
|
|
public function isV6(): bool
|
|
{
|
|
return filter_var($this->value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false;
|
|
}
|
|
|
|
// Comparison
|
|
public function equals(IpAddress $other): bool
|
|
{
|
|
return $this->value === $other->value;
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
return $this->value;
|
|
}
|
|
}
|