Add DDD classes for Mastodon\Field entity
This commit is contained in:
parent
5670c19d5c
commit
07a4bb73fa
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Collection\Api\Mastodon;
|
||||||
|
|
||||||
|
use Friendica\Api\Entity\Mastodon\Field;
|
||||||
|
use Friendica\BaseCollection;
|
||||||
|
|
||||||
|
class Fields extends BaseCollection
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Field[] $entities
|
||||||
|
* @param int|null $totalCount
|
||||||
|
*/
|
||||||
|
public function __construct(array $entities = [], int $totalCount = null)
|
||||||
|
{
|
||||||
|
parent::__construct($entities);
|
||||||
|
|
||||||
|
$this->totalCount = $totalCount ?? count($entities);
|
||||||
|
}
|
||||||
|
}
|
|
@ -236,6 +236,14 @@ abstract class DI
|
||||||
return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
|
return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Factory\Api\Mastodon\Field
|
||||||
|
*/
|
||||||
|
public static function mstdnField()
|
||||||
|
{
|
||||||
|
return self::$dice->create(Factory\Api\Mastodon\Field::class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Factory\Api\Mastodon\FollowRequest
|
* @return Factory\Api\Mastodon\FollowRequest
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Factory\Api\Mastodon;
|
||||||
|
|
||||||
|
use Friendica\BaseFactory;
|
||||||
|
use Friendica\Collection\Api\Mastodon\Fields;
|
||||||
|
use Friendica\Collection\ProfileFields;
|
||||||
|
use Friendica\Content\Text\BBCode;
|
||||||
|
use Friendica\Model\ProfileField;
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class Field extends BaseFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param ProfileField $profileField
|
||||||
|
* @return \Friendica\Api\Entity\Mastodon\Field
|
||||||
|
* @throws HTTPException\InternalServerErrorException
|
||||||
|
*/
|
||||||
|
public function createFromProfileField(ProfileField $profileField)
|
||||||
|
{
|
||||||
|
return new \Friendica\Api\Entity\Mastodon\Field($profileField->label, BBCode::convert($profileField->value, false, 9));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ProfileFields $profileFields
|
||||||
|
* @return Fields
|
||||||
|
* @throws HTTPException\InternalServerErrorException
|
||||||
|
*/
|
||||||
|
public function createFromProfileFields(ProfileFields $profileFields)
|
||||||
|
{
|
||||||
|
$fields = [];
|
||||||
|
|
||||||
|
foreach ($profileFields as $profileField) {
|
||||||
|
$fields[] = $this->createFromProfileField($profileField);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Fields($fields);
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ use Friendica\BaseEntity;
|
||||||
/**
|
/**
|
||||||
* Class Field
|
* Class Field
|
||||||
*
|
*
|
||||||
* @see https://docs.joinmastodon.org/api/entities/#field
|
* @see https://docs.joinmastodon.org/entities/field/
|
||||||
*/
|
*/
|
||||||
class Field extends BaseEntity
|
class Field extends BaseEntity
|
||||||
{
|
{
|
||||||
|
@ -17,4 +17,12 @@ class Field extends BaseEntity
|
||||||
protected $value;
|
protected $value;
|
||||||
/** @var string (Datetime)*/
|
/** @var string (Datetime)*/
|
||||||
protected $verified_at;
|
protected $verified_at;
|
||||||
|
|
||||||
|
public function __construct(string $name, string $value)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
$this->value = $value;
|
||||||
|
// Link verification unsupported
|
||||||
|
$this->verified_at = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user