| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Value object representing a 404 request to be matched. |
| 9 |
* |
| 10 |
* Bundles the data that matching engines need: the full requested URL, |
| 11 |
* the slug-only portion, and the plugin options array. |
| 12 |
*/ |
| 13 |
class ABJ_404_Solution_MatchRequest { |
| 14 |
|
| 15 |
/** @var string */ |
| 16 |
private $requestedURL; |
| 17 |
|
| 18 |
/** @var string */ |
| 19 |
private $urlSlugOnly; |
| 20 |
|
| 21 |
/** @var array<string, mixed> */ |
| 22 |
private $options; |
| 23 |
|
| 24 |
/** |
| 25 |
* @param string $requestedURL Full requested URL path (e.g., '/blog/old-pge') |
| 26 |
* @param string $urlSlugOnly Slug portion only (e.g., 'old-pge') |
| 27 |
* @param array<string, mixed> $options Plugin options array |
| 28 |
*/ |
| 29 |
public function __construct(string $requestedURL, string $urlSlugOnly, array $options) { |
| 30 |
$this->requestedURL = $requestedURL; |
| 31 |
$this->urlSlugOnly = $urlSlugOnly; |
| 32 |
$this->options = $options; |
| 33 |
} |
| 34 |
|
| 35 |
/** @return string */ |
| 36 |
public function getRequestedURL(): string { |
| 37 |
return $this->requestedURL; |
| 38 |
} |
| 39 |
|
| 40 |
/** @return string */ |
| 41 |
public function getUrlSlugOnly(): string { |
| 42 |
return $this->urlSlugOnly; |
| 43 |
} |
| 44 |
|
| 45 |
/** @return array<string, mixed> */ |
| 46 |
public function getOptions(): array { |
| 47 |
return $this->options; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Get the minimum score threshold for a specific engine, falling back to the global auto_score. |
| 52 |
* |
| 53 |
* @param string $engineKey Engine-specific option key (e.g. 'auto_score_title') |
| 54 |
* @return float |
| 55 |
*/ |
| 56 |
public function getMinScore(string $engineKey): float { |
| 57 |
$opts = $this->options; |
| 58 |
if ($engineKey !== '' && isset($opts[$engineKey]) && $opts[$engineKey] !== '' && is_numeric($opts[$engineKey])) { |
| 59 |
return (float)$opts[$engineKey]; |
| 60 |
} |
| 61 |
return isset($opts['auto_score']) && is_numeric($opts['auto_score']) |
| 62 |
? (float)$opts['auto_score'] : 0.0; |
| 63 |
} |
| 64 |
} |
| 65 |
|