share( Services\ScoreCalculator::class, static fn( Container $c ) => new Services\ScoreCalculator( $c->get( Options::class ) ) ); $container->share( Services\EngineReadiness::class, static fn( Container $c ) => new Services\EngineReadiness( $c->get( Options::class ) ) ); } public function boot( Container $container ): void { // The dashboard payload is cached for five minutes; when the page // counts change it is stale by definition, and a stale dashboard next // to a fresh content screen is the "which number is true" bug. add_action( 'airanksuite/inventory/flushed', static function (): void { delete_transient( 'airanksuite_kpis' ); } ); // The dashboard's score line promises one point per recalculation "by // hand or on schedule". Until now only the first half was true: the // score was stamped when somebody pressed Recalculate, and on a site // where nobody did, the line's last date stayed where it was. A daily // reading keeps it moving; the jitter spreads thousands of installs // across the night instead of one minute. add_action( self::CRON_HOOK, static function () use ( $container ): void { $container->get( Services\ScoreCalculator::class )->calculate(); } ); \AiRankSuite\Support\Cron::ensure( self::CRON_HOOK, 'daily', time() + wp_rand( HOUR_IN_SECONDS, 6 * HOUR_IN_SECONDS ) ); add_action( 'rest_api_init', static function () use ( $container ): void { ( new Rest\ScoreController( $container->get( Services\ScoreCalculator::class ) ) )->register_routes(); $readiness = $container->get( Services\EngineReadiness::class ); register_rest_route( \AiRankSuite\Rest\RestController::NAMESPACE, '/score/engines', array( 'methods' => 'GET', 'callback' => static fn() => new \WP_REST_Response( $readiness->report() ), 'permission_callback' => static fn(): bool => current_user_can( 'manage_options' ), ) ); ( new Rest\KpiController() )->register_routes(); ( new Rest\SiteAnalyzerController() )->register_routes(); } ); } }