From 9506909e7a405c23b8515320e028a44fc35d9aef Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Sat, 4 Dec 2021 19:52:14 +0000 Subject: [PATCH] [COMPONENT][FreeNetwork] Iterate documentation --- .../FreeNetwork/Controller/Webfinger.php | 3 +++ components/FreeNetwork/FreeNetwork.php | 26 +++++++++++++++++-- components/FreeNetwork/Util/Discovery.php | 2 +- .../FreeNetwork/Util/WebfingerResource.php | 7 ++++- .../WebfingerResourceActor.php | 8 +++++- .../WebfingerResourceNote.php | 5 ++++ components/Notification/Notification.php | 9 +++++++ 7 files changed, 55 insertions(+), 5 deletions(-) diff --git a/components/FreeNetwork/Controller/Webfinger.php b/components/FreeNetwork/Controller/Webfinger.php index ffd5b3128d..9a87a3964e 100644 --- a/components/FreeNetwork/Controller/Webfinger.php +++ b/components/FreeNetwork/Controller/Webfinger.php @@ -61,6 +61,9 @@ class Webfinger extends XrdController return parent::handle($request); } + /** + * Configures $this->xrd which will later be printed. + */ protected function setXRD() { $this->xrd->subject = $this->resource; diff --git a/components/FreeNetwork/FreeNetwork.php b/components/FreeNetwork/FreeNetwork.php index ee22bf7579..c6a9867c1a 100644 --- a/components/FreeNetwork/FreeNetwork.php +++ b/components/FreeNetwork/FreeNetwork.php @@ -25,6 +25,12 @@ use App\Core\Event; use App\Core\GSFile; use App\Core\HTTPClient; use App\Entity\Activity; +use App\Util\Exception\NicknameEmptyException; +use App\Util\Exception\NicknameException; +use App\Util\Exception\NicknameInvalidException; +use App\Util\Exception\NicknameNotAllowedException; +use App\Util\Exception\NicknameTakenException; +use App\Util\Exception\NicknameTooLongException; use Plugin\ActivityPub\Entity\ActivitypubActor; use XML_XRD; use function App\Core\I18n\_m; @@ -49,7 +55,7 @@ use Component\FreeNetwork\Util\WebfingerResource\WebfingerResourceActor; use Component\FreeNetwork\Util\WebfingerResource\WebfingerResourceNote; use Exception; use Plugin\ActivityPub\Entity\ActivitypubActivity; -use Plugin\ActivityPub\Util\Response\TypeResponse; +use Plugin\ActivityPub\Util\TypeResponse; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use XML_XRD_Element_Link; @@ -107,7 +113,23 @@ class FreeNetwork extends Component return Event::stop; } - public function onEndGetWebFingerResource($resource, ?WebfingerResource &$target = null, array $args = []) + /** + * Last attempts getting a WebFingerResource object + * + * @param string $resource String that contains the requested URI + * @param WebfingerResource|null $target WebFingerResource extended object goes here + * @param array $args Array which may contains arguments such as 'rel' filtering values + * @return bool + * @throws NoSuchActorException + * @throws ServerException + * @throws NicknameEmptyException + * @throws NicknameException + * @throws NicknameInvalidException + * @throws NicknameNotAllowedException + * @throws NicknameTakenException + * @throws NicknameTooLongException + */ + public function onEndGetWebFingerResource(string $resource, ?WebfingerResource &$target = null, array $args = []): bool { // * Either we didn't find the profile, then we want to make // the $profile variable null for clarity. diff --git a/components/FreeNetwork/Util/Discovery.php b/components/FreeNetwork/Util/Discovery.php index a61b9de824..52944e41e2 100644 --- a/components/FreeNetwork/Util/Discovery.php +++ b/components/FreeNetwork/Util/Discovery.php @@ -204,7 +204,7 @@ class Discovery return $uri; } - public static function isAcct($uri): bool + public static function isAcct(string $uri): bool { return mb_strtolower(mb_substr($uri, 0, 5)) == 'acct:'; } diff --git a/components/FreeNetwork/Util/WebfingerResource.php b/components/FreeNetwork/Util/WebfingerResource.php index 4138d154b5..fc1e8b5bd7 100644 --- a/components/FreeNetwork/Util/WebfingerResource.php +++ b/components/FreeNetwork/Util/WebfingerResource.php @@ -38,7 +38,12 @@ abstract class WebfingerResource return $this->object; } - public function getAliases() + /** + * List of alternative IDs of a certain Actor + * + * @return array + */ + public function getAliases(): array { $aliases = $this->object->getAliasesWithIDs(); diff --git a/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceActor.php b/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceActor.php index 1803bd0af6..dd52623ca6 100644 --- a/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceActor.php +++ b/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceActor.php @@ -32,7 +32,7 @@ class WebfingerResourceActor extends WebFingerResource parent::__construct($object); } - public function getAliases() + public function getAliases(): array { $aliases = []; @@ -46,6 +46,12 @@ class WebfingerResourceActor extends WebFingerResource return array_merge($aliases, parent::getAliases()); } + /** + * Reconstruct WebFinger acct: from object + * + * @return array|false|mixed|string|string[]|null + * @throws WebfingerReconstructionException + */ public function reconstructAcct() { $acct = null; diff --git a/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceNote.php b/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceNote.php index bed625d65a..b3658fc8fd 100644 --- a/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceNote.php +++ b/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceNote.php @@ -28,6 +28,11 @@ class WebfingerResourceNote extends WebfingerResource parent::__construct($object); } + /** + * Update given XRD with self's data + * + * @param XML_XRD $xrd + */ public function updateXRD(XML_XRD $xrd) { if (Event::handle('StartWebFingerNoticeLinks', [$xrd, $this->object])) { diff --git a/components/Notification/Notification.php b/components/Notification/Notification.php index 074ace08cf..6bfe7fe563 100644 --- a/components/Notification/Notification.php +++ b/components/Notification/Notification.php @@ -42,6 +42,15 @@ class Notification extends Component return Event::next; } + /** + * Bring given Activity to Targets's attention + * + * @param Actor $sender + * @param Activity $activity + * @param array $targets + * @param string|null $reason + * @return bool + */ public function notify(Actor $sender, Activity $activity, array $targets, ?string $reason = null): bool { $remote_targets = [];