| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Dependency bundle for {@see ABJ_404_Solution_DatabaseUpgradesEtc}. |
| 9 |
* |
| 10 |
* Core upgrade services resolve through the service container when omitted, |
| 11 |
* matching the legacy facade constructor defaults. Late n-gram collaborators |
| 12 |
* stay nullable because the n-gram delegate can lazily build concrete |
| 13 |
* collaborators or accept behavior-based test seams. |
| 14 |
*/ |
| 15 |
final class ABJ_404_Solution_DatabaseUpgradesDependencies { |
| 16 |
|
| 17 |
/** @var ABJ_404_Solution_DataAccess */ |
| 18 |
private $dataAccess; |
| 19 |
/** @var bool */ |
| 20 |
private $dataAccessInjected; |
| 21 |
/** @var ABJ_404_Solution_Logging */ |
| 22 |
private $logging; |
| 23 |
/** @var ABJ_404_Solution_Functions */ |
| 24 |
private $functions; |
| 25 |
/** @var ABJ_404_Solution_PermalinkCache */ |
| 26 |
private $permalinkCache; |
| 27 |
/** @var ABJ_404_Solution_SynchronizationUtils */ |
| 28 |
private $syncUtils; |
| 29 |
/** @var ABJ_404_Solution_PluginLogicInterface */ |
| 30 |
private $pluginLogic; |
| 31 |
/** @var ABJ_404_Solution_NGramFilter */ |
| 32 |
private $ngramFilter; |
| 33 |
/** @var mixed */ |
| 34 |
private $ngramExtractor; |
| 35 |
/** @var mixed */ |
| 36 |
private $ngramCacheRepository; |
| 37 |
/** @var mixed */ |
| 38 |
private $ngramCoveragePolicy; |
| 39 |
/** @var mixed */ |
| 40 |
private $ngramRebuilder; |
| 41 |
/** @var ABJ_404_Solution_CronScheduler|null */ |
| 42 |
private $cronScheduler; |
| 43 |
|
| 44 |
/** |
| 45 |
* @param array<string, mixed> $overrides Optional collaborators keyed by |
| 46 |
* dataAccess, logging, functions, permalinkCache, syncUtils, |
| 47 |
* pluginLogic, ngramFilter, ngramExtractor, ngramCacheRepository, |
| 48 |
* ngramCoveragePolicy, ngramRebuilder, and cronScheduler. |
| 49 |
*/ |
| 50 |
public function __construct(array $overrides = array()) { |
| 51 |
$this->dataAccessInjected = array_key_exists('dataAccess', $overrides) && $overrides['dataAccess'] !== null; |
| 52 |
$this->dataAccess = $this->resolveService($overrides, 'dataAccess', 'data_access', ABJ_404_Solution_DataAccess::class); |
| 53 |
$this->logging = $this->resolveService($overrides, 'logging', 'logging', ABJ_404_Solution_Logging::class); |
| 54 |
$this->functions = $this->resolveService($overrides, 'functions', 'functions', ABJ_404_Solution_Functions::class); |
| 55 |
$this->permalinkCache = $this->resolveService($overrides, 'permalinkCache', 'permalink_cache', ABJ_404_Solution_PermalinkCache::class); |
| 56 |
$this->syncUtils = $this->resolveService($overrides, 'syncUtils', 'sync_utils', ABJ_404_Solution_SynchronizationUtils::class); |
| 57 |
$this->pluginLogic = $this->resolveService($overrides, 'pluginLogic', 'plugin_logic', ABJ_404_Solution_PluginLogicInterface::class); |
| 58 |
$this->ngramFilter = $this->resolveService($overrides, 'ngramFilter', 'ngram_filter', ABJ_404_Solution_NGramFilter::class); |
| 59 |
$this->ngramExtractor = $overrides['ngramExtractor'] ?? null; |
| 60 |
$this->ngramCacheRepository = $overrides['ngramCacheRepository'] ?? null; |
| 61 |
$this->ngramCoveragePolicy = $overrides['ngramCoveragePolicy'] ?? null; |
| 62 |
$this->ngramRebuilder = $overrides['ngramRebuilder'] ?? null; |
| 63 |
$cronScheduler = $overrides['cronScheduler'] ?? null; |
| 64 |
$this->cronScheduler = $cronScheduler instanceof ABJ_404_Solution_CronScheduler ? $cronScheduler : null; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* @param array<string, mixed> $overrides |
| 69 |
* @template T of object |
| 70 |
* @param class-string<T> $expectedClass |
| 71 |
* @return T |
| 72 |
*/ |
| 73 |
private function resolveService(array $overrides, string $key, string $serviceName, string $expectedClass) { |
| 74 |
$service = array_key_exists($key, $overrides) && $overrides[$key] !== null |
| 75 |
? $overrides[$key] |
| 76 |
: abj_service($serviceName); |
| 77 |
|
| 78 |
if ($service instanceof $expectedClass) { |
| 79 |
return $service; |
| 80 |
} |
| 81 |
|
| 82 |
$actual = is_object($service) ? get_class($service) : gettype($service); |
| 83 |
throw new InvalidArgumentException("DatabaseUpgradesDependencies {$key} must resolve to {$expectedClass}; got {$actual}."); |
| 84 |
} |
| 85 |
|
| 86 |
/** @return ABJ_404_Solution_DataAccess */ |
| 87 |
public function getDataAccess() { return $this->dataAccess; } |
| 88 |
|
| 89 |
/** @return bool */ |
| 90 |
public function hasDataAccessOverride(): bool { return $this->dataAccessInjected; } |
| 91 |
|
| 92 |
/** @return ABJ_404_Solution_Logging */ |
| 93 |
public function getLogging() { return $this->logging; } |
| 94 |
|
| 95 |
/** @return ABJ_404_Solution_Functions */ |
| 96 |
public function getFunctions() { return $this->functions; } |
| 97 |
|
| 98 |
/** @return ABJ_404_Solution_PermalinkCache */ |
| 99 |
public function getPermalinkCache() { return $this->permalinkCache; } |
| 100 |
|
| 101 |
/** @return ABJ_404_Solution_SynchronizationUtils */ |
| 102 |
public function getSyncUtils() { return $this->syncUtils; } |
| 103 |
|
| 104 |
/** @return ABJ_404_Solution_PluginLogicInterface */ |
| 105 |
public function getPluginLogic() { return $this->pluginLogic; } |
| 106 |
|
| 107 |
/** @return ABJ_404_Solution_NGramFilter */ |
| 108 |
public function getNGramFilter() { return $this->ngramFilter; } |
| 109 |
|
| 110 |
/** @return mixed */ |
| 111 |
public function getNGramExtractor() { return $this->ngramExtractor; } |
| 112 |
|
| 113 |
/** @return mixed */ |
| 114 |
public function getNGramCacheRepository() { return $this->ngramCacheRepository; } |
| 115 |
|
| 116 |
/** @return mixed */ |
| 117 |
public function getNGramCoveragePolicy() { return $this->ngramCoveragePolicy; } |
| 118 |
|
| 119 |
/** @return mixed */ |
| 120 |
public function getNGramRebuilder() { return $this->ngramRebuilder; } |
| 121 |
|
| 122 |
/** |
| 123 |
* Optional cron scheduler override. Null in production so the n-gram |
| 124 |
* rebuild scheduler falls back to abj_cron_scheduler(); tests inject a |
| 125 |
* recording double to assert (or suppress) WP-Cron scheduling without |
| 126 |
* touching the WordPress cron API. |
| 127 |
* |
| 128 |
* @return ABJ_404_Solution_CronScheduler|null |
| 129 |
*/ |
| 130 |
public function getCronScheduler() { return $this->cronScheduler; } |
| 131 |
} |
| 132 |
|