Network Library for PHP with native Yggdrasil support
composer require yggverse/net
var_dump(
\Yggverse\Net\Socket::isOpen('yo.index', 80)
);
var_dump(
\Yggverse\Net\Socket::isHost('yo.index')
);
var_dump(
\Yggverse\Net\Socket::isPort(80)
);
var_dump(
\Yggverse\Net\Dig::records('yo.index', ['A', 'AAAA'], &$result = [], &$error = [], $provider = null, $timeout = 5)
);
var_dump(
\Yggverse\Net\Dig::isHostName('yo.index')
);
var_dump(
\Yggverse\Net\Dig::isRecord('A')
);
var_dump(
\Yggverse\Net\Dig::isRecordValue('A', '127.0.0.1')
);
$resolve = new \Yggverse\Net\Resolve(
[
'A',
'AAAA'
],
[
'1.1.1.1',
'8.8.8.8'
],
// ..
);
$resolved = $resolve->url(
'https://en.wikipedia.org/wiki/Domain_Name_System'
// next arguments contain debug variables and new address object
);
if ($resolved)
{
var_dump(
$resolved // https://185.15.59.224/wiki/Domain_Name_System
);
}
$resolved = $resolve->address(
new \Yggverse\Net\Address(
'https://en.wikipedia.org/wiki/Domain_Name_System'
)
);
if ($resolved)
{
var_dump(
$resolved->get() // https://185.15.59.224/wiki/Domain_Name_System
);
var_dump(
$resolved->getHost() // 185.15.59.224
);
}
Includes methods to work with network addresses.
Different operations with address parts:
scheme
user
password
host
protocol
path
query
fragment
Document root
$base = new \Yggverse\Net\Address(
'http://yo.ygg/a1/b1/c1'
);
$address = new \Yggverse\Net\Address(
'/a2'
);
var_dump(
$address->getAbsolute(
$base
) // return http://yo.ygg/a2
);
Current folder
$base = new \Yggverse\Net\Address(
'http://yo.ygg/a1/b1/c1'
);
$address = new \Yggverse\Net\Address(
'c2'
);
var_dump(
$address->getAbsolute(
$base
) // return http://yo.ygg/a1/b1/c2
);
Ending slash
$base = new \Yggverse\Net\Address(
'http://yo.ygg/a1/b1/c1/'
);
$address = new \Yggverse\Net\Address(
'../../b2/c2'
);
var_dump(
$address->getAbsolute(
$base
) // return http://yo.ygg/a1/b2/c2
);
All options
$base = new \Yggverse\Net\Address(
'http://user:[email protected]/a1/b1/c1?attribute=value#anchor'
);
$address = new \Yggverse\Net\Address(
'../../a2/b2?attribute2=value2#anchor2'
);
var_dump(
$address->getAbsolute(
$base
) // return http://user:[email protected]/a2/b2?attribute2=value2#anchor2
);
Network entities validation
Supported methods
Valid::ip
Valid::ip4
Valid::ip6
Valid::domainHostName