mirror of
https://github.com/YGGverse/net-php.git
synced 2026-03-31 17:15:35 +00:00
Compare commits
8 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ae447bcf0 | ||
|
|
b28658d041 | ||
|
|
9524c8fdec | ||
|
|
0079e2a755 | ||
|
|
0acff609f4 | ||
|
|
4f369bac45 | ||
|
|
7c918ff99c | ||
|
|
5e17d40245 |
2 changed files with 82 additions and 43 deletions
45
README.md
45
README.md
|
|
@ -12,7 +12,7 @@ Network Library for PHP with native Yggdrasil support
|
||||||
|
|
||||||
#### Check socket is open
|
#### Check socket is open
|
||||||
|
|
||||||
```
|
``` php
|
||||||
var_dump(
|
var_dump(
|
||||||
\Yggverse\Net\Socket::isOpen('yo.index', 80)
|
\Yggverse\Net\Socket::isOpen('yo.index', 80)
|
||||||
);
|
);
|
||||||
|
|
@ -20,7 +20,7 @@ var_dump(
|
||||||
|
|
||||||
#### Check host valid
|
#### Check host valid
|
||||||
|
|
||||||
```
|
``` php
|
||||||
var_dump(
|
var_dump(
|
||||||
\Yggverse\Net\Socket::isHost('yo.index')
|
\Yggverse\Net\Socket::isHost('yo.index')
|
||||||
);
|
);
|
||||||
|
|
@ -28,7 +28,7 @@ var_dump(
|
||||||
|
|
||||||
#### Check port valid
|
#### Check port valid
|
||||||
|
|
||||||
```
|
``` php
|
||||||
var_dump(
|
var_dump(
|
||||||
\Yggverse\Net\Socket::isPort(80)
|
\Yggverse\Net\Socket::isPort(80)
|
||||||
);
|
);
|
||||||
|
|
@ -38,7 +38,7 @@ var_dump(
|
||||||
|
|
||||||
#### Resolve records
|
#### Resolve records
|
||||||
|
|
||||||
```
|
``` php
|
||||||
var_dump(
|
var_dump(
|
||||||
\Yggverse\Net\Dig::records('yo.index', ['A', 'AAAA'], &$result = [], &$error = [], $provider = null, $timeout = 5)
|
\Yggverse\Net\Dig::records('yo.index', ['A', 'AAAA'], &$result = [], &$error = [], $provider = null, $timeout = 5)
|
||||||
);
|
);
|
||||||
|
|
@ -46,7 +46,7 @@ var_dump(
|
||||||
|
|
||||||
#### Check hostname valid
|
#### Check hostname valid
|
||||||
|
|
||||||
```
|
``` php
|
||||||
var_dump(
|
var_dump(
|
||||||
\Yggverse\Net\Dig::isHostName('yo.index')
|
\Yggverse\Net\Dig::isHostName('yo.index')
|
||||||
);
|
);
|
||||||
|
|
@ -54,7 +54,7 @@ var_dump(
|
||||||
|
|
||||||
#### Check record valid
|
#### Check record valid
|
||||||
|
|
||||||
```
|
``` php
|
||||||
var_dump(
|
var_dump(
|
||||||
\Yggverse\Net\Dig::isRecord('A')
|
\Yggverse\Net\Dig::isRecord('A')
|
||||||
);
|
);
|
||||||
|
|
@ -62,7 +62,7 @@ var_dump(
|
||||||
|
|
||||||
#### Check record value valid
|
#### Check record value valid
|
||||||
|
|
||||||
```
|
``` php
|
||||||
var_dump(
|
var_dump(
|
||||||
\Yggverse\Net\Dig::isRecordValue('A', '127.0.0.1')
|
\Yggverse\Net\Dig::isRecordValue('A', '127.0.0.1')
|
||||||
);
|
);
|
||||||
|
|
@ -72,7 +72,7 @@ var_dump(
|
||||||
|
|
||||||
#### Init resolver
|
#### Init resolver
|
||||||
|
|
||||||
```
|
``` php
|
||||||
$resolve = new \Yggverse\Net\Resolve(
|
$resolve = new \Yggverse\Net\Resolve(
|
||||||
[
|
[
|
||||||
'A',
|
'A',
|
||||||
|
|
@ -88,7 +88,7 @@ $resolve = new \Yggverse\Net\Resolve(
|
||||||
|
|
||||||
#### Get resolved URL string
|
#### Get resolved URL string
|
||||||
|
|
||||||
```
|
``` php
|
||||||
$resolved = $resolve->url(
|
$resolved = $resolve->url(
|
||||||
'https://en.wikipedia.org/wiki/Domain_Name_System'
|
'https://en.wikipedia.org/wiki/Domain_Name_System'
|
||||||
// next arguments contain debug variables and new address object
|
// next arguments contain debug variables and new address object
|
||||||
|
|
@ -104,7 +104,7 @@ if ($resolved)
|
||||||
|
|
||||||
#### Resolve Address object
|
#### Resolve Address object
|
||||||
|
|
||||||
```
|
``` php
|
||||||
$resolved = $resolve->address(
|
$resolved = $resolve->address(
|
||||||
new \Yggverse\Net\Address(
|
new \Yggverse\Net\Address(
|
||||||
'https://en.wikipedia.org/wiki/Domain_Name_System'
|
'https://en.wikipedia.org/wiki/Domain_Name_System'
|
||||||
|
|
@ -144,7 +144,7 @@ Different operations with address parts:
|
||||||
|
|
||||||
**Document root**
|
**Document root**
|
||||||
|
|
||||||
```
|
``` php
|
||||||
$base = new \Yggverse\Net\Address(
|
$base = new \Yggverse\Net\Address(
|
||||||
'http://yo.ygg/a1/b1/c1'
|
'http://yo.ygg/a1/b1/c1'
|
||||||
);
|
);
|
||||||
|
|
@ -162,7 +162,7 @@ var_dump(
|
||||||
|
|
||||||
**Current folder**
|
**Current folder**
|
||||||
|
|
||||||
```
|
``` php
|
||||||
$base = new \Yggverse\Net\Address(
|
$base = new \Yggverse\Net\Address(
|
||||||
'http://yo.ygg/a1/b1/c1'
|
'http://yo.ygg/a1/b1/c1'
|
||||||
);
|
);
|
||||||
|
|
@ -180,7 +180,7 @@ var_dump(
|
||||||
|
|
||||||
**Ending slash**
|
**Ending slash**
|
||||||
|
|
||||||
```
|
``` php
|
||||||
$base = new \Yggverse\Net\Address(
|
$base = new \Yggverse\Net\Address(
|
||||||
'http://yo.ygg/a1/b1/c1/'
|
'http://yo.ygg/a1/b1/c1/'
|
||||||
);
|
);
|
||||||
|
|
@ -198,7 +198,7 @@ var_dump(
|
||||||
|
|
||||||
**All options**
|
**All options**
|
||||||
|
|
||||||
```
|
``` php
|
||||||
$base = new \Yggverse\Net\Address(
|
$base = new \Yggverse\Net\Address(
|
||||||
'http://user:password@yo.ygg/a1/b1/c1?attribute=value#anchor'
|
'http://user:password@yo.ygg/a1/b1/c1?attribute=value#anchor'
|
||||||
);
|
);
|
||||||
|
|
@ -214,7 +214,20 @@ var_dump(
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Valid
|
||||||
|
|
||||||
|
Network entities validation
|
||||||
|
|
||||||
|
**Supported methods**
|
||||||
|
|
||||||
|
* `Valid::ip`
|
||||||
|
* `Valid::ip4`
|
||||||
|
* `Valid::ip6`
|
||||||
|
* `Valid::domainHostName`
|
||||||
|
|
||||||
## Integrations
|
## Integrations
|
||||||
|
|
||||||
* [Network API with native Yggdrasil/IPv6 support](https://github.com/YGGverse/web-api)
|
* [gemini-dl](https://github.com/YGGverse/gemini-dl) - CLI batch downloader for Gemini protocol
|
||||||
* [Yo! Crawler for different networks](https://github.com/YGGverse/Yo)
|
* [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
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,9 @@ class Address
|
||||||
|
|
||||||
public function isAbsolute(): bool
|
public function isAbsolute(): bool
|
||||||
{
|
{
|
||||||
return ($this->_scheme && $this->_host);
|
return boolval(
|
||||||
|
$this->_scheme || $this->_host
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isRelative(): bool
|
public function isRelative(): bool
|
||||||
|
|
@ -198,28 +200,37 @@ class Address
|
||||||
$this->_separator = $value;
|
$this->_separator = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(): string
|
public function get(
|
||||||
|
bool $scheme = true,
|
||||||
|
bool $user = true,
|
||||||
|
bool $pass = true,
|
||||||
|
bool $host = true,
|
||||||
|
bool $port = true,
|
||||||
|
bool $path = true,
|
||||||
|
bool $query = true,
|
||||||
|
bool $fragment = true,
|
||||||
|
): string
|
||||||
{
|
{
|
||||||
$address = '';
|
$address = '';
|
||||||
|
|
||||||
if ($scheme = $this->getScheme())
|
if ($scheme && $this->getScheme())
|
||||||
{
|
{
|
||||||
$address .= sprintf(
|
$address .= sprintf(
|
||||||
'%s:%s%s',
|
'%s:%s%s',
|
||||||
$scheme,
|
$this->getScheme(),
|
||||||
$this->getSeparator(),
|
$this->getSeparator(),
|
||||||
$this->getSeparator()
|
$this->getSeparator()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user = $this->getUser())
|
if ($user && $this->getUser())
|
||||||
{
|
{
|
||||||
if ($pass = $this->getPass())
|
if ($pass && $this->getPass())
|
||||||
{
|
{
|
||||||
$address .= sprintf(
|
$address .= sprintf(
|
||||||
'%s:%s@',
|
'%s:%s@',
|
||||||
$user,
|
$this->getUser(),
|
||||||
$pass
|
$this->getPass()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -227,65 +238,65 @@ class Address
|
||||||
{
|
{
|
||||||
$address .= sprintf(
|
$address .= sprintf(
|
||||||
'%s@',
|
'%s@',
|
||||||
$user
|
$this->getUser()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($host = $this->getHost())
|
if ($host && $this->getHost())
|
||||||
{
|
{
|
||||||
$address .= $host;
|
$address .= $this->getHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($port = $this->getPort())
|
if ($port && $this->getPort())
|
||||||
{
|
{
|
||||||
$address .= sprintf(
|
$address .= sprintf(
|
||||||
':%d',
|
':%d',
|
||||||
$port
|
$this->getPort()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($path = $this->getPath())
|
if ($path && $this->getPath())
|
||||||
{
|
{
|
||||||
if (!str_starts_with($path, $this->getSeparator()))
|
if (!str_starts_with($this->getPath(), $this->getSeparator()))
|
||||||
{
|
{
|
||||||
$address .= $this->getSeparator();
|
$address .= $this->getSeparator();
|
||||||
}
|
}
|
||||||
|
|
||||||
$address .= $path;
|
$address .= $this->getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($query = $this->getQuery())
|
if ($query && $this->getQuery())
|
||||||
{
|
{
|
||||||
$address .= sprintf(
|
$address .= sprintf(
|
||||||
'?%s',
|
'?%s',
|
||||||
$query
|
$this->getQuery()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($fragment = $this->getFragment())
|
if ($fragment && $this->getFragment())
|
||||||
{
|
{
|
||||||
$address .= sprintf(
|
$address .= sprintf(
|
||||||
'#%s',
|
'#%s',
|
||||||
$fragment
|
$this->getFragment()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $address;
|
return $address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAbsolute(
|
public function toAbsolute(
|
||||||
\Yggverse\Net\Address $base
|
\Yggverse\Net\Address $base
|
||||||
): ?string
|
): bool
|
||||||
{
|
{
|
||||||
if ($this->isAbsolute())
|
if ($this->isAbsolute())
|
||||||
{
|
{
|
||||||
return $this->get();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($base->isRelative())
|
if ($base->isRelative())
|
||||||
{
|
{
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setScheme(
|
$this->setScheme(
|
||||||
|
|
@ -314,7 +325,7 @@ class Address
|
||||||
|
|
||||||
if (str_starts_with((string) $this->getPath(), $this->getSeparator()))
|
if (str_starts_with((string) $this->getPath(), $this->getSeparator()))
|
||||||
{
|
{
|
||||||
return $this->get();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($path = $this->getPath())
|
if ($path = $this->getPath())
|
||||||
|
|
@ -342,7 +353,7 @@ class Address
|
||||||
{
|
{
|
||||||
if (empty($prefix[$index]))
|
if (empty($prefix[$index]))
|
||||||
{
|
{
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unset(
|
unset(
|
||||||
|
|
@ -368,8 +379,23 @@ class Address
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @TODO deprecated, legacy needs only
|
||||||
|
public function getAbsolute(
|
||||||
|
\Yggverse\Net\Address $base
|
||||||
|
): ?string
|
||||||
|
{
|
||||||
|
if ($this->toAbsolute($base))
|
||||||
|
{
|
||||||
return $this->get();
|
return $this->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue