blob: 053418c3fcdd6a79ae45d9d633d908b43bd5da9a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<?php
namespace Digitigrade\Policy;
use Digitigrade\Model\Actor;
use Digitigrade\Model\Instance;
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|Instance|null $obj): bool {
if ($obj == null) {
return false;
}
$objHost = hostname_from_uri($obj instanceof Instance ? $obj->domain : $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);
}
public function checkActorFederation(Actor $actor, ?Instance $instance): bool {
return !$this->isBlocked($instance);
}
public function checkInteractionFederation(Interaction $interaction, ?Instance $instance): bool {
return !$this->isBlocked($instance);
}
public function checkNoteFederation(Note $note, ?Instance $instance): bool {
return !$this->isBlocked($instance);
}
}
|