webmentions/src/Endpoint.php

34 lines
927 B
PHP
Raw Normal View History

2023-03-09 09:48:08 +00:00
<?php declare(strict_types=1);
namespace Lewisdale\Webmentions;
use Lewisdale\Webmentions\Gateways\WebmentionGatewayInterface;
class Endpoint {
private readonly WebmentionGatewayInterface $gateway;
public function validateUrl(string $url) : bool {
return !!filter_var($url, FILTER_VALIDATE_URL);
}
public function receiveWebmention(string $source, string $target) : void
{
// Validate that both source and target are actual domains
if (!$this->validateUrl($source) || !$this->validateUrl($target))
{
return;
}
// Validate that the webmention target is a domain I care about
if (!str_contains($target, "https://lewisdale.dev")) {
// Should throw a Bad Request error
return;
}
// Parse content from the source
// Store the webmention
// Send the appropriate response
}
2023-03-09 09:48:08 +00:00
}