Initial commit, start creating a webmention sender
This commit is contained in:
commit
4eba80387d
7 files changed
+2588
No files matched your search
@@ -0,0 +1,31 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Lewisdale\Webmentions;
|
||||
|
||||
use Symfony\Contracts\HttpClient\ResponseInterface;
|
||||
|
||||
class EndpointParser {
|
||||
public static function parse(ResponseInterface $response) : string | null
|
||||
{
|
||||
$headers = $response->getHeaders();
|
||||
$endpoint = null;
|
||||
|
||||
if (isset($headers["link"])) {
|
||||
$link = $headers["link"][0];
|
||||
if (preg_match('/rel=("?)webmention("?)/', $link)) {
|
||||
$matches = [];
|
||||
preg_match('/\<(..*?)\>/', $link, $matches);
|
||||
|
||||
if (count($matches) > 1) {
|
||||
$endpoint = $matches[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($endpoint && !str_contains($endpoint, "https://")) {
|
||||
$res = parse_url($response->getInfo('url'));
|
||||
$endpoint = $res["scheme"] . "://" . $res["host"] . $endpoint;
|
||||
}
|
||||
return $endpoint;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user