Network tools Library for PHP with native Yggdrasil / IPv6 support
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
3.5 KiB

# net-php
1 year ago
Network Library for PHP with native Yggdrasil support
1 year ago
## Install
`composer require yggverse/net`
1 year ago
## Usage
1 year ago
### Socket
#### Check socket is open
9 months ago
``` php
1 year ago
var_dump(
\Yggverse\Net\Socket::isOpen('yo.index', 80)
);
```
#### Check host valid
9 months ago
``` php
1 year ago
var_dump(
1 year ago
\Yggverse\Net\Socket::isHost('yo.index')
1 year ago
);
```
#### Check port valid
9 months ago
``` php
1 year ago
var_dump(
1 year ago
\Yggverse\Net\Socket::isPort(80)
1 year ago
);
```
### Dig
#### Resolve records
1 year ago
9 months ago
``` php
1 year ago
var_dump(
\Yggverse\Net\Dig::records('yo.index', ['A', 'AAAA'], &$result = [], &$error = [], $provider = null, $timeout = 5)
1 year ago
);
```
1 year ago
#### Check hostname valid
1 year ago
9 months ago
``` php
1 year ago
var_dump(
\Yggverse\Net\Dig::isHostName('yo.index')
1 year ago
);
1 year ago
```
1 year ago
1 year ago
#### Check record valid
1 year ago
9 months ago
``` php
1 year ago
var_dump(
\Yggverse\Net\Dig::isRecord('A')
1 year ago
);
1 year ago
```
1 year ago
1 year ago
#### Check record value valid
1 year ago
9 months ago
``` php
1 year ago
var_dump(
\Yggverse\Net\Dig::isRecordValue('A', '127.0.0.1')
1 year ago
);
1 year ago
```
### Resolve
9 months ago
#### Init resolver
9 months ago
``` php
$resolve = new \Yggverse\Net\Resolve(
[
'A',
'AAAA'
],
[
'1.1.1.1',
'8.8.8.8'
],
// ..
);
9 months ago
```
9 months ago
#### Get resolved URL string
9 months ago
``` php
9 months ago
$resolved = $resolve->url(
'https://en.wikipedia.org/wiki/Domain_Name_System'
9 months ago
// next arguments contain debug variables and new address object
);
if ($resolved)
{
var_dump(
$resolved // https://185.15.59.224/wiki/Domain_Name_System
);
}
```
#### Resolve Address object
9 months ago
``` php
9 months ago
$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
);
}
```
### Address
Includes methods to work with network addresses.
#### Base address methods
Different operations with address parts:
* `scheme`
* `user`
* `password`
* `host`
* `protocol`
* `path`
* `query`
* `fragment`
#### Address conversion from relative to absolute format
**Document root**
9 months ago
``` php
$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**
9 months ago
``` php
$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**
9 months ago
``` php
$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**
9 months ago
``` php
$base = new \Yggverse\Net\Address(
'http://user:password@yo.ygg/a1/b1/c1?attribute=value#anchor'
);
$address = new \Yggverse\Net\Address(
'../../a2/b2?attribute2=value2#anchor2'
);
var_dump(
$address->getAbsolute(
$base
) // return http://user:password@yo.ygg/a2/b2?attribute2=value2#anchor2
);
```
9 months ago
### Valid
Network entities validation
**Supported methods**
* `Valid::ip`
* `Valid::ip4`
* `Valid::ip6`
* `Valid::domainHostName`
1 year ago
## Integrations
6 months ago
* [gemini-dl](https://github.com/YGGverse/gemini-dl) - CLI batch downloader for Gemini protocol
* [web-api](https://github.com/YGGverse/web-api) - Network API with native Yggdrasil/IPv6 support
* [Yo!](https://github.com/YGGverse/Yo) - Crawler and search engine for different networks
* [Yoda](https://github.com/YGGverse/Yoda) - Experimental PHP-GTK browser for Gemini protocol