mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-08 00:04:27 +02:00
Add DDD classes for post media entities
This commit is contained in:
parent
86cba639fc
commit
1052f6fde0
4 changed files with 586 additions and 0 deletions
117
src/Content/Post/Factory/PostMedia.php
Normal file
117
src/Content/Post/Factory/PostMedia.php
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Content\Post\Factory;
|
||||
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Capabilities\ICanCreateFromTableRow;
|
||||
use Friendica\Content\Post\Entity;
|
||||
use Friendica\Network;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use stdClass;
|
||||
|
||||
class PostMedia extends BaseFactory implements ICanCreateFromTableRow
|
||||
{
|
||||
/** @var Network\Factory\MimeType */
|
||||
private $mimeTypeFactory;
|
||||
|
||||
public function __construct(Network\Factory\MimeType $mimeTypeFactory, LoggerInterface $logger)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
|
||||
$this->mimeTypeFactory = $mimeTypeFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createFromTableRow(array $row)
|
||||
{
|
||||
return new Entity\PostMedia(
|
||||
$row['uri-id'],
|
||||
$row['url'] ? new Uri($row['url']) : null,
|
||||
$row['type'],
|
||||
$this->mimeTypeFactory->createFromContentType($row['mimetype']),
|
||||
$row['media-uri-id'],
|
||||
$row['width'],
|
||||
$row['height'],
|
||||
$row['size'],
|
||||
$row['preview'] ? new Uri($row['preview']) : null,
|
||||
$row['preview-width'],
|
||||
$row['preview-height'],
|
||||
$row['description'],
|
||||
$row['name'],
|
||||
$row['author-url'] ? new Uri($row['author-url']) : null,
|
||||
$row['author-name'],
|
||||
$row['author-image'] ? new Uri($row['author-image']) : null,
|
||||
$row['publisher-url'] ? new Uri($row['publisher-url']) : null,
|
||||
$row['publisher-name'],
|
||||
$row['publisher-image'] ? new Uri($row['publisher-image']) : null,
|
||||
$row['blurhash'],
|
||||
$row['id']
|
||||
);
|
||||
}
|
||||
|
||||
public function createFromBlueskyImageEmbed(int $uriId, stdClass $image): Entity\PostMedia
|
||||
{
|
||||
return new Entity\PostMedia(
|
||||
$uriId,
|
||||
new Uri($image->fullsize),
|
||||
Entity\PostMedia::TYPE_IMAGE,
|
||||
new Network\Entity\MimeType('unkn', 'unkn'),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
new Uri($image->thumb),
|
||||
null,
|
||||
null,
|
||||
$image->alt,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function createFromBlueskyExternalEmbed(int $uriId, stdClass $external): Entity\PostMedia
|
||||
{
|
||||
return new Entity\PostMedia(
|
||||
$uriId,
|
||||
new Uri($external->uri),
|
||||
Entity\PostMedia::TYPE_HTML,
|
||||
new Network\Entity\MimeType('text', 'html'),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$external->description,
|
||||
$external->title
|
||||
);
|
||||
}
|
||||
|
||||
public function createFromAttachment(int $uriId, array $attachment)
|
||||
{
|
||||
$attachment['uri-id'] = $uriId;
|
||||
return $this->createFromTableRow($attachment);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue