diff options
| author | winter | 2025-02-23 18:32:09 +0000 |
|---|---|---|
| committer | winter | 2025-02-23 18:32:09 +0000 |
| commit | 261ab1364aa40384b0315be60e78cd89ea7fe661 (patch) | |
| tree | bf114af430c761abfaf33e814e3cf9ba0ed096d2 /Digitigrade/Policy/BlockInstance.php | |
| parent | 1ba56a5b687e6c906c2b24e5b37df119ef5752e3 (diff) | |
implement policies
Diffstat (limited to 'Digitigrade/Policy/BlockInstance.php')
| -rw-r--r-- | Digitigrade/Policy/BlockInstance.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Digitigrade/Policy/BlockInstance.php b/Digitigrade/Policy/BlockInstance.php new file mode 100644 index 0000000..5f902f2 --- /dev/null +++ b/Digitigrade/Policy/BlockInstance.php @@ -0,0 +1,37 @@ +<?php +namespace Digitigrade\Policy; + +use Digitigrade\Model\Actor; +use Digitigrade\Model\Interaction; +use Digitigrade\Model\Note; +use Digitigrade\Model\PushableModel; +use Digitigrade\Policy; + +class BlockInstance extends Policy { + /** @var string[] */ + private array $blockedHosts; + + public function __construct(string ...$hosts) { + $this->blockedHosts = $hosts; + } + + private function isBlocked(PushableModel $obj): bool { + $objHost = hostname_from_uri($obj->uri); + foreach ($this->blockedHosts as $host) { + if (str_ends_with($objHost, $host)) { + return true; + } + } + return false; + } + + public function checkActor(Actor $actor): bool { + return !$this->isBlocked($actor); + } + public function checkInteraction(Interaction $interaction): bool { + return !$this->isBlocked($interaction); + } + public function checkNote(Note $note): bool { + return !$this->isBlocked($note); + } +}
\ No newline at end of file |
