From: Hypolite Petovan Date: Sun, 16 Jul 2023 21:25:57 +0000 (-0400) Subject: Create DDD classes for gserver class X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2ba3069b073ecf1483c9028d017ab881b5c8a3a4;p=friendica.git Create DDD classes for gserver class --- diff --git a/src/Federation/Entity/GServer.php b/src/Federation/Entity/GServer.php new file mode 100644 index 0000000000..0e331f4803 --- /dev/null +++ b/src/Federation/Entity/GServer.php @@ -0,0 +1,151 @@ +. + * + */ + +namespace Friendica\Federation\Entity; + +use DateTimeImmutable; +use Psr\Http\Message\UriInterface; + +/** + * @property-read int $id + * @property-read string $url + * @property-read string $nurl + * @property-read string $version + * @property-read string $siteName + * @property-read string $info + * @property-read int $registerPolicy + * @property-read int $registeredUsers + * @property-read string $poco + * @property-read string $noscrape + * @property-read string $network + * @property-read string $platform + * @property-read int $relaySubscribe + * @property-read string $relayScope + * @property-read DateTimeImmutable $created + * @property-read ?DateTimeImmutable $lastPocoQuery + * @property-read ?DateTimeImmutable $lastContact + * @property-read ?DateTimeImmutable $lastFailure + * @property-read int $directoryType + * @property-read int $detectionMethod + * @property-read bool $failed + * @property-read DateTimeImmutable $nextContact + * @property-read int $protocol + * @property-read int $activeWeekUsers + * @property-read int $activeMonthUsers + * @property-read int $activeHalfyearUsers + * @property-read int $localPosts + * @property-read int $localComments + * @property-read bool $blocked + */ +class GServer extends \Friendica\BaseEntity +{ + /** @var ?int */ + protected $id; + /** @var UriInterface */ + protected $url; + /** @var UriInterface */ + protected $nurl; + /** @var string */ + protected $version; + /** @var string */ + protected $siteName; + /** @var string */ + protected $info; + /** @var int One of Module\Register::* constant values */ + protected $registerPolicy; + /** @var int */ + protected $registeredUsers; + /** @var ?UriInterface */ + protected $poco; + /** @var ?UriInterface */ + protected $noscrape; + /** @var string One of the Protocol::* constant values */ + protected $network; + /** @var string */ + protected $platform; + /** @var bool */ + protected $relaySubscribe; + /** @var string */ + protected $relayScope; + /** @var DateTimeImmutable */ + protected $created; + /** @var DateTimeImmutable */ + protected $lastPocoQuery; + /** @var DateTimeImmutable */ + protected $lastContact; + /** @var DateTimeImmutable */ + protected $lastFailure; + /** @var int One of Model\Gserver::DT_* constant values */ + protected $directoryType; + /** @var ?int One of Model\Gserver::DETECT_* constant values */ + protected $detectionMethod; + /** @var bool */ + protected $failed; + /** @var DateTimeImmutable */ + protected $nextContact; + /** @var ?int One of Model\Post\DeliveryData::* constant values */ + protected $protocol; + /** @var ?int */ + protected $activeWeekUsers; + /** @var ?int */ + protected $activeMonthUsers; + /** @var ?int */ + protected $activeHalfyearUsers; + /** @var ?int */ + protected $localPosts; + /** @var ?int */ + protected $localComments; + /** @var bool */ + protected $blocked; + + public function __construct(UriInterface $url, UriInterface $nurl, string $version, string $siteName, string $info, int $registerPolicy, int $registeredUsers, ?UriInterface $poco, ?UriInterface $noscrape, string $network, string $platform, bool $relaySubscribe, string $relayScope, DateTimeImmutable $created, ?DateTimeImmutable $lastPocoQuery, ?DateTimeImmutable $lastContact, ?DateTimeImmutable $lastFailure, int $directoryType, ?int $detectionMethod, bool $failed, ?DateTimeImmutable $nextContact, ?int $protocol, ?int $activeWeekUsers, ?int $activeMonthUsers, ?int $activeHalfyearUsers, ?int $localPosts, ?int $localComments, bool $blocked, ?int $id = null) + { + $this->url = $url; + $this->nurl = $nurl; + $this->version = $version; + $this->siteName = $siteName; + $this->info = $info; + $this->registerPolicy = $registerPolicy; + $this->registeredUsers = $registeredUsers; + $this->poco = $poco; + $this->noscrape = $noscrape; + $this->network = $network; + $this->platform = $platform; + $this->relaySubscribe = $relaySubscribe; + $this->relayScope = $relayScope; + $this->created = $created; + $this->lastPocoQuery = $lastPocoQuery; + $this->lastContact = $lastContact; + $this->lastFailure = $lastFailure; + $this->directoryType = $directoryType; + $this->detectionMethod = $detectionMethod; + $this->failed = $failed; + $this->nextContact = $nextContact; + $this->protocol = $protocol; + $this->activeWeekUsers = $activeWeekUsers; + $this->activeMonthUsers = $activeMonthUsers; + $this->activeHalfyearUsers = $activeHalfyearUsers; + $this->localPosts = $localPosts; + $this->localComments = $localComments; + $this->blocked = $blocked; + $this->id = $id; + } +} diff --git a/src/Federation/Factory/GServer.php b/src/Federation/Factory/GServer.php new file mode 100644 index 0000000000..681cad7af4 --- /dev/null +++ b/src/Federation/Factory/GServer.php @@ -0,0 +1,68 @@ +. + * + */ + +namespace Friendica\Federation\Factory; + +use Friendica\Capabilities\ICanCreateFromTableRow; +use Friendica\Database\DBA; +use Friendica\Federation\Entity; +use GuzzleHttp\Psr7\Uri; + +class GServer extends \Friendica\BaseFactory implements ICanCreateFromTableRow +{ + /** + * @inheritDoc + */ + public function createFromTableRow(array $row): Entity\GServer + { + return new Entity\GServer( + new Uri($row['url']), + new Uri($row['nurl']), + $row['version'], + $row['site_name'], + $row['info'] ?? '', + $row['register_policy'], + $row['registered-users'], + $row['poco'] ? new Uri($row['poco']) : null, + $row['noscrape'] ? new Uri($row['noscrape']) : null, + $row['network'], + $row['platform'], + $row['relay-subscribe'], + $row['relay-scope'], + new \DateTimeImmutable($row['created']), + $row['last_poco_query'] !== DBA::NULL_DATETIME ? new \DateTimeImmutable($row['last_poco_query']) : null, + $row['last_contact'] !== DBA::NULL_DATETIME ? new \DateTimeImmutable($row['last_contact']) : null, + $row['last_failure'] !== DBA::NULL_DATETIME ? new \DateTimeImmutable($row['last_failure']) : null, + $row['directory-type'], + $row['detection-method'], + $row['failed'], + $row['next_contact'] !== DBA::NULL_DATETIME ? new \DateTimeImmutable($row['next_contact']) : null, + $row['protocol'], + $row['active-week-users'], + $row['active-month-users'], + $row['active-halfyear-users'], + $row['local-posts'], + $row['local-comments'], + $row['blocked'], + $row['id'], + ); + } +} diff --git a/src/Federation/Repository/GServer.php b/src/Federation/Repository/GServer.php new file mode 100644 index 0000000000..47a9244f6a --- /dev/null +++ b/src/Federation/Repository/GServer.php @@ -0,0 +1,47 @@ +. + * + */ + +namespace Friendica\Federation\Repository; + +use Friendica\Database\Database; +use Friendica\Federation\Factory; +use Friendica\Federation\Entity; +use Psr\Log\LoggerInterface; + +class GServer extends \Friendica\BaseRepository +{ + protected static $table_name = 'gserver'; + + public function __construct(Database $database, LoggerInterface $logger, Factory\GServer $factory) + { + parent::__construct($database, $logger, $factory); + } + + /** + * @param int $gsid + * @return Entity\GServer + * @throws \Friendica\Network\HTTPException\NotFoundException + */ + public function selectOneById(int $gsid): Entity\GServer + { + return $this->_selectOne(['id' => $gsid]); + } +}