]> git.mxchange.org Git - friendica.git/commitdiff
"DI" calls are replaced
authorMichael <heluecht@pirati.ca>
Sun, 16 Jan 2022 07:07:46 +0000 (07:07 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 16 Jan 2022 07:07:46 +0000 (07:07 +0000)
src/DI.php
src/Factory/Api/Friendica/Activities.php
src/Module/Api/Friendica/Photo.php
src/Module/Api/Friendica/Photo/Create.php
src/Module/Api/Friendica/Photo/Lists.php
src/Module/Api/Friendica/Photo/Update.php
src/Module/Api/Twitter/Lists/Create.php
src/Module/Api/Twitter/Lists/Destroy.php
src/Module/Api/Twitter/Lists/Ownership.php
src/Module/Api/Twitter/Lists/Statuses.php
src/Module/Api/Twitter/Lists/Update.php

index 992e2c649d515a017cddf4411d4e54df3ebe8b0f..708fb7d836da3fe54a7c72bc40d81c4ce1a19a3b 100644 (file)
@@ -262,30 +262,6 @@ abstract class DI
        // "Factory" namespace instances
        //
 
-       /**
-        * @return Factory\Api\Friendica\Activities
-        */
-       public static function friendicaActivities()
-       {
-               return self::$dice->create(Factory\Api\Friendica\Activities::class);
-       }
-
-       /**
-        * @return Factory\Api\Friendica\Group
-        */
-       public static function friendicaGroup()
-       {
-               return self::$dice->create(Factory\Api\Friendica\Group::class);
-       }
-
-       /**
-        * @return Factory\Api\Friendica\Photo
-        */
-       public static function friendicaPhoto()
-       {
-               return self::$dice->create(Factory\Api\Friendica\Photo::class);
-       }
-
        /**
         * @return Factory\Api\Mastodon\Account
         */
index b4936f31079257d418bedfc0b70c399b19ba349c..7b8f458b048268787b8b5863c3205182d3f7e757 100644 (file)
@@ -21,7 +21,6 @@
 
 namespace Friendica\Factory\Api\Friendica;
 
-use Friendica\App\BaseURL;
 use Friendica\BaseFactory;
 use Friendica\Database\DBA;
 use Friendica\Model\Post;
@@ -32,17 +31,14 @@ use Friendica\Factory\Api\Twitter\User as TwitterUser;
 
 class Activities extends BaseFactory
 {
-       /** @var BaseURL */
-       private $baseUrl;
        /** @var twitterUser entity */
        private $twitterUser;
 
-       public function __construct(LoggerInterface $logger, BaseURL $baseURL, TwitterUser $twitteruser)
+       public function __construct(LoggerInterface $logger, TwitterUser $twitteruser)
        {
                parent::__construct($logger);
 
                $this->twitterUser = $twitteruser;
-               $this->baseUrl     = $baseURL;
        }
 
        /**
index 5c2f46fc2278b91eb6742c1a0eccd0608ea6196a..4334bafebed88bb8c79fcf24482021b0a75a4f19 100644 (file)
 
 namespace Friendica\Module\Api\Friendica;
 
-use Friendica\DI;
-use Friendica\Model\Contact;
+use Friendica\App;
+use Friendica\Core\L10n;
+use Friendica\Factory\Api\Friendica\Photo as FriendicaPhoto;
 use Friendica\Module\BaseApi;
+use Friendica\Model\Contact;
+use Friendica\Module\Api\ApiResponse;
 use Friendica\Network\HTTPException;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
 
 class Photo extends BaseApi
 {
+       /** @var FriendicaPhoto */
+       private $friendicaPhoto;
+
+
+       public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
+       {
+               parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->friendicaPhoto = $friendicaPhoto;
+       }
+
        protected function post(array $request = [])
        {
                BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
@@ -42,7 +58,7 @@ class Photo extends BaseApi
                $photo_id = $_REQUEST['photo_id'];
 
                // prepare json/xml output with data from database for the requested photo
-               $data = ['photo' => DI::friendicaPhoto()->createFromId($photo_id, $scale, $uid, $type)];
+               $data = ['photo' => $this->friendicaPhoto->createFromId($photo_id, $scale, $uid, $type)];
 
                $this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
        }
index 8da6acbf4ebd5422dafec4fc031a297dadf2fd15..0455321d0834aa780f0e23871c3f43e7a51b9964 100644 (file)
 
 namespace Friendica\Module\Api\Friendica\Photo;
 
+use Friendica\App;
 use Friendica\Core\ACL;
-use Friendica\DI;
-use Friendica\Model\Photo;
+use Friendica\Core\L10n;
+use Friendica\Factory\Api\Friendica\Photo as FriendicaPhoto;
 use Friendica\Module\BaseApi;
+use Friendica\Model\Photo;
+use Friendica\Module\Api\ApiResponse;
 use Friendica\Network\HTTPException;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
 
 /**
  * API endpoint: /api/friendica/photo/create
  */
 class Create extends BaseApi
 {
+       /** @var FriendicaPhoto */
+       private $friendicaPhoto;
+
+
+       public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
+       {
+               parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->friendicaPhoto = $friendicaPhoto;
+       }
+
        protected function post(array $request = [])
        {
                BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
@@ -72,7 +88,7 @@ class Create extends BaseApi
 
                // return success of updating or error message
                if (!empty($photo)) {
-                       $data = ['photo' => DI::friendicaPhoto()->createFromId($photo['resource_id'], null, $uid, $type)];
+                       $data = ['photo' => $this->friendicaPhoto->createFromId($photo['resource_id'], null, $uid, $type)];
                        $this->response->exit('photo_create', $data, $this->parameters['extension'] ?? null);
                        return;
                } else {
index d7080b442853410e37f572193c079883603fe37e..6d2eb1716c764c300cc7c2454abb014016a85859 100644 (file)
 namespace Friendica\Module\Api\Friendica\Photo;
 
 use Friendica\Database\DBA;
-use Friendica\DI;
+use Friendica\App;
+use Friendica\Core\L10n;
+use Friendica\Factory\Api\Friendica\Photo as FriendicaPhoto;
 use Friendica\Module\BaseApi;
 use Friendica\Model\Contact;
 use Friendica\Model\Photo;
+use Friendica\Module\Api\ApiResponse;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
 
 /**
  * Returns all lists the user subscribes to.
@@ -34,6 +39,17 @@ use Friendica\Model\Photo;
  */
 class Lists extends BaseApi
 {
+       /** @var FriendicaPhoto */
+       private $friendicaPhoto;
+
+
+       public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
+       {
+               parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->friendicaPhoto = $friendicaPhoto;
+       }
+
        protected function rawContent(array $request = [])
        {
                BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
@@ -46,7 +62,7 @@ class Lists extends BaseApi
                $data = ['photo' => []];
                if (DBA::isResult($photos)) {
                        foreach ($photos as $photo) {
-                               $element = DI::friendicaPhoto()->createFromId($photo['resource-id'], null, $uid, 'json', false);
+                               $element = $this->friendicaPhoto->createFromId($photo['resource-id'], null, $uid, 'json', false);
 
                                $element['thumb'] = end($element['link']);
                                unset($element['link']);
index c4bd6c70bf3cb112abed70435025e12605e82611..b964ad0230cb51345f569792be767a72034795db 100644 (file)
 
 namespace Friendica\Module\Api\Friendica\Photo;
 
+use Friendica\App;
 use Friendica\Core\ACL;
-use Friendica\DI;
-use Friendica\Model\Photo;
+use Friendica\Core\L10n;
+use Friendica\Factory\Api\Friendica\Photo as FriendicaPhoto;
 use Friendica\Module\BaseApi;
+use Friendica\Model\Photo;
+use Friendica\Module\Api\ApiResponse;
 use Friendica\Network\HTTPException;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
 
 /**
  * API endpoint: /api/friendica/photo/update
  */
 class Update extends BaseApi
 {
+       /** @var FriendicaPhoto */
+       private $friendicaPhoto;
+
+
+       public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
+       {
+               parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->friendicaPhoto = $friendicaPhoto;
+       }
+
        protected function post(array $request = [])
        {
                BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
@@ -111,7 +127,7 @@ class Update extends BaseApi
                        $nothingtodo = false;
                        $photo = Photo::upload($uid, $_FILES['media'], $album, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc, $photo_id);
                        if (!empty($photo)) {
-                               $data = ['photo' => DI::friendicaPhoto()->createFromId($photo['resource_id'], null, $uid, $type)];
+                               $data = ['photo' => $this->friendicaPhoto->createFromId($photo['resource_id'], null, $uid, $type)];
                                $this->response->exit('photo_update', $data, $this->parameters['extension'] ?? null);
                                return;
                        }
index f39d7bbfcb71253a692d6f84af01865df28b5196..746f71d0f38d7e97474e2e6db7d1e53dffcc4e4c 100644 (file)
 
 namespace Friendica\Module\Api\Twitter\Lists;
 
-use Friendica\Database\DBA;
-use Friendica\DI;
+use Friendica\App;
+use Friendica\Core\L10n;
+use Friendica\Database\Database;
+use Friendica\Factory\Api\Friendica\Group as FriendicaGroup;
 use Friendica\Module\BaseApi;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
+use Friendica\Module\Api\ApiResponse;
 use Friendica\Network\HTTPException;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
 
 /**
  * Update information about a group.
@@ -35,6 +40,20 @@ use Friendica\Network\HTTPException;
  */
 class Create extends BaseApi
 {
+       /** @var friendicaGroup */
+       private $friendicaGroup;
+
+       /** @var Database */
+       private $dba;
+
+       public function __construct(Database $dba, FriendicaGroup $friendicaGroup, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
+       {
+               parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->dba = $dba;
+               $this->friendicaGroup = $friendicaGroup;
+       }
+       
        protected function rawContent(array $request = [])
        {
                BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
@@ -48,7 +67,7 @@ class Create extends BaseApi
                }
        
                // error message if specified group name already exists
-               if (DBA::exists('group', ['uid' => $uid, 'name' => $name, 'deleted' => false])) {
+               if ($this->dba->exists('group', ['uid' => $uid, 'name' => $name, 'deleted' => false])) {
                        throw new HTTPException\BadRequestException('group name already exists');
                }
        
@@ -59,7 +78,7 @@ class Create extends BaseApi
                        throw new HTTPException\BadRequestException('other API error');
                }
        
-               $grp = DI::friendicaGroup()->createFromId($gid);
+               $grp = $this->friendicaGroup->createFromId($gid);
        
                $this->response->exit('statuses', ['lists' => ['lists' => $grp]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
        }
index 8e84cb8d4a9f2b5aabcdc2e48b5cca2c75b76a91..ee2ac2d3cbd139fb83c0fd69841a85d5f0edc733 100644 (file)
 
 namespace Friendica\Module\Api\Twitter\Lists;
 
-use Friendica\Database\DBA;
-use Friendica\DI;
+use Friendica\App;
+use Friendica\Core\L10n;
+use Friendica\Database\Database;
+use Friendica\Factory\Api\Friendica\Group as FriendicaGroup;
 use Friendica\Module\BaseApi;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
+use Friendica\Module\Api\ApiResponse;
 use Friendica\Network\HTTPException;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
 
 /**
  * Delete a group.
@@ -35,6 +40,20 @@ use Friendica\Network\HTTPException;
  */
 class Destroy extends BaseApi
 {
+       /** @var friendicaGroup */
+       private $friendicaGroup;
+
+       /** @var Database */
+       private $dba;
+
+       public function __construct(Database $dba, FriendicaGroup $friendicaGroup, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
+       {
+               parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->dba = $dba;
+               $this->friendicaGroup = $friendicaGroup;
+       }
+       
        protected function rawContent(array $request = [])
        {
                BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
@@ -49,13 +68,13 @@ class Destroy extends BaseApi
                }
        
                // get data of the specified group id
-               $group = DBA::selectFirst('group', [], ['uid' => $uid, 'id' => $gid]);
+               $group = $this->dba->selectFirst('group', [], ['uid' => $uid, 'id' => $gid]);
                // error message if specified gid is not in database
                if (!$group) {
                        throw new HTTPException\BadRequestException('gid not available');
                }
        
-               $list = DI::friendicaGroup()->createFromId($gid);
+               $list = $this->friendicaGroup->createFromId($gid);
        
                if (Group::remove($gid)) {
                        $this->response->exit('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
index 57aa2855f250f9ba103676c1e15126ca3909b8c0..436097970d4c37c4924593d5d7c1efde9bc6c2b3 100644 (file)
 
 namespace Friendica\Module\Api\Twitter\Lists;
 
-use Friendica\Database\DBA;
-use Friendica\DI;
+use Friendica\App;
+use Friendica\Core\L10n;
+use Friendica\Database\Database;
+use Friendica\Factory\Api\Friendica\Group as FriendicaGroup;
 use Friendica\Module\BaseApi;
 use Friendica\Model\Contact;
+use Friendica\Module\Api\ApiResponse;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
 
 /**
  * Returns all groups the user owns.
@@ -33,17 +38,30 @@ use Friendica\Model\Contact;
  */
 class Ownership extends BaseApi
 {
+       /** @var friendicaGroup */
+       private $friendicaGroup;
+
+       /** @var Database */
+       private $dba;
+
+       public function __construct(Database $dba, FriendicaGroup $friendicaGroup, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
+       {
+               parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->dba = $dba;
+               $this->friendicaGroup = $friendicaGroup;
+       }
        protected function rawContent(array $request = [])
        {
                BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
                $uid = BaseApi::getCurrentUserID();
        
-               $groups = DBA::select('group', [], ['deleted' => false, 'uid' => $uid]);
+               $groups = $this->dba->select('group', [], ['deleted' => false, 'uid' => $uid]);
        
                // loop through all groups
                $lists = [];
                foreach ($groups as $group) {
-                       $lists[] = DI::friendicaGroup()->createFromId($group['id']);
+                       $lists[] = $this->friendicaGroup->createFromId($group['id']);
                }
 
                $this->response->exit('statuses', ['lists' => ['lists' => $lists]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
index 34220fe993bfd14e0e9198beef8065d86ef61703..257d6bc5138cf4b4d5bce930d46c3384a650f165 100644 (file)
 
 namespace Friendica\Module\Api\Twitter\Lists;
 
+use Friendica\App;
+use Friendica\Core\L10n;
+use Friendica\Database\Database;
 use Friendica\Database\DBA;
+use Friendica\Factory\Api\Twitter\Status as TwitterStatus;
 use Friendica\Module\BaseApi;
-use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Post;
-use Friendica\Network\HTTPException\BadRequestException;
+use Friendica\Module\Api\ApiResponse;
+use Friendica\Network\HTTPException;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
 
 /**
  * Returns recent statuses from users in the specified group.
@@ -35,13 +41,27 @@ use Friendica\Network\HTTPException\BadRequestException;
  */
 class Statuses extends BaseApi
 {
+       /** @var TwitterStatus */
+       private $twitterStatus;
+
+       /** @var Database */
+       private $dba;
+
+       public function __construct(Database $dba, TwitterStatus $twitterStatus, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
+       {
+               parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->dba = $dba;
+               $this->twitterStatus = $twitterStatus;
+       }
+       
        protected function rawContent(array $request = [])
        {
                BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
                $uid = BaseApi::getCurrentUserID();
 
                if (empty($request['list_id'])) {
-                       throw new BadRequestException('list_id not specified');
+                       throw new HTTPException\BadRequestException('list_id not specified');
                }
 
                // params
@@ -54,7 +74,7 @@ class Statuses extends BaseApi
 
                $start = max(0, ($page - 1) * $count);
 
-               $groups    = DBA::selectToArray('group_member', ['contact-id'], ['gid' => $request['list_id']]);
+               $groups    = $this->dba->selectToArray('group_member', ['contact-id'], ['gid' => $request['list_id']]);
                $gids      = array_column($groups, 'contact-id');
                $condition = ['uid' => $uid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'contact-id' => $gids];
                $condition = DBA::mergeConditions($condition, ["`id` > ?", $since_id]);
@@ -78,10 +98,10 @@ class Statuses extends BaseApi
                $include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true');
 
                $items = [];
-               while ($status = DBA::fetch($statuses)) {
-                       $items[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
+               while ($status = $this->dba->fetch($statuses)) {
+                       $items[] = $this->twitterStatus->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
                }
-               DBA::close($statuses);
+               $this->dba->close($statuses);
 
                $this->response->exit('statuses', ['status' => $items], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
        }
index e78ae2744d2a82d8b4a5acc4585bb65d8d181dbb..95fe90d0acbb9a7396dfb0b547b9414943d124eb 100644 (file)
 
 namespace Friendica\Module\Api\Twitter\Lists;
 
-use Friendica\Database\DBA;
-use Friendica\DI;
+use Friendica\App;
+use Friendica\Core\L10n;
+use Friendica\Database\Database;
+use Friendica\Factory\Api\Friendica\Group as FriendicaGroup;
 use Friendica\Module\BaseApi;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
+use Friendica\Module\Api\ApiResponse;
 use Friendica\Network\HTTPException;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
 
 /**
  * Update information about a group.
@@ -35,6 +40,20 @@ use Friendica\Network\HTTPException;
  */
 class Update extends BaseApi
 {
+       /** @var friendicaGroup */
+       private $friendicaGroup;
+
+       /** @var Database */
+       private $dba;
+
+       public function __construct(Database $dba, FriendicaGroup $friendicaGroup, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
+       {
+               parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->dba = $dba;
+               $this->friendicaGroup = $friendicaGroup;
+       }
+
        protected function rawContent(array $request = [])
        {
                BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
@@ -50,14 +69,14 @@ class Update extends BaseApi
                }
        
                // get data of the specified group id
-               $group = DBA::selectFirst('group', [], ['uid' => $uid, 'id' => $gid]);
+               $group = $this->dba->selectFirst('group', [], ['uid' => $uid, 'id' => $gid]);
                // error message if specified gid is not in database
                if (!$group) {
                        throw new HTTPException\BadRequestException('gid not available');
                }
        
                if (Group::update($gid, $name)) {
-                       $list = DI::friendicaGroup()->createFromId($gid);
+                       $list = $this->friendicaGroup->createFromId($gid);
        
                        $this->response->exit('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
                }