mirror of
https://github.com/YGGverse/gemini-php.git
synced 2026-04-01 01:15:28 +00:00
Implement Gemtext/Link class
This commit is contained in:
parent
be8b86102f
commit
7916351299
2 changed files with 106 additions and 1 deletions
63
src/Gemtext/Link.php
Normal file
63
src/Gemtext/Link.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Gemini\Gemtext;
|
||||
|
||||
class Link
|
||||
{
|
||||
private string $_line;
|
||||
|
||||
public function __construct(string $line)
|
||||
{
|
||||
$this->_line = $line;
|
||||
}
|
||||
|
||||
public function getAddress(): ?string
|
||||
{
|
||||
if (preg_match('/^([^\s]+)\s.*/', trim($this->_line), $match))
|
||||
{
|
||||
return trim(
|
||||
$match[1]
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getDate(?int &$timestamp = null): ?string
|
||||
{
|
||||
if (preg_match('/\s([\d]+-[\d+]+-[\d]+)\s/', trim($this->_line), $match))
|
||||
{
|
||||
if ($result = strtotime($match[1]))
|
||||
{
|
||||
$timestamp = $result;
|
||||
|
||||
return trim(
|
||||
$match[1]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getAlt(): ?string
|
||||
{
|
||||
if (preg_match('/\s[\d]+-[\d+]+-[\d]+\s(.*)$/', trim($this->_line), $match))
|
||||
{
|
||||
return trim(
|
||||
$match[1]
|
||||
);
|
||||
}
|
||||
|
||||
else if (preg_match('/\s(.*)$/', trim($this->_line), $match))
|
||||
{
|
||||
return trim(
|
||||
$match[1]
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue