Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Aug 3, 2024
1 parent c62c6f4 commit 5c798b6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,29 @@ if (!DnsHelper::existsA('yiiframework.com')) {
}
```

### `IpRanges`

```php
use Yiisoft\NetworkUtilities\IpRanges;

$ipRanges = new IpRanges(
[
'10.0.1.0/24',
'2001:db0:1:2::/64',
IpRanges::LOCALHOST,
'myNetworkEu',
'!' . IpRanges::ANY,
],
[
'myNetworkEu' => ['1.2.3.4/10', '5.6.7.8'],
],
);

$ipRanges->isAllowed('10.0.1.28/28'); // true
$ipRanges->isAllowed('1.2.3.4'); // true
$ipRanges->isAllowed('192.168.0.1'); // false
```

## Documentation

- [Internals](docs/internals.md)
Expand Down
20 changes: 20 additions & 0 deletions tests/IpRangesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@

final class IpRangesTest extends TestCase
{
public function testReadmeExample(): void
{
$ipRanges = new IpRanges(
[
'10.0.1.0/24',
'2001:db0:1:2::/64',
IpRanges::LOCALHOST,
'myNetworkEu',
'!' . IpRanges::ANY,
],
[
'myNetworkEu' => ['1.2.3.4/10', '5.6.7.8'],
],
);

$this->assertTrue($ipRanges->isAllowed('10.0.1.28/28'));
$this->assertTrue($ipRanges->isAllowed('1.2.3.4'));
$this->assertFalse($ipRanges->isAllowed('192.168.0.1'));
}

public function testNetworkAliasException(): void
{
$this->expectException(InvalidArgumentException::class);
Expand Down

0 comments on commit 5c798b6

Please sign in to comment.