Add Model\Introduction class to DI registry

This commit is contained in:
nupplaPhil 2019-12-27 15:20:09 +01:00
parent 2cb449a0d5
commit df0c05d635
No known key found for this signature in database
GPG Key ID: D8365C3D36B77D90
5 changed files with 10 additions and 15 deletions

View File

@ -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'):

View File

@ -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);
}
/**

View File

@ -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,

View File

@ -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'};

View File

@ -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'};