Skip to content

Network

Pieter Hordijk edited this page Jan 1, 2019 · 1 revision

TOC

MxRecord

Validates the input (string address) to have a MX DNS record.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Network\Dns\MxRecord;

(new MxRecord())->validate('example.com');

Failure reasons

  • Type.String when the validated value is not a string
  • Network.Dns.MxRecord when the validated value does not contain an MX record

RecordExists

Validates the input (string address) to have a DNS record of type \HarmonyIO\Validation\Enum\Network\Dns\RecordType.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Enum\Network\Dns\RecordType;
use HarmonyIO\Validation\Rule\Network\Dns\RecordExists;

(new RecordExists(RecordType::A()))->validate('example.com');

Failure reasons

  • Type.String when the validated value is not a string
  • Network.Dns.RecordExists when the validated value does not contain the defined record type

Tld

Validates the input (string TLD) to ba a valid and registered Tld.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use Amp\Artax\DefaultClient;
use Amp\Redis\Client;
use HarmonyIO\Cache\Provider\Redis;
use HarmonyIO\HttpClient\Client\ArtaxClient;
use HarmonyIO\Validation\Rule\Network\Domain\Tld;

$httpClient = new ArtaxClient(new DefaultClient(), new Redis(new Client('tcp://127.0.0.1:6379')));

(new Tld($httpClient))->validate('com');

Note: the source of valid TLDs is retrieved from IANA (https://data.iana.org/TLD/tlds-alpha-by-domain.txt)and is cached for 7 days.

Failure reasons

  • Type.String when the validated value is not a string
  • Network.Domain.Tld when the validated value is not a valid TLD

InCidrRange

Validates the input (string ip address) to be in the defined range (string ...$cidrRange).

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Network\IpAddress\InCidrRange;

(new InCidrRange('192.168.100.0/24'))->validate('192.168.210.10');

Failure reasons

  • Type.String when the validated value is not a string
  • Network.IpAddress.InCidrRange when the validated value is not within the specified range

Ipv4

Validates the input (string ip address) to be a valid IPv4 address.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Network\IpAddress\IPv4;

(new Ipv4())->validate('192.168.210.10');

Failure reasons

  • Type.String when the validated value is not a string
  • Network.IpAddress.Ipv4 when the validated value is not a valid IPv4 address

Ipv6

Validates the input (string ip address) to be a valid IPv6 address.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Network\IpAddress\IPv6;

(new Ipv6())->validate('2001:0db8:85a3:0000:0000:8a2e:0370:7334');

Failure reasons

  • Type.String when the validated value is not a string
  • Network.IpAddress.Ipv6 when the validated value is not a valid IPv6 address

NotInPrivateRange

Validates the input (string ip address) to not be a private IP address.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Network\IpAddress\NotInPrivateRange;

(new NotInPrivateRange())->validate('80.24.72.48');

Failure reasons

  • Type.String when the validated value is not a string
  • Network.IpAddress.NotInPrivateRange when the validated value is in one of the private ranges of IP addresses

NotInReservedRange

Validates the input (string ip address) to not be a reserved IP address.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Network\IpAddress\NotInReservedRange;

(new NotInReservedRange())->validate('80.24.72.48');

Failure reasons

  • Type.String when the validated value is not a string
  • Network.IpAddress.NotInReservedRange when the validated value is a reserved IP addresses

OkResponse

Validates the input (string) URL to return a HTTP status 200.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use Amp\Artax\DefaultClient;
use Amp\Redis\Client;
use HarmonyIO\Cache\Provider\Redis;
use HarmonyIO\HttpClient\Client\ArtaxClient;
use HarmonyIO\Validation\Rule\Network\Url\OkResponse;

$httpClient = new ArtaxClient(new DefaultClient(), new Redis(new Client('tcp://127.0.0.1:6379')));

(new OkResponse($httpClient))->validate('https://example.com');

Failure reasons

  • Type.String when the validated value is not a string
  • Network.Url.OkResponse when the URL does not result in a 200 HTTP response

Url

Validates the input (string) URL to be syntactically valid.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Network\Url\Url;

(new Url())->validate('https://example.com');

Failure reasons

  • Type.String when the validated value is not a string
  • Network.Url.Url when the URL is not valid