* @param BaseEntity[] $entities
* @param int|null $totalCount
*/
- public function __construct(array $entities = [], int $totalCount = null)
+ public function __construct(array $entities = [], ?int $totalCount = null)
{
parent::__construct($entities);
* @return BaseCollection
* @see array_filter()
*/
- public function filter(callable $callback = null, int $flag = 0): BaseCollection
+ public function filter(?callable $callback = null, int $flag = 0): BaseCollection
{
$class = get_class($this);
/**
* Reverse the orders of the elements in the collection
- *
- * @return $this
*/
public function reverse(): BaseCollection
{
* Split the collection in smaller collections no bigger than the provided length
*
* @param int $length
- * @return static[]
*/
public function chunk(int $length): array
{
throw new \RangeException('BaseCollection->chunk(): Size parameter expected to be greater than 0');
}
- return array_map(function ($array) {
- $class = get_class($this);
+ return array_map(
+ function ($array) {
+ $class = get_class($this);
- return new $class($array);
- }, array_chunk($this->getArrayCopy(), $length));
+ return new $class($array);
+ },
+ array_chunk($this->getArrayCopy(), $length)
+ );
}
namespace Friendica\Contact\FriendSuggest\Repository;
use Friendica\BaseRepository;
-use Friendica\Contact\FriendSuggest\Collection;
+use Friendica\Contact\FriendSuggest\Collection\FriendSuggests as FriendSuggestsCollection;
use Friendica\Contact\FriendSuggest\Entity\FriendSuggest as FriendSuggestEntity;
use Friendica\Contact\FriendSuggest\Exception\FriendSuggestNotFoundException;
use Friendica\Contact\FriendSuggest\Exception\FriendSuggestPersistenceException;
-use Friendica\Contact\FriendSuggest\Factory;
+use Friendica\Contact\FriendSuggest\Factory\FriendSuggest as FriendSuggestFactory;
use Friendica\Database\Database;
use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Util\DateTimeFormat;
class FriendSuggest extends BaseRepository
{
- /** @var Factory\FriendSuggest */
+ /** @var FriendSuggestFactory */
protected $factory;
protected static $table_name = 'fsuggest';
- public function __construct(Database $database, LoggerInterface $logger, Factory\FriendSuggest $factory)
+ public function __construct(Database $database, LoggerInterface $logger, FriendSuggestFactory $factory)
{
parent::__construct($database, $logger, $factory);
}
*/
private function selectOne(array $condition, array $params = []): FriendSuggestEntity
{
- return parent::_selectOne($condition, $params);
+ $fields = $this->_selectFirstRowAsArray( $condition, $params);
+
+ return $this->factory->createFromTableRow($fields);
}
/**
- * @param array $condition
- * @param array $params
- *
- * @return Collection\FriendSuggests
- *
* @throws \Exception
*/
- private function select(array $condition, array $params = []): Collection\FriendSuggests
+ private function select(array $condition, array $params = []): FriendSuggestsCollection
{
- return new Collection\FriendSuggests(parent::_select($condition, $params)->getArrayCopy());
+ return new FriendSuggestsCollection(parent::_select($condition, $params)->getArrayCopy());
}
/**
}
/**
- * @param int $cid
- *
- * @return Collection\FriendSuggests
- *
* @throws FriendSuggestPersistenceException In case the underlying storage cannot select the suggestion
*/
- public function selectForContact(int $cid): Collection\FriendSuggests
+ public function selectForContact(int $cid): FriendSuggestsCollection
{
try {
return $this->select(['cid' => $cid]);
}
/**
- * @param Collection\FriendSuggests $fsuggests
- *
- * @return bool
- *
* @throws FriendSuggestNotFoundException in case the underlying storage cannot delete the suggestion
*/
- public function delete(Collection\FriendSuggests $fsuggests): bool
+ public function delete(FriendSuggestsCollection $fsuggests): bool
{
try {
$ids = $fsuggests->column('id');
use Friendica\BaseRepository;
use Friendica\Contact\Introduction\Exception\IntroductionNotFoundException;
use Friendica\Contact\Introduction\Exception\IntroductionPersistenceException;
-use Friendica\Contact\Introduction\Collection;
-use Friendica\Contact\Introduction\Entity;
-use Friendica\Contact\Introduction\Factory;
+use Friendica\Contact\Introduction\Collection\Introductions as IntroductionsCollection;
+use Friendica\Contact\Introduction\Entity\Introduction as IntroductionEntity;
+use Friendica\Contact\Introduction\Factory\Introduction as IntroductionFactory;
use Friendica\Database\Database;
use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Util\DateTimeFormat;
class Introduction extends BaseRepository
{
- /** @var Factory\Introduction */
+ /** @var IntroductionFactory */
protected $factory;
protected static $table_name = 'intro';
- public function __construct(Database $database, LoggerInterface $logger, Factory\Introduction $factory)
+ public function __construct(Database $database, LoggerInterface $logger, IntroductionFactory $factory)
{
parent::__construct($database, $logger, $factory);
}
/**
- * @param array $condition
- * @param array $params
- *
- * @return Entity\Introduction
- *
* @throws NotFoundException the underlying exception if there's no Introduction with the given conditions
*/
- private function selectOne(array $condition, array $params = []): Entity\Introduction
+ private function selectOne(array $condition, array $params = []): IntroductionEntity
{
- return parent::_selectOne($condition, $params);
+ $fields = $this->_selectFirstRowAsArray( $condition, $params);
+
+ return $this->factory->createFromTableRow($fields);
}
/**
* Converts a given Introduction into a DB compatible row array
- *
- * @param Entity\Introduction $introduction
- *
- * @return array
*/
- protected function convertToTableRow(Entity\Introduction $introduction): array
+ protected function convertToTableRow(IntroductionEntity $introduction): array
{
return [
'uid' => $introduction->uid,
}
/**
- * @param int $id
- * @param int $uid
- *
- * @return Entity\Introduction
- *
* @throws IntroductionNotFoundException in case there is no Introduction with this id
*/
- public function selectOneById(int $id, int $uid): Entity\Introduction
+ public function selectOneById(int $id, int $uid): IntroductionEntity
{
try {
return $this->selectOne(['id' => $id, 'uid' => $uid]);
* @param int|null $min_id
* @param int|null $max_id
* @param int $limit
- *
- * @return Collection\Introductions
*/
- public function selectForUser(int $uid, int $min_id = null, int $max_id = null, int $limit = self::LIMIT): Collection\Introductions
+ public function selectForUser(int $uid, ?int $min_id = null, ?int $max_id = null, int $limit = self::LIMIT): IntroductionsCollection
{
try {
$BaseCollection = parent::_selectByBoundaries(
throw new IntroductionPersistenceException(sprintf('Cannot select Introductions for used %d', $uid), $e);
}
- return new Collection\Introductions($BaseCollection->getArrayCopy(), $BaseCollection->getTotalCount());
+ return new IntroductionsCollection($BaseCollection->getArrayCopy(), $BaseCollection->getTotalCount());
}
/**
* Selects the introduction for a given contact
*
- * @param int $cid
- *
- * @return Entity\Introduction
- *
* @throws IntroductionNotFoundException in case there is not Introduction for this contact
*/
- public function selectForContact(int $cid): Entity\Introduction
+ public function selectForContact(int $cid): IntroductionEntity
{
try {
return $this->selectOne(['contact-id' => $cid]);
}
/**
- * @param Entity\Introduction $introduction
- *
- * @return bool
- *
* @throws IntroductionPersistenceException in case the underlying storage cannot delete the Introduction
*/
- public function delete(Entity\Introduction $introduction): bool
+ public function delete(IntroductionEntity $introduction): bool
{
if (!$introduction->id) {
return false;
}
/**
- * @param Entity\Introduction $introduction
- *
- * @return Entity\Introduction
- *
* @throws IntroductionPersistenceException In case the underlying storage cannot save the Introduction
*/
- public function save(Entity\Introduction $introduction): Entity\Introduction
+ public function save(IntroductionEntity $introduction): IntroductionEntity
{
try {
$fields = $this->convertToTableRow($introduction);
namespace Friendica\Contact\LocalRelationship\Repository;
-use Friendica\Contact\LocalRelationship\Entity;
-use Friendica\Contact\LocalRelationship\Exception;
-use Friendica\Contact\LocalRelationship\Factory;
+use Exception;
+use Friendica\BaseRepository;
+use Friendica\Contact\LocalRelationship\Entity\LocalRelationship as LocalRelationshipEntity;
+use Friendica\Contact\LocalRelationship\Exception\LocalRelationshipPersistenceException;
+use Friendica\Contact\LocalRelationship\Factory\LocalRelationship as LocalRelationshipFactory;
use Friendica\Database\Database;
-use Friendica\Network\HTTPException;
+use Friendica\Network\HTTPException\NotFoundException;
use Psr\Log\LoggerInterface;
-class LocalRelationship extends \Friendica\BaseRepository
+class LocalRelationship extends BaseRepository
{
protected static $table_name = 'user-contact';
- /** @var Factory\LocalRelationship */
+ /** @var LocalRelationshipFactory */
protected $factory;
- public function __construct(Database $database, LoggerInterface $logger, Factory\LocalRelationship $factory)
+ public function __construct(Database $database, LoggerInterface $logger, LocalRelationshipFactory $factory)
{
parent::__construct($database, $logger, $factory);
}
/**
- * @param int $uid
- * @param int $cid
- * @return Entity\LocalRelationship
- * @throws HTTPException\NotFoundException
+ * @throws NotFoundException
*/
- public function selectForUserContact(int $uid, int $cid): Entity\LocalRelationship
+ public function selectForUserContact(int $uid, int $cid): LocalRelationshipEntity
{
- return $this->_selectOne(['uid' => $uid, 'cid' => $cid]);
+ $fields = $this->_selectFirstRowAsArray( ['uid' => $uid, 'cid' => $cid]);
+
+ return $this->factory->createFromTableRow($fields);
}
/**
* Returns the existing local relationship between a user and a public contact or a default
* relationship if it doesn't.
*
- * @param int $uid
- * @param int $cid
- * @return Entity\LocalRelationship
- * @throws HTTPException\NotFoundException
+ * @throws NotFoundException
*/
- public function getForUserContact(int $uid, int $cid): Entity\LocalRelationship
+ public function getForUserContact(int $uid, int $cid): LocalRelationshipEntity
{
try {
return $this->selectForUserContact($uid, $cid);
- } catch (HTTPException\NotFoundException $e) {
+ } catch (NotFoundException $e) {
return $this->factory->createFromTableRow(['uid' => $uid, 'cid' => $cid]);
}
}
/**
- * @param int $uid
- * @param int $cid
- * @return bool
- * @throws \Exception
+ * @throws Exception
*/
public function existsForUserContact(int $uid, int $cid): bool
{
/**
* Converts a given local relationship into a DB compatible row array
- *
- * @param Entity\LocalRelationship $localRelationship
- *
- * @return array
*/
- protected function convertToTableRow(Entity\LocalRelationship $localRelationship): array
+ protected function convertToTableRow(LocalRelationshipEntity $localRelationship): array
{
return [
'uid' => $localRelationship->userId,
}
/**
- * @param Entity\LocalRelationship $localRelationship
- *
- * @return Entity\LocalRelationship
- *
- * @throws Exception\LocalRelationshipPersistenceException In case the underlying storage cannot save the LocalRelationship
+ * @throws LocalRelationshipPersistenceException In case the underlying storage cannot save the LocalRelationship
*/
- public function save(Entity\LocalRelationship $localRelationship): Entity\LocalRelationship
+ public function save(LocalRelationshipEntity $localRelationship): LocalRelationshipEntity
{
try {
$fields = $this->convertToTableRow($localRelationship);
$this->db->insert(self::$table_name, $fields, Database::INSERT_UPDATE);
return $localRelationship;
- } catch (\Exception $exception) {
- throw new Exception\LocalRelationshipPersistenceException(sprintf('Cannot insert/update the local relationship %d for user %d', $localRelationship->contactId, $localRelationship->userId), $exception);
+ } catch (Exception $exception) {
+ throw new LocalRelationshipPersistenceException(sprintf('Cannot insert/update the local relationship %d for user %d', $localRelationship->contactId, $localRelationship->userId), $exception);
}
}
}
namespace Friendica\Content\Conversation\Repository;
-use Friendica\BaseCollection;
+use Friendica\BaseRepository;
use Friendica\Content\Conversation\Collection\UserDefinedChannels;
-use Friendica\Content\Conversation\Entity;
-use Friendica\Content\Conversation\Factory;
+use Friendica\Content\Conversation\Entity\UserDefinedChannel as UserDefinedChannelEntity;
+use Friendica\Content\Conversation\Factory\UserDefinedChannel as UserDefinedChannelFactory;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\Util\DateTimeFormat;
use Psr\Log\LoggerInterface;
-class UserDefinedChannel extends \Friendica\BaseRepository
+class UserDefinedChannel extends BaseRepository
{
protected static $table_name = 'channel';
+ /** @var UserDefinedChannelFactory */
+ protected $factory;
+
private IManageConfigValues $config;
- public function __construct(Database $database, LoggerInterface $logger, Factory\UserDefinedChannel $factory, IManageConfigValues $config)
+ public function __construct(Database $database, LoggerInterface $logger, UserDefinedChannelFactory $factory, IManageConfigValues $config)
{
parent::__construct($database, $logger, $factory);
* @return UserDefinedChannels
* @throws \Exception
*/
- protected function _select(array $condition, array $params = []): BaseCollection
+ protected function _select(array $condition, array $params = []): UserDefinedChannels
{
$rows = $this->db->selectToArray(static::$table_name, [], $condition, $params);
*
* @param int $id The id of the user defined channel
* @param int $uid The user that this channel belongs to. (Not part of the primary key)
- * @return Entity\UserDefinedChannel
* @throws \Friendica\Network\HTTPException\NotFoundException
*/
- public function selectById(int $id, int $uid): Entity\UserDefinedChannel
+ public function selectById(int $id, int $uid): UserDefinedChannelEntity
{
- return $this->_selectOne(['id' => $id, 'uid' => $uid]);
+ $fields = $this->_selectFirstRowAsArray( ['id' => $id, 'uid' => $uid]);
+
+ return $this->factory->createFromTableRow($fields);
}
/**
return $this->_select(['uid' => $uid]);
}
- public function save(Entity\UserDefinedChannel $Channel): Entity\UserDefinedChannel
+ public function save(UserDefinedChannelEntity $Channel): UserDefinedChannelEntity
{
$fields = [
'label' => $Channel->label,
$disposableFullTextSearch = new DisposableFullTextSearch($this->db, $searchtext);
$filteredChannels = $this->select(['uid' => array_column($users, 'uid'), 'publish' => true, 'valid' => true])->filter(
- function (Entity\UserDefinedChannel $channel) use ($owner_id, $reshare_id, $language, $tags, $media_type, $disposableFullTextSearch, $searchtext) {
+ function (UserDefinedChannelEntity $channel) use ($owner_id, $reshare_id, $language, $tags, $media_type, $disposableFullTextSearch, $searchtext) {
static $uids = [];
// Filter out channels from already picked users
use Friendica\Util\Proxy;
use Psr\Http\Message\UriInterface;
-
/**
* @property-read int $id
* @property-read int $uriId
*
* @param \GuzzleHttp\Psr7\Uri $preview
* @param string $size
- * @return $this
+ * @return self
*/
public function withPreview(\GuzzleHttp\Psr7\Uri $preview, string $size = ''): self
{
use Friendica\BaseFactory;
use Friendica\Capabilities\ICanCreateFromTableRow;
-use Friendica\Content\Post\Entity;
-use Friendica\Network;
+use Friendica\Content\Post\Entity\PostMedia as PostMediaEntity;
+use Friendica\Network\Entity\MimeType as MimeTypeEntity;
+use Friendica\Network\Factory\MimeType as MimeTypeFactory;
use Friendica\Util\Network as UtilNetwork;
use GuzzleHttp\Psr7\Uri;
use Psr\Log\LoggerInterface;
class PostMedia extends BaseFactory implements ICanCreateFromTableRow
{
- /** @var Network\Factory\MimeType */
+ /** @var MimeTypeFactory */
private $mimeTypeFactory;
- public function __construct(Network\Factory\MimeType $mimeTypeFactory, LoggerInterface $logger)
+ public function __construct(MimeTypeFactory $mimeTypeFactory, LoggerInterface $logger)
{
parent::__construct($logger);
/**
* @inheritDoc
*/
- public function createFromTableRow(array $row)
+ public function createFromTableRow(array $row): PostMediaEntity
{
- return new Entity\PostMedia(
+ return new PostMediaEntity(
$row['uri-id'],
UtilNetwork::createUriFromString($row['url']),
$row['type'],
);
}
- public function createFromBlueskyImageEmbed(int $uriId, stdClass $image): Entity\PostMedia
+ public function createFromBlueskyImageEmbed(int $uriId, stdClass $image): PostMediaEntity
{
- return new Entity\PostMedia(
+ return new PostMediaEntity(
$uriId,
new Uri($image->fullsize),
- Entity\PostMedia::TYPE_IMAGE,
- new Network\Entity\MimeType('unkn', 'unkn'),
+ PostMediaEntity::TYPE_IMAGE,
+ new MimeTypeEntity('unkn', 'unkn'),
null,
null,
null,
}
- public function createFromBlueskyExternalEmbed(int $uriId, stdClass $external): Entity\PostMedia
+ public function createFromBlueskyExternalEmbed(int $uriId, stdClass $external): PostMediaEntity
{
- return new Entity\PostMedia(
+ return new PostMediaEntity(
$uriId,
new Uri($external->uri),
- Entity\PostMedia::TYPE_HTML,
- new Network\Entity\MimeType('text', 'html'),
+ PostMediaEntity::TYPE_HTML,
+ new MimeTypeEntity('text', 'html'),
null,
null,
null,
namespace Friendica\Content\Post\Repository;
-use Friendica\BaseCollection;
use Friendica\BaseRepository;
-use Friendica\Content\Post\Collection;
-use Friendica\Content\Post\Entity;
-use Friendica\Content\Post\Factory;
+use Friendica\Content\Post\Collection\PostMedias as PostMediasCollection;
+use Friendica\Content\Post\Entity\PostMedia as PostMediaEntity;
+use Friendica\Content\Post\Factory\PostMedia as PostMediaFactory;
use Friendica\Database\Database;
use Friendica\Model\Post;
use Friendica\Util\Strings;
{
protected static $table_name = 'post-media';
- public function __construct(Database $database, LoggerInterface $logger, Factory\PostMedia $factory)
+ /** @var PostMediaFactory */
+ protected $factory;
+
+ public function __construct(Database $database, LoggerInterface $logger, PostMediaFactory $factory)
{
parent::__construct($database, $logger, $factory);
}
- protected function _select(array $condition, array $params = []): BaseCollection
+ protected function _select(array $condition, array $params = []): PostMediasCollection
{
$rows = $this->db->selectToArray(static::$table_name, [], $condition, $params);
- $Entities = new Collection\PostMedias();
+ $Entities = new PostMediasCollection();
foreach ($rows as $fields) {
try {
$Entities[] = $this->factory->createFromTableRow($fields);
return $Entities;
}
- public function selectOneById(int $postMediaId): Entity\PostMedia
+ public function selectOneById(int $postMediaId): PostMediaEntity
{
- return $this->_selectOne(['id' => $postMediaId]);
+ $fields = $this->_selectFirstRowAsArray( ['id' => $postMediaId]);
+
+ return $this->factory->createFromTableRow($fields);
}
- public function selectByUriId(int $uriId): Collection\PostMedias
+ public function selectByUriId(int $uriId): PostMediasCollection
{
return $this->_select(["`uri-id` = ? AND `type` != ?", $uriId, Post\Media::UNKNOWN]);
}
- public function save(Entity\PostMedia $PostMedia): Entity\PostMedia
+ public function save(PostMediaEntity $PostMedia): PostMediaEntity
{
$fields = [
'uri-id' => $PostMedia->uriId,
* @param int $uri_id URI id
* @param array $links list of links that shouldn't be added
* @param bool $has_media
- * @return Collection\PostMedias[] Three collections in "visual", "link" and "additional" keys
+ * @return PostMediasCollection[] Three collections in "visual", "link" and "additional" keys
*/
public function splitAttachments(int $uri_id, array $links = [], bool $has_media = true): array
{
$attachments = [
- 'visual' => new Collection\PostMedias(),
- 'link' => new Collection\PostMedias(),
- 'additional' => new Collection\PostMedias(),
+ 'visual' => new PostMediasCollection(),
+ 'link' => new PostMediasCollection(),
+ 'additional' => new PostMediasCollection(),
];
if (!$has_media) {
// Currently these two types are ignored here.
// Posts are added differently and contacts are not displayed as attachments.
- if (in_array($PostMedia->type, [Entity\PostMedia::TYPE_ACCOUNT, Entity\PostMedia::TYPE_ACTIVITY])) {
+ if (in_array($PostMedia->type, [PostMediaEntity::TYPE_ACCOUNT, PostMediaEntity::TYPE_ACTIVITY])) {
continue;
}
//$PostMedia->filetype = $filetype;
//$PostMedia->subtype = $subtype;
- if ($PostMedia->type == Entity\PostMedia::TYPE_HTML || ($PostMedia->mimetype->type == 'text' && $PostMedia->mimetype->subtype == 'html')) {
+ if ($PostMedia->type == PostMediaEntity::TYPE_HTML || ($PostMedia->mimetype->type == 'text' && $PostMedia->mimetype->subtype == 'html')) {
$attachments['link'][] = $PostMedia;
continue;
}
if (
- in_array($PostMedia->type, [Entity\PostMedia::TYPE_AUDIO, Entity\PostMedia::TYPE_IMAGE, Entity\PostMedia::TYPE_HLS]) ||
+ in_array($PostMedia->type, [PostMediaEntity::TYPE_AUDIO, PostMediaEntity::TYPE_IMAGE, PostMediaEntity::TYPE_HLS]) ||
in_array($PostMedia->mimetype->type, ['audio', 'image'])
) {
$attachments['visual'][] = $PostMedia;
- } elseif (($PostMedia->type == Entity\PostMedia::TYPE_VIDEO) || ($PostMedia->mimetype->type == 'video')) {
+ } elseif (($PostMedia->type == PostMediaEntity::TYPE_VIDEO) || ($PostMedia->mimetype->type == 'video')) {
if (!empty($PostMedia->height)) {
// Peertube videos are delivered in many different resolutions. We pick a moderate one.
// Since only Peertube provides a "height" parameter, this wouldn't be executed
namespace Friendica\Core\Worker\Repository;
use Friendica\BaseRepository;
+use Friendica\Core\Worker\Entity\Process as ProcessEntity;
use Friendica\Core\Worker\Exception\ProcessPersistenceException;
+use Friendica\Core\Worker\Factory\Process as ProcessFactory;
use Friendica\Database\Database;
use Friendica\Util\DateTimeFormat;
-use Friendica\Core\Worker\Factory;
-use Friendica\Core\Worker\Entity;
use Psr\Log\LoggerInterface;
/**
protected static $table_name = 'process';
- /** @var Factory\Process */
+ /** @var ProcessFactory */
protected $factory;
/** @var string */
private $currentHost;
- public function __construct(Database $database, LoggerInterface $logger, Factory\Process $factory, array $server)
+ public function __construct(Database $database, LoggerInterface $logger, ProcessFactory $factory, array $server)
{
parent::__construct($database, $logger, $factory);
/**
* Starts and Returns the process for a given PID at the current host
- *
- * @param int $pid
- * @param string $command
- *
- * @return Entity\Process
*/
- public function create(int $pid, string $command): Entity\Process
+ public function create(int $pid, string $command): ProcessEntity
{
// Cleanup inactive process
$this->deleteInactive();
}
}
- $result = $this->_selectOne(['pid' => $pid, 'hostname' => $this->currentHost]);
+ $fields = $this->_selectFirstRowAsArray( ['pid' => $pid, 'hostname' => $this->currentHost]);
+
+ $result = $this->factory->createFromTableRow($fields);
$this->db->commit();
}
}
- public function delete(Entity\Process $process)
+ public function delete(ProcessEntity $process)
{
try {
if (!$this->db->delete(static::$table_name, [