Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yggverse/net-php
Network tools Library for PHP with native Yggdrasil / IPv6 support
https://github.com/yggverse/net-php
address composer converter dig dns dns-php dns-php-library dns-resolver-api ipv4 ipv6 net-php network network-api path php-dig php-resolver resolver uri url urn
Last synced: 1 day ago
JSON representation
Network tools Library for PHP with native Yggdrasil / IPv6 support
- Host: GitHub
- URL: https://github.com/yggverse/net-php
- Owner: YGGverse
- License: mit
- Created: 2023-12-15T09:51:40.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-07-11T07:10:37.000Z (4 months ago)
- Last Synced: 2024-08-09T09:49:39.683Z (3 months ago)
- Topics: address, composer, converter, dig, dns, dns-php, dns-php-library, dns-resolver-api, ipv4, ipv6, net-php, network, network-api, path, php-dig, php-resolver, resolver, uri, url, urn
- Language: PHP
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# net-php
Network Library for PHP with native Yggdrasil support
## Install
`composer require yggverse/net`
## Usage
### Socket
#### Check socket is open
``` php
var_dump(
\Yggverse\Net\Socket::isOpen('yo.index', 80)
);
```#### Check host valid
``` php
var_dump(
\Yggverse\Net\Socket::isHost('yo.index')
);
```#### Check port valid
``` php
var_dump(
\Yggverse\Net\Socket::isPort(80)
);
```### Dig
#### Resolve records
``` php
var_dump(
\Yggverse\Net\Dig::records('yo.index', ['A', 'AAAA'], &$result = [], &$error = [], $provider = null, $timeout = 5)
);
```#### Check hostname valid
``` php
var_dump(
\Yggverse\Net\Dig::isHostName('yo.index')
);
```#### Check record valid
``` php
var_dump(
\Yggverse\Net\Dig::isRecord('A')
);
```#### Check record value valid
``` php
var_dump(
\Yggverse\Net\Dig::isRecordValue('A', '127.0.0.1')
);
```### Resolve
#### Init resolver
``` php
$resolve = new \Yggverse\Net\Resolve(
[
'A',
'AAAA'
],
[
'1.1.1.1',
'8.8.8.8'
],
// ..
);
```#### Get resolved URL string
``` php
$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
);
}
```#### Resolve Address object
``` php
$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**
``` 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**
``` 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**
``` 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**
``` php
$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
);
```### Valid
Network entities validation
**Supported methods**
* `Valid::ip`
* `Valid::ip4`
* `Valid::ip6`
* `Valid::domainHostName`## Integrations
* [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