mirror of
https://github.com/friendica/friendica
synced 2024-12-22 19:20:17 +00:00
Fix errors in Factory namespace
This commit is contained in:
parent
1fe730f514
commit
06e3051ad1
10 changed files with 71 additions and 56 deletions
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Friendica;
|
||||
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
|
||||
/**
|
||||
* The Entity classes directly inheriting from this abstract class are meant to represent a single business entity.
|
||||
|
@ -23,18 +23,29 @@ use Friendica\Network\HTTPException;
|
|||
*
|
||||
* Since these objects aren't meant to be using any dependency, including logging, unit tests can and must be
|
||||
* written for each and all of their methods
|
||||
*
|
||||
* @property-read int $id
|
||||
* @property-read int $uid
|
||||
* @property-read string $verb
|
||||
* @property-read int $type
|
||||
* @property-read int $actorId
|
||||
* @property-read int $targetUriId
|
||||
* @property-read int $parentUriId
|
||||
* @property-read \DateTime $created
|
||||
* @property-read bool $seen
|
||||
* @property-read bool $dismissed
|
||||
*/
|
||||
abstract class BaseEntity extends BaseDataTransferObject
|
||||
{
|
||||
/**
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function __get(string $name)
|
||||
{
|
||||
if (!property_exists($this, $name)) {
|
||||
throw new HTTPException\InternalServerErrorException('Unknown property ' . $name . ' in Entity ' . static::class);
|
||||
throw new InternalServerErrorException('Unknown property ' . $name . ' in Entity ' . static::class);
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
|
@ -43,12 +54,12 @@ abstract class BaseEntity extends BaseDataTransferObject
|
|||
/**
|
||||
* @param mixed $name
|
||||
* @return bool
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function __isset($name): bool
|
||||
{
|
||||
if (!property_exists($this, $name)) {
|
||||
throw new HTTPException\InternalServerErrorException('Unknown property ' . $name . ' of type ' . gettype($name) . ' in Entity ' . static::class);
|
||||
throw new InternalServerErrorException('Unknown property ' . $name . ' of type ' . gettype($name) . ' in Entity ' . static::class);
|
||||
}
|
||||
|
||||
return !empty($this->$name);
|
||||
|
|
|
@ -525,7 +525,7 @@ abstract class DI
|
|||
//
|
||||
|
||||
/**
|
||||
* @return Contact\FriendSuggest\Repository\FriendSuggest;
|
||||
* @return Contact\FriendSuggest\Repository\FriendSuggest
|
||||
*/
|
||||
public static function fsuggest()
|
||||
{
|
||||
|
@ -533,7 +533,7 @@ abstract class DI
|
|||
}
|
||||
|
||||
/**
|
||||
* @return Contact\FriendSuggest\Factory\FriendSuggest;
|
||||
* @return Contact\FriendSuggest\Factory\FriendSuggest
|
||||
*/
|
||||
public static function fsuggestFactory()
|
||||
{
|
||||
|
|
|
@ -8,10 +8,8 @@
|
|||
namespace Friendica\Factory\Api\Mastodon;
|
||||
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
class Card extends BaseFactory
|
||||
{
|
||||
|
@ -21,7 +19,8 @@ class Card extends BaseFactory
|
|||
*
|
||||
* @return \Friendica\Object\Api\Mastodon\Card
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException*@throws \Exception
|
||||
* @throws \ImagickException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createFromUriId(int $uriId, array $history = []): \Friendica\Object\Api\Mastodon\Card
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Friendica\Factory\Api\Mastodon;
|
|||
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Navigation\Notifications;
|
||||
use Friendica\Navigation\Notifications\Entity\Notification as NotificationEntity;
|
||||
use Friendica\Navigation\Notifications\Exception\UnexpectedNotificationTypeException;
|
||||
use Friendica\Object\Api\Mastodon\Notification as MstdnNotification;
|
||||
use Friendica\Protocol\Activity;
|
||||
|
@ -32,16 +32,17 @@ class Notification extends BaseFactory
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Notifications\Entity\Notification $Notification
|
||||
* @param bool $display_quote Display quoted posts
|
||||
* @param NotificationEntity $Notification
|
||||
* @param bool $display_quotes Display quoted posts
|
||||
*
|
||||
* @return MstdnNotification
|
||||
* @throws UnexpectedNotificationTypeException
|
||||
*/
|
||||
public function createFromNotification(Notifications\Entity\Notification $Notification, bool $display_quotes): MstdnNotification
|
||||
public function createFromNotification(NotificationEntity $Notification, bool $display_quotes): MstdnNotification
|
||||
{
|
||||
$type = self::getType($Notification);
|
||||
if (empty($type)) {
|
||||
|
||||
if ($type === '') {
|
||||
throw new UnexpectedNotificationTypeException();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,8 @@ use Friendica\DI;
|
|||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Model\Verb;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Object\Api\Mastodon\Status\FriendicaDeliveryData;
|
||||
use Friendica\Object\Api\Mastodon\Status\FriendicaExtension;
|
||||
use Friendica\Object\Api\Mastodon\Status\FriendicaVisibility;
|
||||
|
@ -87,8 +88,8 @@ class Status extends BaseFactory
|
|||
* @param bool $in_reply_status Add an "in_reply_status" element
|
||||
*
|
||||
* @return \Friendica\Object\Api\Mastodon\Status
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws ImagickException|HTTPException\NotFoundException
|
||||
* @throws InternalServerErrorException
|
||||
* @throws ImagickException|NotFoundException
|
||||
*/
|
||||
public function createFromUriId(int $uriId, int $uid = 0, bool $display_quote = false, bool $reblog = true, bool $in_reply_status = true): \Friendica\Object\Api\Mastodon\Status
|
||||
{
|
||||
|
@ -101,7 +102,7 @@ class Status extends BaseFactory
|
|||
if ($mail) {
|
||||
return $this->createFromMailId($mail['id']);
|
||||
}
|
||||
throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
|
||||
throw new NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
|
||||
}
|
||||
|
||||
$activity_fields = ['uri-id', 'thr-parent-id', 'uri', 'author-id', 'author-uri-id', 'author-link', 'app', 'created', 'network', 'parent-author-id', 'private'];
|
||||
|
@ -113,7 +114,7 @@ class Status extends BaseFactory
|
|||
$activity = $item;
|
||||
$item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
|
||||
if (!$item) {
|
||||
throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
|
||||
throw new NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
|
||||
}
|
||||
foreach ($activity_fields as $field) {
|
||||
$item[$field] = $activity[$field];
|
||||
|
@ -370,17 +371,17 @@ class Status extends BaseFactory
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int $uriId id of the mail
|
||||
* @param int $id id of the mail
|
||||
*
|
||||
* @return \Friendica\Object\Api\Mastodon\Status
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws ImagickException|HTTPException\NotFoundException
|
||||
* @throws InternalServerErrorException
|
||||
* @throws ImagickException|NotFoundException
|
||||
*/
|
||||
public function createFromMailId(int $id): \Friendica\Object\Api\Mastodon\Status
|
||||
{
|
||||
$item = ActivityPub\Transmitter::getItemArrayFromMail($id, true);
|
||||
if (empty($item)) {
|
||||
throw new HTTPException\NotFoundException('Mail record not found with id: ' . $id);
|
||||
throw new NotFoundException('Mail record not found with id: ' . $id);
|
||||
}
|
||||
|
||||
$account = $this->mstdnAccountFactory->createFromContactId($item['author-id']);
|
||||
|
|
|
@ -20,7 +20,8 @@ class StatusSource extends BaseFactory
|
|||
*
|
||||
* @return \Friendica\Object\Api\Mastodon\StatusSource
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException*@throws \Exception
|
||||
* @throws \ImagickException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createFromUriId(int $uriId, int $uid): \Friendica\Object\Api\Mastodon\StatusSource
|
||||
{
|
||||
|
|
|
@ -10,18 +10,17 @@ namespace Friendica\Factory\Api\Mastodon;
|
|||
use Friendica\BaseFactory;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Subscription as ModelSubscription;
|
||||
use Friendica\Object\Api\Mastodon\Subscription as SubscriptionObject;
|
||||
|
||||
class Subscription extends BaseFactory
|
||||
{
|
||||
/**
|
||||
* @param int $applicationid Application Id
|
||||
* @param int $uid Item user
|
||||
*
|
||||
* @return \Friendica\Object\Api\Mastodon\Status
|
||||
*/
|
||||
public function createForApplicationIdAndUserId(int $applicationid, int $uid): \Friendica\Object\Api\Mastodon\Subscription
|
||||
public function createForApplicationIdAndUserId(int $applicationid, int $uid): SubscriptionObject
|
||||
{
|
||||
$subscription = DBA::selectFirst('subscription', [], ['application-id' => $applicationid, 'uid' => $uid]);
|
||||
return new \Friendica\Object\Api\Mastodon\Subscription($subscription, ModelSubscription::getPublicVapidKey());
|
||||
return new SubscriptionObject($subscription, ModelSubscription::getPublicVapidKey());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,8 @@ use Friendica\Factory\Api\Twitter\User as TwitterUser;
|
|||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Model\Verb;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Protocol\Activity;
|
||||
use ImagickException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
@ -58,13 +59,13 @@ class Status extends BaseFactory
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int $uriId Uri-ID of the item
|
||||
* @param int $id Uri-ID of the item
|
||||
* @param int $uid Item user
|
||||
* @param bool $include_entities Whether to include entities
|
||||
*
|
||||
* @return \Friendica\Object\Api\Twitter\Status
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws ImagickException|HTTPException\NotFoundException
|
||||
* @throws InternalServerErrorException
|
||||
* @throws ImagickException|NotFoundException
|
||||
*/
|
||||
public function createFromItemId(int $id, int $uid, bool $include_entities = false): \Friendica\Object\Api\Twitter\Status
|
||||
{
|
||||
|
@ -73,7 +74,7 @@ class Status extends BaseFactory
|
|||
'thr-parent-id', 'parent-author-id', 'parent-author-nick', 'uri', 'plink', 'private', 'vid', 'coord', 'quote-uri-id'];
|
||||
$item = Post::selectFirst($fields, ['id' => $id], ['order' => ['uid' => true]]);
|
||||
if (!$item) {
|
||||
throw new HTTPException\NotFoundException('Item with ID ' . $id . ' not found.');
|
||||
throw new NotFoundException('Item with ID ' . $id . ' not found.');
|
||||
}
|
||||
return $this->createFromArray($item, $uid, $include_entities);
|
||||
}
|
||||
|
@ -84,8 +85,8 @@ class Status extends BaseFactory
|
|||
* @param bool $include_entities Whether to include entities
|
||||
*
|
||||
* @return \Friendica\Object\Api\Twitter\Status
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws ImagickException|HTTPException\NotFoundException
|
||||
* @throws InternalServerErrorException
|
||||
* @throws ImagickException|NotFoundException
|
||||
*/
|
||||
public function createFromUriId(int $uriId, int $uid = 0, bool $include_entities = false): \Friendica\Object\Api\Twitter\Status
|
||||
{
|
||||
|
@ -94,7 +95,7 @@ class Status extends BaseFactory
|
|||
'thr-parent-id', 'parent-author-id', 'parent-author-nick', 'uri', 'plink', 'private', 'vid', 'coord'];
|
||||
$item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
|
||||
if (!$item) {
|
||||
throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
|
||||
throw new NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
|
||||
}
|
||||
return $this->createFromArray($item, $uid, $include_entities);
|
||||
}
|
||||
|
@ -105,8 +106,8 @@ class Status extends BaseFactory
|
|||
* @param bool $include_entities Whether to include entities
|
||||
*
|
||||
* @return \Friendica\Object\Api\Twitter\Status
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws ImagickException|HTTPException\NotFoundException
|
||||
* @throws InternalServerErrorException
|
||||
* @throws ImagickException|NotFoundException
|
||||
*/
|
||||
private function createFromArray(array $item, int $uid, bool $include_entities): \Friendica\Object\Api\Twitter\Status
|
||||
{
|
||||
|
@ -161,8 +162,8 @@ class Status extends BaseFactory
|
|||
if ($include_entities) {
|
||||
$hashtags = $this->hashtag->createFromUriId($item['uri-id'], $text);
|
||||
$medias = $this->media->createFromUriId($item['uri-id'], $text);
|
||||
$urls = $this->url->createFromUriId($item['uri-id'], $text);
|
||||
$mentions = $this->mention->createFromUriId($item['uri-id'], $text);
|
||||
$urls = $this->url->createFromUriId($item['uri-id']);
|
||||
$mentions = $this->mention->createFromUriId($item['uri-id']);
|
||||
} else {
|
||||
$attachments = $this->attachment->createFromUriId($item['uri-id'], $text);
|
||||
}
|
||||
|
@ -176,8 +177,8 @@ class Status extends BaseFactory
|
|||
if ($include_entities) {
|
||||
$hashtags = array_merge($hashtags, $this->hashtag->createFromUriId($shared_uri_id, $text));
|
||||
$medias = array_merge($medias, $this->media->createFromUriId($shared_uri_id, $text));
|
||||
$urls = array_merge($urls, $this->url->createFromUriId($shared_uri_id, $text));
|
||||
$mentions = array_merge($mentions, $this->mention->createFromUriId($shared_uri_id, $text));
|
||||
$urls = array_merge($urls, $this->url->createFromUriId($shared_uri_id));
|
||||
$mentions = array_merge($mentions, $this->mention->createFromUriId($shared_uri_id));
|
||||
} else {
|
||||
$attachments = array_merge($attachments, $this->attachment->createFromUriId($shared_uri_id, $text));
|
||||
}
|
||||
|
|
|
@ -11,16 +11,16 @@ use DateTime;
|
|||
use Friendica\BaseEntity;
|
||||
|
||||
/**
|
||||
* @property-read $id
|
||||
* @property-read $uid
|
||||
* @property-read $verb
|
||||
* @property-read $type
|
||||
* @property-read $actorId
|
||||
* @property-read $targetUriId
|
||||
* @property-read $parentUriId
|
||||
* @property-read $created
|
||||
* @property-read $seen
|
||||
* @property-read $dismissed
|
||||
* @property-read int $id
|
||||
* @property-read int $uid
|
||||
* @property-read string $verb
|
||||
* @property-read int $type
|
||||
* @property-read int $actorId
|
||||
* @property-read int $targetUriId
|
||||
* @property-read int $parentUriId
|
||||
* @property-read DateTime $created
|
||||
* @property-read bool $seen
|
||||
* @property-read bool $dismissed
|
||||
*/
|
||||
class Notification extends BaseEntity
|
||||
{
|
||||
|
@ -31,7 +31,7 @@ class Notification extends BaseEntity
|
|||
/** @var string */
|
||||
protected $verb;
|
||||
/**
|
||||
* @var int One of the \Friendica\Model\Post\UserNotification::TYPE_* constant values
|
||||
* @var int $type One of the \Friendica\Model\Post\UserNotification::TYPE_* constant values
|
||||
* @see \Friendica\Model\Post\UserNotification
|
||||
*/
|
||||
protected $type;
|
||||
|
|
|
@ -11,6 +11,8 @@ namespace Friendica\Object\Api\Mastodon\Status;
|
|||
* Class Counts
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/entities/status
|
||||
*
|
||||
* @property-read int $dislikes
|
||||
*/
|
||||
class Counts
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue