PluginProbe
404 Solution / 4.1.13
404 Solution v4.1.13
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / MatchRequest.php

MatchRequest.php in 404 Solution 4.1.13, at includes/MatchRequest.php

65 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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