mirror of
https://github.com/friendica/friendica
synced 2025-04-24 07:50:11 +00:00
"DI" calls are replaced
This commit is contained in:
parent
f68c94db04
commit
c55c42b303
11 changed files with 194 additions and 63 deletions
|
@ -21,12 +21,17 @@
|
|||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -21,12 +21,17 @@
|
|||
|
||||
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));
|
||||
|
|
|
@ -21,10 +21,15 @@
|
|||
|
||||
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));
|
||||
|
|
|
@ -21,12 +21,18 @@
|
|||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -21,12 +21,17 @@
|
|||
|
||||
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));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue