| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* The platform services an n-gram rebuild tick runs against. |
| 9 |
* |
| 10 |
* A rebuild tick needs three things from outside its own subsystem: somewhere |
| 11 |
* to run queries, somewhere to log, and something that can put the next tick on |
| 12 |
* the schedule. They travel together because they are all "the platform", not |
| 13 |
* because grouping them made a parameter list shorter: every class in the |
| 14 |
* rebuild chain that needs one needs all three, and each was separately |
| 15 |
* re-deriving the same cron-scheduler default. |
| 16 |
* |
| 17 |
* That default lives here now. Callers used to write |
| 18 |
* `$x instanceof ABJ_404_Solution_CronScheduler ? $x : null` on the way in and |
| 19 |
* the receiving constructor wrote the mirror-image check on the way out, so the |
| 20 |
* same decision was spelled twice per call site and could drift. Passing a null |
| 21 |
* scheduler here means "use the shipped one"; tests pass their own. |
| 22 |
* |
| 23 |
* @see ABJ_404_Solution_NGramCacheRebuildBatchRunner |
| 24 |
* @see ABJ_404_Solution_NGramRescheduleFailureReport |
| 25 |
*/ |
| 26 |
class ABJ_404_Solution_NGramRebuildRuntime { |
| 27 |
|
| 28 |
/** @var ABJ_404_Solution_DatabaseCore */ |
| 29 |
private $dbCore; |
| 30 |
|
| 31 |
/** @var ABJ_404_Solution_Logging */ |
| 32 |
private $logger; |
| 33 |
|
| 34 |
/** @var ABJ_404_Solution_CronScheduler */ |
| 35 |
private $cronScheduler; |
| 36 |
|
| 37 |
/** |
| 38 |
* @param ABJ_404_Solution_DatabaseCore $dbCore |
| 39 |
* @param ABJ_404_Solution_Logging $logger |
| 40 |
* @param ABJ_404_Solution_CronScheduler|null $cronScheduler Null resolves to |
| 41 |
* the shipped scheduler; tests pass one to pin scheduling. |
| 42 |
*/ |
| 43 |
public function __construct( |
| 44 |
ABJ_404_Solution_DatabaseCore $dbCore, |
| 45 |
ABJ_404_Solution_Logging $logger, |
| 46 |
?ABJ_404_Solution_CronScheduler $cronScheduler = null |
| 47 |
) { |
| 48 |
$this->dbCore = $dbCore; |
| 49 |
$this->logger = $logger; |
| 50 |
$this->cronScheduler = $cronScheduler instanceof ABJ_404_Solution_CronScheduler |
| 51 |
? $cronScheduler |
| 52 |
: abj_cron_scheduler(); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Accessors rather than public fields, and non-nullable rather than |
| 57 |
* nullable: the constructor resolves every one of these, so a consumer |
| 58 |
* never has to ask whether it got a real collaborator. The older bundles in |
| 59 |
* this codebase expose nullable public fields and make each consumer repeat |
| 60 |
* a `?? abj_service(...)` fallback, which is the duplication this exists to |
| 61 |
* remove. |
| 62 |
* |
| 63 |
* @return ABJ_404_Solution_DatabaseCore |
| 64 |
*/ |
| 65 |
public function dbCore(): ABJ_404_Solution_DatabaseCore { |
| 66 |
return $this->dbCore; |
| 67 |
} |
| 68 |
|
| 69 |
/** @return ABJ_404_Solution_Logging */ |
| 70 |
public function logger(): ABJ_404_Solution_Logging { |
| 71 |
return $this->logger; |
| 72 |
} |
| 73 |
|
| 74 |
/** @return ABJ_404_Solution_CronScheduler */ |
| 75 |
public function cronScheduler(): ABJ_404_Solution_CronScheduler { |
| 76 |
return $this->cronScheduler; |
| 77 |
} |
| 78 |
} |
| 79 |
|