| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\HttpFoundation\RequestMatcher; |
| 13 |
|
| 14 |
use Symfony\Component\HttpFoundation\IpUtils; |
| 15 |
use Symfony\Component\HttpFoundation\Request; |
| 16 |
use Symfony\Component\HttpFoundation\RequestMatcherInterface; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
class IpsRequestMatcher implements RequestMatcherInterface |
| 24 |
{ |
| 25 |
private array $ips; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public function __construct(array|string $ips) |
| 32 |
{ |
| 33 |
$this->ips = array_reduce((array) $ips, static fn (array $ips, string $ip) => array_merge($ips, preg_split('/\s*,\s*/', $ip)), []); |
| 34 |
} |
| 35 |
|
| 36 |
public function matches(Request $request): bool |
| 37 |
{ |
| 38 |
if (!$this->ips) { |
| 39 |
return true; |
| 40 |
} |
| 41 |
|
| 42 |
return IpUtils::checkIp($request->getClientIp() ?? '', $this->ips); |
| 43 |
} |
| 44 |
} |