]> git.mxchange.org Git - friendica.git/commitdiff
Move Mastodon API factories to Factory\Api\Mastodon
authorHypolite Petovan <hypolite@mrpetovan.com>
Tue, 28 Jan 2020 12:33:37 +0000 (07:33 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Tue, 28 Jan 2020 12:33:55 +0000 (07:33 -0500)
src/DI.php
src/Factory/Api/Mastodon/Account.php [new file with mode: 0644]
src/Factory/Api/Mastodon/Emoji.php [new file with mode: 0644]
src/Factory/Api/Mastodon/FollowRequest.php [new file with mode: 0644]
src/Factory/Api/Mastodon/Relationship.php [new file with mode: 0644]
src/Factory/Mastodon/Account.php [deleted file]
src/Factory/Mastodon/FollowRequest.php [deleted file]
src/Factory/Mastodon/Relationship.php [deleted file]

index 6eb1ed4b633c17d73c2f67cef8495f5063cdd8c4..2c4163722ee1ff6e515bda17babdbcd8a9f0a36d 100644 (file)
@@ -141,7 +141,7 @@ abstract class DI
        }
 
        /**
-        * @return \Friendica\Core\PConfig\IPConfig
+        * @return Core\PConfig\IPConfig
         */
        public static function pConfig()
        {
@@ -221,31 +221,31 @@ abstract class DI
        //
 
        /**
-        * @return Factory\Mastodon\Account
+        * @return Factory\Api\Mastodon\Account
         */
        public static function mstdnAccount()
        {
-               return self::$dice->create(Factory\Mastodon\Account::class);
+               return self::$dice->create(Factory\Api\Mastodon\Account::class);
        }
 
        /**
-        * @return Factory\Mastodon\FollowRequest
+        * @return Factory\Api\Mastodon\FollowRequest
         */
        public static function mstdnFollowRequest()
        {
-               return self::$dice->create(Factory\Mastodon\FollowRequest::class);
+               return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class);
        }
 
        /**
-        * @return Factory\Mastodon\Relationship
+        * @return Factory\Api\Mastodon\Relationship
         */
        public static function mstdnRelationship()
        {
-               return self::$dice->create(Factory\Mastodon\Relationship::class);
+               return self::$dice->create(Factory\Api\Mastodon\Relationship::class);
        }
 
        /**
-        * @return \Friendica\Factory\Notification\Notification
+        * @return Factory\Notification\Notification
         */
        public static function notification()
        {
@@ -253,7 +253,7 @@ abstract class DI
        }
 
        /**
-        * @return \Friendica\Factory\Notification\Introduction
+        * @return Factory\Notification\Introduction
         */
        public static function notificationIntro()
        {
diff --git a/src/Factory/Api/Mastodon/Account.php b/src/Factory/Api/Mastodon/Account.php
new file mode 100644 (file)
index 0000000..60f9a76
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+namespace Friendica\Factory\Api\Mastodon;
+
+use Friendica\App\BaseURL;
+use Friendica\BaseFactory;
+use Friendica\Model\APContact;
+use Friendica\Model\Contact;
+use Friendica\Network\HTTPException;
+use Psr\Log\LoggerInterface;
+
+class Account extends BaseFactory
+{
+       /** @var BaseURL */
+       protected $baseUrl;
+
+       public function __construct(LoggerInterface $logger, BaseURL $baseURL)
+       {
+               parent::__construct($logger);
+
+               $this->baseUrl = $baseURL;
+       }
+
+       /**
+        * @param int $contactId
+        * @param int $uid        User Id
+        * @return \Friendica\Object\Api\Mastodon\Account
+        * @throws HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public function createFromContactId(int $contactId, $uid = 0)
+       {
+               $cdata = Contact::getPublicAndUserContacID($contactId, $uid);
+               if (!empty($cdata)) {
+                       $publicContact = Contact::getById($cdata['public']);
+                       $userContact = Contact::getById($cdata['user']);
+               } else {
+                       $publicContact = Contact::getById($contactId);
+                       $userContact = [];
+               }
+
+               $apcontact = APContact::getByURL($publicContact['url'], false);
+
+               return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $apcontact, $userContact);
+       }
+}
diff --git a/src/Factory/Api/Mastodon/Emoji.php b/src/Factory/Api/Mastodon/Emoji.php
new file mode 100644 (file)
index 0000000..770966a
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+namespace Friendica\Factory\Api\Mastodon;
+
+use Friendica\App\BaseURL;
+use Friendica\BaseFactory;
+use Friendica\Model\APContact;
+use Friendica\Model\Contact;
+use Friendica\Network\HTTPException;
+use Psr\Log\LoggerInterface;
+
+class Emoji extends BaseFactory
+{
+       /** @var BaseURL */
+       protected $baseUrl;
+
+       public function __construct(LoggerInterface $logger, BaseURL $baseURL)
+       {
+               parent::__construct($logger);
+
+               $this->baseUrl = $baseURL;
+       }
+
+       /**
+        * @param int $contactId
+        * @param int $uid        User Id
+        * @return \Friendica\Api\Entity\Mastodon\Account
+        * @throws HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public function createFromContactId(int $contactId, $uid = 0)
+       {
+               $cdata = Contact::getPublicAndUserContacID($contactId, $uid);
+               if (!empty($cdata)) {
+                       $publicContact = Contact::getById($cdata['public']);
+                       $userContact = Contact::getById($cdata['user']);
+               } else {
+                       $publicContact = Contact::getById($contactId);
+                       $userContact = [];
+               }
+
+               $apcontact = APContact::getByURL($publicContact['url'], false);
+
+               return new \Friendica\Api\Entity\Mastodon\Account($this->baseUrl, $publicContact, $apcontact, $userContact);
+       }
+}
diff --git a/src/Factory/Api/Mastodon/FollowRequest.php b/src/Factory/Api/Mastodon/FollowRequest.php
new file mode 100644 (file)
index 0000000..e012561
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+
+namespace Friendica\Factory\Api\Mastodon;
+
+use Friendica\App\BaseURL;
+use Friendica\BaseFactory;
+use Friendica\Model\APContact;
+use Friendica\Model\Contact;
+use Friendica\Model\Introduction;
+use Friendica\Network\HTTPException;
+use Psr\Log\LoggerInterface;
+
+class FollowRequest extends BaseFactory
+{
+       /** @var BaseURL */
+       protected $baseUrl;
+
+       public function __construct(LoggerInterface $logger, BaseURL $baseURL)
+       {
+               parent::__construct($logger);
+
+               $this->baseUrl = $baseURL;
+       }
+
+       /**
+        * @param Introduction $introduction
+        * @return \Friendica\Object\Api\Mastodon\FollowRequest
+        * @throws HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public function createFromIntroduction(Introduction $introduction)
+       {
+               $cdata = Contact::getPublicAndUserContacID($introduction->{'contact-id'}, $introduction->uid);
+
+               if (empty($cdata)) {
+                       $this->logger->warning('Wrong introduction data', ['Introduction' => $introduction]);
+                       throw new HTTPException\InternalServerErrorException('Wrong introduction data');
+               }
+
+               $publicContact = Contact::getById($cdata['public']);
+               $userContact = Contact::getById($cdata['user']);
+
+               $apcontact = APContact::getByURL($publicContact['url'], false);
+
+               return new \Friendica\Object\Api\Mastodon\FollowRequest($this->baseUrl, $introduction->id, $publicContact, $apcontact, $userContact);
+       }
+}
diff --git a/src/Factory/Api/Mastodon/Relationship.php b/src/Factory/Api/Mastodon/Relationship.php
new file mode 100644 (file)
index 0000000..121d57e
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+namespace Friendica\Factory\Api\Mastodon;
+
+use Friendica\Object\Api\Mastodon\Relationship as RelationshipEntity;
+use Friendica\BaseFactory;
+use Friendica\Model\Contact;
+
+class Relationship extends BaseFactory
+{
+       /**
+        * @param int $userContactId Contact row id with uid != 0
+        * @return RelationshipEntity
+        * @throws \Exception
+        */
+       public function createFromContactId(int $userContactId)
+       {
+               return $this->createFromContact(Contact::getById($userContactId));
+       }
+
+       /**
+        * @param array $userContact Full contact row record with uid != 0
+        * @return RelationshipEntity
+        */
+       public function createFromContact(array $userContact)
+       {
+               return new RelationshipEntity($userContact['id'], $userContact);
+       }
+
+       /**
+        * @param int $userContactId Contact row id with uid != 0
+        * @return RelationshipEntity
+        */
+       public function createDefaultFromContactId(int $userContactId)
+       {
+               return new RelationshipEntity($userContactId);
+       }
+}
diff --git a/src/Factory/Mastodon/Account.php b/src/Factory/Mastodon/Account.php
deleted file mode 100644 (file)
index e777e76..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-
-namespace Friendica\Factory\Mastodon;
-
-use Friendica\App\BaseURL;
-use Friendica\Model\APContact;
-use Friendica\Model\Contact;
-use Friendica\Network\HTTPException;
-use Friendica\BaseFactory;
-use Psr\Log\LoggerInterface;
-
-class Account extends BaseFactory
-{
-       /** @var BaseURL */
-       protected $baseUrl;
-
-       public function __construct(LoggerInterface $logger, BaseURL $baseURL)
-       {
-               parent::__construct($logger);
-
-               $this->baseUrl = $baseURL;
-       }
-
-       /**
-        * @param int $contactId
-        * @param int $uid        User Id
-        * @return \Friendica\Object\Api\Mastodon\Account
-        * @throws HTTPException\InternalServerErrorException
-        * @throws \ImagickException
-        */
-       public function createFromContactId(int $contactId, $uid = 0)
-       {
-               $cdata = Contact::getPublicAndUserContacID($contactId, $uid);
-               if (!empty($cdata)) {
-                       $publicContact = Contact::getById($cdata['public']);
-                       $userContact = Contact::getById($cdata['user']);
-               } else {
-                       $publicContact = Contact::getById($contactId);
-                       $userContact = [];
-               }
-
-               $apcontact = APContact::getByURL($publicContact['url'], false);
-
-               return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $apcontact, $userContact);
-       }
-}
diff --git a/src/Factory/Mastodon/FollowRequest.php b/src/Factory/Mastodon/FollowRequest.php
deleted file mode 100644 (file)
index 3aabe41..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-
-namespace Friendica\Factory\Mastodon;
-
-use Friendica\App\BaseURL;
-use Friendica\Model\APContact;
-use Friendica\Model\Contact;
-use Friendica\Model\Introduction;
-use Friendica\Network\HTTPException;
-use Friendica\BaseFactory;
-use Psr\Log\LoggerInterface;
-
-class FollowRequest extends BaseFactory
-{
-       /** @var BaseURL */
-       protected $baseUrl;
-
-       public function __construct(LoggerInterface $logger, BaseURL $baseURL)
-       {
-               parent::__construct($logger);
-
-               $this->baseUrl = $baseURL;
-       }
-
-       /**
-        * @param Introduction $introduction
-        * @return \Friendica\Object\Api\Mastodon\FollowRequest
-        * @throws HTTPException\InternalServerErrorException
-        * @throws \ImagickException
-        */
-       public function createFromIntroduction(Introduction $introduction)
-       {
-               $cdata = Contact::getPublicAndUserContacID($introduction->{'contact-id'}, $introduction->uid);
-
-               if (empty($cdata)) {
-                       $this->logger->warning('Wrong introduction data', ['Introduction' => $introduction]);
-                       throw new HTTPException\InternalServerErrorException('Wrong introduction data');
-               }
-
-               $publicContact = Contact::getById($cdata['public']);
-               $userContact = Contact::getById($cdata['user']);
-
-               $apcontact = APContact::getByURL($publicContact['url'], false);
-
-               return new \Friendica\Object\Api\Mastodon\FollowRequest($this->baseUrl, $introduction->id, $publicContact, $apcontact, $userContact);
-       }
-}
diff --git a/src/Factory/Mastodon/Relationship.php b/src/Factory/Mastodon/Relationship.php
deleted file mode 100644 (file)
index 7a8b216..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-
-namespace Friendica\Factory\Mastodon;
-
-use Friendica\Object\Api\Mastodon\Relationship as RelationshipEntity;
-use Friendica\BaseFactory;
-use Friendica\Model\Contact;
-
-class Relationship extends BaseFactory
-{
-       /**
-        * @param int $userContactId Contact row id with uid != 0
-        * @return RelationshipEntity
-        * @throws \Exception
-        */
-       public function createFromContactId(int $userContactId)
-       {
-               return $this->createFromContact(Contact::getById($userContactId));
-       }
-
-       /**
-        * @param array $userContact Full contact row record with uid != 0
-        * @return RelationshipEntity
-        */
-       public function createFromContact(array $userContact)
-       {
-               return new RelationshipEntity($userContact['id'], $userContact);
-       }
-
-       /**
-        * @param int $userContactId Contact row id with uid != 0
-        * @return RelationshipEntity
-        */
-       public function createDefaultFromContactId(int $userContactId)
-       {
-               return new RelationshipEntity($userContactId);
-       }
-}