mirror of
https://github.com/nextcloud/server.git
synced 2026-03-02 05:20:46 -05:00
Bumps [nextcloud/coding-standard](https://github.com/nextcloud/coding-standard) from 1.3.1 to 1.3.2. - [Release notes](https://github.com/nextcloud/coding-standard/releases) - [Changelog](https://github.com/nextcloud/coding-standard/blob/master/CHANGELOG.md) - [Commits](https://github.com/nextcloud/coding-standard/compare/v1.3.1...v1.3.2) --- updated-dependencies: - dependency-name: nextcloud/coding-standard dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: provokateurin <kate@provokateurin.de>
48 lines
996 B
PHP
48 lines
996 B
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
/**
|
||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||
*/
|
||
|
||
namespace OC\Security\Ip;
|
||
|
||
use InvalidArgumentException;
|
||
use IPLib\Address\AddressInterface;
|
||
use IPLib\Factory;
|
||
use OCP\Security\Ip\IAddress;
|
||
use OCP\Security\Ip\IRange;
|
||
|
||
/**
|
||
* @since 30.0.0
|
||
*/
|
||
class Address implements IAddress {
|
||
private readonly AddressInterface $ip;
|
||
|
||
public function __construct(string $ip) {
|
||
$ip = Factory::parseAddressString($ip);
|
||
if ($ip === null) {
|
||
throw new InvalidArgumentException('Given IP address can’t be parsed');
|
||
}
|
||
$this->ip = $ip;
|
||
}
|
||
|
||
public static function isValid(string $ip): bool {
|
||
return Factory::parseAddressString($ip) !== null;
|
||
}
|
||
|
||
public function matches(IRange ... $ranges): bool {
|
||
foreach ($ranges as $range) {
|
||
if ($range->contains($this)) {
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
public function __toString(): string {
|
||
return $this->ip->toString();
|
||
}
|
||
}
|