From: nupplaPhil Date: Fri, 27 Dec 2019 14:20:09 +0000 (+0100) Subject: Add Model\Introduction class to DI registry X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=df0c05d6356c8e06cd07be5bf81eb1d860b3d9a5;p=friendica.git Add Model\Introduction class to DI registry --- diff --git a/mod/notifications.php b/mod/notifications.php index 4db4a8a83e..73730b50a5 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -31,9 +31,7 @@ function notifications_post(App $a) } if ($request_id) { - /** @var Introduction $Intro */ - $Intro = \Friendica\BaseObject::getClass(Introduction::class); - $Intro->fetch(['id' => $request_id, 'uid' => local_user()]); + $Intro = DI::intro()->fetch(['id' => $request_id, 'uid' => local_user()]); switch ($_POST['submit']) { case L10n::t('Discard'): diff --git a/src/BaseModel.php b/src/BaseModel.php index 32011c7db2..f8cef0c13e 100644 --- a/src/BaseModel.php +++ b/src/BaseModel.php @@ -32,10 +32,11 @@ abstract class BaseModel */ private $data = []; - public function __construct(Database $dba, LoggerInterface $logger) + public function __construct(Database $dba, LoggerInterface $logger, $data = []) { $this->dba = $dba; $this->logger = $logger; + $this->data = $data; } /** @@ -71,15 +72,13 @@ abstract class BaseModel */ public function fetch(array $condition) { - $intro = $this->dba->selectFirst(static::$table_name, [], $condition); + $data = $this->dba->selectFirst(static::$table_name, [], $condition); - if (!$intro) { + if (!$data) { throw new HTTPException\NotFoundException(static::class . ' record not found.'); } - $this->data = $intro; - - return $this; + return new static($this->dba, $this->logger, $data); } /** diff --git a/src/DI.php b/src/DI.php index 557e98a801..e328a1fdd3 100644 --- a/src/DI.php +++ b/src/DI.php @@ -29,6 +29,7 @@ use Psr\Log\LoggerInterface; * @method static Core\Session\ISession session() * @method static Database\Database dba() * @method static Model\Notify notify() + * @method static Model\Introduction intro() * @method static Protocol\Activity activity() * @method static Util\ACLFormatter aclFormatter() * @method static Util\DateTimeFormat dtFormat() @@ -61,6 +62,7 @@ abstract class DI 'session' => Core\Session\ISession::class, 'dba' => Database\Database::class, 'notify' => Model\Notify::class, + 'intro' => Model\Introduction::class, 'activity' => Protocol\Activity::class, 'aclFormatter' => Util\ACLFormatter::class, 'dtFormat' => Util\DateTimeFormat::class, diff --git a/src/Module/Api/Mastodon/FollowRequests.php b/src/Module/Api/Mastodon/FollowRequests.php index a8d6cb52ea..6cafb44a66 100644 --- a/src/Module/Api/Mastodon/FollowRequests.php +++ b/src/Module/Api/Mastodon/FollowRequests.php @@ -30,9 +30,7 @@ class FollowRequests extends Api { parent::post($parameters); - /** @var Introduction $Intro */ - $Intro = self::getClass(Introduction::class); - $Intro->fetch(['id' => $parameters['id'], 'uid' => self::$current_user_id]); + $Intro = DI::intro()->fetch(['id' => $parameters['id'], 'uid' => self::$current_user_id]); $contactId = $Intro->{'contact-id'}; diff --git a/src/Module/FollowConfirm.php b/src/Module/FollowConfirm.php index b97b00944c..e54032c850 100644 --- a/src/Module/FollowConfirm.php +++ b/src/Module/FollowConfirm.php @@ -23,9 +23,7 @@ class FollowConfirm extends BaseModule $duplex = intval($_POST['duplex'] ?? 0); $hidden = intval($_POST['hidden'] ?? 0); - /** @var Introduction $Intro */ - $Intro = self::getClass(Introduction::class); - $Intro->fetch(['id' => $intro_id, 'uid' => local_user()]); + $Intro = DI::intro()->fetch(['id' => $intro_id, 'uid' => local_user()]); $cid = $Intro->{'contact-id'};