From 22a1e00a2aead51f17e3ebd23b94476d8e2b276e Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Mon, 3 Dec 2018 21:07:26 -0100 Subject: [PATCH] spliting ACore (ActivityPub Core methods) -> Item (model) Signed-off-by: Maxence Lange --- lib/Model/ActivityPub/ACore.php | 729 ++++---------------------------- lib/Model/ActivityPub/Item.php | 603 ++++++++++++++++++++++++++ 2 files changed, 684 insertions(+), 648 deletions(-) create mode 100644 lib/Model/ActivityPub/Item.php diff --git a/lib/Model/ActivityPub/ACore.php b/lib/Model/ActivityPub/ACore.php index e0df238f..ebb2e0e0 100644 --- a/lib/Model/ActivityPub/ACore.php +++ b/lib/Model/ActivityPub/ACore.php @@ -36,11 +36,10 @@ use JsonSerializable; use OCA\Social\Exceptions\ActivityCantBeVerifiedException; use OCA\Social\Exceptions\InvalidOriginException; use OCA\Social\Exceptions\UrlCloudException; -use OCA\Social\Model\InstancePath; use OCA\Social\Service\ActivityPub\ICoreService; -abstract class ACore implements JsonSerializable { +abstract class ACore extends Item implements JsonSerializable { use TArrayTools; @@ -59,99 +58,24 @@ abstract class ACore implements JsonSerializable { const AS_STRING = 7; - /** @var string */ - private $urlSocial = ''; - - /** @var string */ - private $urlCloud = ''; - -// /** @var bool */ -// private $isTopLevel = false; - - /** @var array */ - private $meta = []; - - /** @var string */ - private $address = ''; - - /** @var string */ - private $id = ''; - - /** @var string */ - private $type = ''; - - /** @var string */ - private $url = ''; - - /** @var string */ - private $summary = ''; - - /** @var InstancePath[] */ - private $instancePaths = []; - - /** @var string */ - private $to = ''; - - /** @var array */ - private $toArray = []; - - /** @var array */ - private $cc = []; - - /** @var array */ - private $bcc = []; - - /** @var string */ - private $published = ''; - - /** @var array */ - private $tags = []; + /** @var null Item */ + private $parent = null; /** @var array */ private $entries = []; - /** @var Person */ - private $actor = null; - - /** @var string */ - private $actorId = ''; - - /** @var Document */ - private $icon = null; - /** @var ACore */ private $object = null; - /** @var string */ - private $objectId = ''; - /** @var ICoreService */ private $saveAs; - /** @var bool */ - private $completeDetails = false; - - /** @var string */ - private $source = ''; - - /** @var null ACore */ - private $parent = null; - - /** @var bool */ - private $local = false; - - /** @var string */ - private $origin = ''; - - /** * Core constructor. * * @param ACore $parent */ public function __construct($parent = null) { -// $this->isTopLevel = $isTopLevel; - if ($parent instanceof ACore) { $this->setParent($parent); } @@ -159,23 +83,68 @@ abstract class ACore implements JsonSerializable { /** - * @return string - */ - public function getId(): string { - return $this->id; - } - - /** - * @param string $id + * @param Item $parent * - * @return ACore + * @return Item */ - public function setId(string $id): ACore { - $this->id = $id; + public function setParent(Item $parent): ACore { + $this->parent = $parent; return $this; } + /** + * @return Item + */ + public function getParent(): ACore { + return $this->parent; + } + + + /** + * @return bool + */ + public function gotObject(): bool { + if ($this->object === null) { + return false; + } + + return true; + } + + /** + * @return ACore + */ + public function getObject(): ACore { + return $this->object; + } + + /** + * @param ACore $object + * + * @return ACore + */ + public function setObject(ACore $object): ACore { + $this->object = $object; + + return $this; + } + + /** + * @param ICoreService $class + */ + public function saveAs(ICoreService $class) { + $this->saveAs = $class; + } + + /** + * @return ICoreService + */ + public function savingAs() { + return $this->saveAs; + } + + /** * @param string $base * @@ -199,325 +168,6 @@ abstract class ACore implements JsonSerializable { $this->setId($this->getUrlCloud() . $base . '/' . $uuid); } - /** - * @return string - */ - public function getType(): string { - return $this->type; - } - - /** - * @param string $type - * - * @return ACore - */ - public function setType(string $type): ACore { -// if ($type !== '') { - $this->type = $type; - -// } - - return $this; - } - - - /** - * @return string - */ - public function getUrl(): string { - return $this->url; - } - - /** - * @param string $url - * - * @return ACore - */ - public function setUrl(string $url): ACore { - $this->url = $url; - - return $this; - } - - - /** - * @param InstancePath $instancePath - * - * @return ACore - */ - public function addInstancePath(InstancePath $instancePath): ACore { - if ($instancePath->getUri() !== '') { - $this->instancePaths[] = $instancePath; - } - - return $this; - } - - - /** - * @param InstancePath[] $path - * - * @return ACore - */ - public function addInstancePaths(array $path): ACore { - $this->instancePaths = array_merge($this->instancePaths, $path); - - return $this; - } - - /** - * @return InstancePath[] - */ - public function getInstancePaths(): array { - return $this->instancePaths; - } - - /** - * @param InstancePath[] $instancePaths - * - * @return ACore - */ - public function setInstancePaths(array $instancePaths): ACore { - $this->instancePaths = $instancePaths; - - return $this; - } - - - /** - * @return string - */ - public function getSummary(): string { - return $this->summary; - } - - /** - * @param string $summary - * - * @return ACore - */ - public function setSummary(string $summary): ACore { - $this->summary = $summary; - - return $this; - } - - - /** - * @return Person - */ - public function getActor(): Person { - return $this->actor; - } - - /** - * @param Person $actor - * - * @return ACore - */ - public function setActor(Person $actor): ACore { - $this->actor = $actor; - - return $this; - } - - /** - * @return bool - */ - public function gotActor(): bool { - if ($this->actor === null) { - return false; - } - - return true; - } - - - /** - * @param string $actorId - * - * @return ACore - */ - public function setActorId(string $actorId): ACore { - $this->actorId = $actorId; - - return $this; - } - - /** - * @return string - */ - public function getActorId(): string { - return $this->actorId; - } - - - /** - * @return string - */ - public function getUrlSocial(): string { - return $this->urlSocial; - } - - /** - * @param string $path - * - * @return ACore - */ - public function setUrlSocial(string $path): ACore { - $this->urlSocial = $path; - - return $this; - } - - - /** - * @return string - */ - public function getUrlCloud(): string { - return $this->urlCloud; - } - - /** - * @param string $path - * - * @return ACore - */ - public function setUrlCloud(string $path): ACore { - $this->urlCloud = $path; - - return $this; - } - - - /** - * @return string - */ - public function getAddress(): string { - return $this->address; - } - - /** - * @param string $address - * - * @return ACore - */ - public function setAddress(string $address) { - $this->address = $address; - - return $this; - } - - - /** - * @return string - */ - public function getTo(): string { - return $this->to; - } - - /** - * @param string $to - * - * @return ACore - */ - public function setTo(string $to): ACore { - $this->to = $to; - - return $this; - } - - /** - * @return array - */ - public function getToArray(): array { - return $this->toArray; - } - - /** - * @param string $to - * - * @return ACore - */ - public function addToArray(string $to): ACore { - $this->toArray[] = $to; - - return $this; - } - - /** - * @param array $toArray - * - * @return ACore - */ - public function setToArray(array $toArray): ACore { - $this->toArray = $toArray; - - return $this; - } - - - public function addCc(string $cc): Acore { - $this->cc[] = $cc; - - return $this; - } - - /** - * @return array - */ - public function getCcArray(): array { - return $this->cc; - } - - /** - * @param array $cc - * - * @return ACore - */ - public function setCcArray(array $cc): ACore { - $this->cc = $cc; - - return $this; - } - - - /** - * @return array - */ - public function getBccArray(): array { - return $this->bcc; - } - - /** - * @param array $bcc - * - * @return ACore - */ - public function setBccArray(array $bcc): ACore { - $this->bcc = $bcc; - - return $this; - } - - - /** - * @return string - */ - public function getOrigin(): string { - return $this->origin; - } - - /** - * @param string $origin - * - * @return ACore - */ - public function setOrigin(string $origin): ACore { - $this->origin = $origin; - - return $this; - } /** * @param $id @@ -525,7 +175,7 @@ abstract class ACore implements JsonSerializable { * @throws InvalidOriginException */ public function checkOrigin($id) { - + // TODO - compare with verify $host = parse_url($id, PHP_URL_HOST); if ($this->getRoot() ->getOrigin() === $host) { @@ -562,171 +212,6 @@ abstract class ACore implements JsonSerializable { } - /** - * @param string $published - * - * @return ACore - */ - public function setPublished(string $published): ACore { - $this->published = $published; - - return $this; - } - - /** - * @return string - */ - public function getPublished(): string { - return $this->published; - } - - - /** - * @param array $tag - * - * @return ACore - */ - public function addTag(array $tag): ACore { - $this->tags[] = $tag; - - return $this; - } - - /** - * @return array - */ - public function getTags(): array { - return $this->tags; - } - - /** - * @param array $tag - * - * @return ACore - */ - public function setTags(array $tag): ACore { - $this->tags = $tag; - - return $this; - } - - - /** - * @return bool - */ - public function gotObject(): bool { - if ($this->object === null) { - return false; - } - - return true; - } - - /** - * @return ACore - */ - public function getObject(): ACore { - return $this->object; - } - - /** - * @param ACore $object - * - * @return ACore - */ - public function setObject(ACore $object): ACore { - $this->object = $object; - - return $this; - } - - - /** - * @return string - */ - public function getObjectId(): string { - return $this->objectId; - } - - /** - * @param string $objectId - * - * @return ACore - */ - public function setObjectId(string $objectId): ACore { - $this->objectId = $objectId; - - return $this; - } - - - /** - * @return bool - */ - public function gotIcon(): bool { - if ($this->icon === null) { - return false; - } - - return true; - } - - /** - * @return Document - */ - public function getIcon(): Document { - return $this->icon; - } - - /** - * @param Document $icon - * - * @return ACore - */ - public function setIcon(Document $icon): ACore { - $this->icon = $icon; - - return $this; - } - - - /** - * @return bool - */ - public function isLocal(): bool { - return $this->local; - } - - /** - * @param bool $local - * - * @return Person - */ - public function setLocal(bool $local): ACore { - $this->local = $local; - - return $this; - } - - - /** - * @param ACore $parent - * - * @return ACore - */ - public function setParent(ACore $parent): ACore { - $this->parent = $parent; - - return $this; - } - - /** - * @return ACore - */ - public function getParent(): ACore { - return $this->parent; - } - /** * @return bool */ @@ -856,58 +341,6 @@ abstract class ACore implements JsonSerializable { } - /** - * @param ICoreService $class - */ - public function saveAs(ICoreService $class) { - $this->saveAs = $class; - } - - /** - * @return ICoreService - */ - public function savingAs() { - return $this->saveAs; - } - - - /** - * @return bool - */ - public function isCompleteDetails(): bool { - return $this->completeDetails; - } - - /** - * @param bool $completeDetails - * - * @return ACore - */ - public function setCompleteDetails(bool $completeDetails): ACore { - $this->completeDetails = $completeDetails; - - return $this; - } - - - /** - * @return string - */ - public function getSource(): string { - return $this->source; - } - - /** - * @param string $source - * - * @return ACore - */ - public function setSource(string $source): ACore { - $this->source = $source; - - return $this; - } - /** * @param int $as * @param string $k @@ -917,13 +350,33 @@ abstract class ACore implements JsonSerializable { * @return string */ public function validate(int $as, string $k, array $arr, string $default = ''): string { - $value = $this->valideEntryString($as, $this->get($k, $arr, $default)); + $value = $this->validateEntryString($as, $this->get($k, $arr, $default)); return $value; } + /** + * @param int $as + * @param string $k + * @param array $arr + * @param array $default + * + * @return array + */ + public function validateArray(int $as, string $k, array $arr, array $default = []): array { + $values = $this->getArray($k, $arr, $default); + + $result = []; + foreach ($values as $value) { + $result[] = $this->validateEntryString($as, $value); + } + + return $result; + } + + /** * @param $as * @param $value @@ -961,26 +414,6 @@ abstract class ACore implements JsonSerializable { } - /** - * @param int $as - * @param string $k - * @param array $arr - * @param array $default - * - * @return array - */ - public function validateArray(int $as, string $k, array $arr, array $default = []): array { - $values = $this->getArray($k, $arr, $default); - - $result = []; - foreach ($values as $value) { - $result[] = $this->validateEntryString($as, $value); - } - - return $result; - } - - /** * @param array $data */ diff --git a/lib/Model/ActivityPub/Item.php b/lib/Model/ActivityPub/Item.php new file mode 100644 index 00000000..448ad37c --- /dev/null +++ b/lib/Model/ActivityPub/Item.php @@ -0,0 +1,603 @@ + + * @copyright 2018, Maxence Lange + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Social\Model\ActivityPub; + + +use OCA\Social\Model\InstancePath; + + +class Item { + + + /** @var string */ + private $urlSocial = ''; + + /** @var string */ + private $urlCloud = ''; + + /** @var string */ + private $address = ''; + + /** @var string */ + private $id = ''; + + /** @var string */ + private $type = ''; + + /** @var string */ + private $url = ''; + + /** @var string */ + private $summary = ''; + + /** @var InstancePath[] */ + private $instancePaths = []; + + /** @var string */ + private $to = ''; + + /** @var array */ + private $toArray = []; + + /** @var array */ + private $cc = []; + + /** @var array */ + private $bcc = []; + + /** @var string */ + private $published = ''; + + /** @var array */ + private $tags = []; + + /** @var Person */ + private $actor = null; + + /** @var string */ + private $actorId = ''; + + /** @var Document */ + private $icon = null; + + /** @var string */ + private $objectId = ''; + + /** @var bool */ + private $completeDetails = false; + + /** @var string */ + private $source = ''; + + /** @var bool */ + private $local = false; + + /** @var string */ + private $origin = ''; + + + /** + * @return string + */ + public function getId(): string { + return $this->id; + } + + /** + * @param string $id + * + * @return Item + */ + public function setId(string $id): Item { + $this->id = $id; + + return $this; + } + + + /** + * @return string + */ + public function getType(): string { + return $this->type; + } + + /** + * @param string $type + * + * @return Item + */ + public function setType(string $type): Item { +// if ($type !== '') { + $this->type = $type; + +// } + + return $this; + } + + + /** + * @return string + */ + public function getUrl(): string { + return $this->url; + } + + /** + * @param string $url + * + * @return Item + */ + public function setUrl(string $url): Item { + $this->url = $url; + + return $this; + } + + + /** + * @param InstancePath $instancePath + * + * @return Item + */ + public function addInstancePath(InstancePath $instancePath): Item { + if ($instancePath->getUri() !== '') { + $this->instancePaths[] = $instancePath; + } + + return $this; + } + + + /** + * @param InstancePath[] $path + * + * @return Item + */ + public function addInstancePaths(array $path): Item { + $this->instancePaths = array_merge($this->instancePaths, $path); + + return $this; + } + + /** + * @return InstancePath[] + */ + public function getInstancePaths(): array { + return $this->instancePaths; + } + + /** + * @param InstancePath[] $instancePaths + * + * @return Item + */ + public function setInstancePaths(array $instancePaths): Item { + $this->instancePaths = $instancePaths; + + return $this; + } + + + /** + * @return string + */ + public function getSummary(): string { + return $this->summary; + } + + /** + * @param string $summary + * + * @return Item + */ + public function setSummary(string $summary): Item { + $this->summary = $summary; + + return $this; + } + + + /** + * @return Person + */ + public function getActor(): Person { + return $this->actor; + } + + /** + * @param Person $actor + * + * @return Item + */ + public function setActor(Person $actor): Item { + $this->actor = $actor; + + return $this; + } + + /** + * @return bool + */ + public function gotActor(): bool { + if ($this->actor === null) { + return false; + } + + return true; + } + + + /** + * @param string $actorId + * + * @return Item + */ + public function setActorId(string $actorId): Item { + $this->actorId = $actorId; + + return $this; + } + + /** + * @return string + */ + public function getActorId(): string { + return $this->actorId; + } + + + /** + * @return string + */ + public function getUrlSocial(): string { + return $this->urlSocial; + } + + /** + * @param string $path + * + * @return Item + */ + public function setUrlSocial(string $path): Item { + $this->urlSocial = $path; + + return $this; + } + + + /** + * @return string + */ + public function getUrlCloud(): string { + return $this->urlCloud; + } + + /** + * @param string $path + * + * @return Item + */ + public function setUrlCloud(string $path): Item { + $this->urlCloud = $path; + + return $this; + } + + + /** + * @return string + */ + public function getAddress(): string { + return $this->address; + } + + /** + * @param string $address + * + * @return Item + */ + public function setAddress(string $address) { + $this->address = $address; + + return $this; + } + + + /** + * @return string + */ + public function getTo(): string { + return $this->to; + } + + /** + * @param string $to + * + * @return Item + */ + public function setTo(string $to): Item { + $this->to = $to; + + return $this; + } + + /** + * @return array + */ + public function getToArray(): array { + return $this->toArray; + } + + /** + * @param string $to + * + * @return Item + */ + public function addToArray(string $to): Item { + $this->toArray[] = $to; + + return $this; + } + + /** + * @param array $toArray + * + * @return Item + */ + public function setToArray(array $toArray): Item { + $this->toArray = $toArray; + + return $this; + } + + + public function addCc(string $cc): Item { + $this->cc[] = $cc; + + return $this; + } + + /** + * @return array + */ + public function getCcArray(): array { + return $this->cc; + } + + /** + * @param array $cc + * + * @return Item + */ + public function setCcArray(array $cc): Item { + $this->cc = $cc; + + return $this; + } + + + /** + * @return array + */ + public function getBccArray(): array { + return $this->bcc; + } + + /** + * @param array $bcc + * + * @return Item + */ + public function setBccArray(array $bcc): Item { + $this->bcc = $bcc; + + return $this; + } + + + /** + * @return string + */ + public function getOrigin(): string { + return $this->origin; + } + + /** + * @param string $origin + * + * @return Item + */ + public function setOrigin(string $origin): Item { + $this->origin = $origin; + + return $this; + } + + + /** + * @param string $published + * + * @return Item + */ + public function setPublished(string $published): Item { + $this->published = $published; + + return $this; + } + + /** + * @return string + */ + public function getPublished(): string { + return $this->published; + } + + + /** + * @param array $tag + * + * @return Item + */ + public function addTag(array $tag): Item { + $this->tags[] = $tag; + + return $this; + } + + /** + * @return array + */ + public function getTags(): array { + return $this->tags; + } + + /** + * @param array $tag + * + * @return Item + */ + public function setTags(array $tag): Item { + $this->tags = $tag; + + return $this; + } + + + /** + * @return string + */ + public function getObjectId(): string { + return $this->objectId; + } + + /** + * @param string $objectId + * + * @return Item + */ + public function setObjectId(string $objectId): Item { + $this->objectId = $objectId; + + return $this; + } + + + /** + * @return bool + */ + public function gotIcon(): bool { + if ($this->icon === null) { + return false; + } + + return true; + } + + /** + * @return Document + */ + public function getIcon(): Document { + return $this->icon; + } + + /** + * @param Document $icon + * + * @return Item + */ + public function setIcon(Document $icon): Item { + $this->icon = $icon; + + return $this; + } + + + /** + * @return bool + */ + public function isLocal(): bool { + return $this->local; + } + + /** + * @param bool $local + * + * @return Person + */ + public function setLocal(bool $local): Item { + $this->local = $local; + + return $this; + } + + + /** + * @return bool + */ + public function isCompleteDetails(): bool { + return $this->completeDetails; + } + + /** + * @param bool $completeDetails + * + * @return Item + */ + public function setCompleteDetails(bool $completeDetails): Item { + $this->completeDetails = $completeDetails; + + return $this; + } + + + /** + * @return string + */ + public function getSource(): string { + return $this->source; + } + + /** + * @param string $source + * + * @return Item + */ + public function setSource(string $source): Item { + $this->source = $source; + + return $this; + } + + +} + +