| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Value object representing a successful match from a matching engine. |
| 9 |
* |
| 10 |
* Immutable after construction. Provides toLegacyArray() for backward compatibility |
| 11 |
* with code that expects the old associative array shape. |
| 12 |
*/ |
| 13 |
class ABJ_404_Solution_MatchResult { |
| 14 |
|
| 15 |
/** @var string */ |
| 16 |
private $id; |
| 17 |
|
| 18 |
/** @var string */ |
| 19 |
private $type; |
| 20 |
|
| 21 |
/** @var string */ |
| 22 |
private $link; |
| 23 |
|
| 24 |
/** @var string */ |
| 25 |
private $title; |
| 26 |
|
| 27 |
/** @var float */ |
| 28 |
private $score; |
| 29 |
|
| 30 |
/** @var string */ |
| 31 |
private $engineName; |
| 32 |
|
| 33 |
/** |
| 34 |
* @param string $id Post/page ID |
| 35 |
* @param string $type Content type (ABJ404_TYPE_POST, etc.) |
| 36 |
* @param string $link Permalink URL |
| 37 |
* @param string $title Post/page title |
| 38 |
* @param float $score Match confidence score |
| 39 |
* @param string $engineName Name of the engine that produced this result |
| 40 |
*/ |
| 41 |
public function __construct( |
| 42 |
string $id, |
| 43 |
string $type, |
| 44 |
string $link, |
| 45 |
string $title, |
| 46 |
float $score, |
| 47 |
string $engineName |
| 48 |
) { |
| 49 |
$this->id = $id; |
| 50 |
$this->type = $type; |
| 51 |
$this->link = $link; |
| 52 |
$this->title = $title; |
| 53 |
$this->score = $score; |
| 54 |
$this->engineName = $engineName; |
| 55 |
} |
| 56 |
|
| 57 |
/** @return string */ |
| 58 |
public function getId(): string { |
| 59 |
return $this->id; |
| 60 |
} |
| 61 |
|
| 62 |
/** @return string */ |
| 63 |
public function getType(): string { |
| 64 |
return $this->type; |
| 65 |
} |
| 66 |
|
| 67 |
/** @return string */ |
| 68 |
public function getLink(): string { |
| 69 |
return $this->link; |
| 70 |
} |
| 71 |
|
| 72 |
/** @return string */ |
| 73 |
public function getTitle(): string { |
| 74 |
return $this->title; |
| 75 |
} |
| 76 |
|
| 77 |
/** @return float */ |
| 78 |
public function getScore(): float { |
| 79 |
return $this->score; |
| 80 |
} |
| 81 |
|
| 82 |
/** @return string */ |
| 83 |
public function getEngineName(): string { |
| 84 |
return $this->engineName; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Convert to the legacy associative array used by existing pipeline code. |
| 89 |
* |
| 90 |
* @return array{id: string, type: string, link: string, title: string, score: float, engine: string} |
| 91 |
*/ |
| 92 |
public function toLegacyArray(): array { |
| 93 |
return [ |
| 94 |
'id' => $this->id, |
| 95 |
'type' => $this->type, |
| 96 |
'link' => $this->link, |
| 97 |
'title' => $this->title, |
| 98 |
'score' => $this->score, |
| 99 |
'engine' => $this->engineName, |
| 100 |
]; |
| 101 |
} |
| 102 |
} |
| 103 |
|