35 lines
803 B
PHP
35 lines
803 B
PHP
<?php
|
|
|
|
namespace App\DTOs;
|
|
|
|
use App\Models\Article;
|
|
|
|
class ArticleCandidateDTO
|
|
{
|
|
public function __construct(
|
|
public readonly int $articleId,
|
|
public readonly string $title,
|
|
public readonly string $content,
|
|
public readonly float $distance
|
|
) {}
|
|
|
|
public static function fromArticle(Article $article, float $distance): self
|
|
{
|
|
return new self(
|
|
articleId: $article->id,
|
|
title: $article->title,
|
|
content: $article->content,
|
|
distance: $distance
|
|
);
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'article_id' => $this->articleId,
|
|
'title' => $this->title,
|
|
'content' => $this->content,
|
|
'distance' => $this->distance,
|
|
];
|
|
}
|
|
} |