]> git.mxchange.org Git - friendica.git/blob - src/Factory/Mastodon/FollowRequest.php
Merge pull request #8179 from MrPetovan/bug/notices
[friendica.git] / src / Factory / Mastodon / FollowRequest.php
1 <?php
2
3 namespace Friendica\Factory\Mastodon;
4
5 use Friendica\App\BaseURL;
6 use Friendica\Model\APContact;
7 use Friendica\Model\Contact;
8 use Friendica\Model\Introduction;
9 use Friendica\Network\HTTPException;
10 use Friendica\BaseFactory;
11 use Psr\Log\LoggerInterface;
12
13 class FollowRequest extends BaseFactory
14 {
15         /** @var BaseURL */
16         protected $baseUrl;
17
18         public function __construct(LoggerInterface $logger, BaseURL $baseURL)
19         {
20                 parent::__construct($logger);
21
22                 $this->baseUrl = $baseURL;
23         }
24
25         /**
26          * @param Introduction $introduction
27          * @return \Friendica\Api\Entity\Mastodon\FollowRequest
28          * @throws HTTPException\InternalServerErrorException
29          * @throws \ImagickException
30          */
31         public function createFromIntroduction(Introduction $introduction)
32         {
33                 $cdata = Contact::getPublicAndUserContacID($introduction->{'contact-id'}, $introduction->uid);
34
35                 if (empty($cdata)) {
36                         $this->logger->warning('Wrong introduction data', ['Introduction' => $introduction]);
37                         throw new HTTPException\InternalServerErrorException('Wrong introduction data');
38                 }
39
40                 $publicContact = Contact::getById($cdata['public']);
41                 $userContact = Contact::getById($cdata['user']);
42
43                 $apcontact = APContact::getByURL($publicContact['url'], false);
44
45                 return new \Friendica\Api\Entity\Mastodon\FollowRequest($this->baseUrl, $introduction->id, $publicContact, $apcontact, $userContact);
46         }
47 }