Initial commit, start creating a webmention sender

This commit is contained in:
Lewis Dale committed 2023-03-08 15:31:49 +00:00
commit 4eba80387d
7 files changed
+2588

No files matched your search

+31
View File
@@ -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;
}
}