| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
require_once __DIR__ . '/GscConfig.php'; |
| 8 |
require_once __DIR__ . '/GscOAuthTokenStore.php'; |
| 9 |
require_once __DIR__ . '/GscSearchAnalyticsClient.php'; |
| 10 |
require_once __DIR__ . '/GscAdminSectionRenderer.php'; |
| 11 |
|
| 12 |
/** |
| 13 |
* Composition root for the Google Search Console integration. |
| 14 |
* |
| 15 |
* Wires the three collaborators that do the real work and exposes them through |
| 16 |
* accessors. OAuth/token state, Search Analytics querying, and admin rendering |
| 17 |
* live in those collaborators; callers reach the behaviour they need via |
| 18 |
* {@see oauthStore()}, {@see searchAnalytics()}, and {@see renderer()}. |
| 19 |
* |
| 20 |
* Config constants are re-exported here as a stable reference surface for |
| 21 |
* callers and tests (the values themselves live in ABJ_404_Solution_GscConfig). |
| 22 |
*/ |
| 23 |
class ABJ_404_Solution_GoogleSearchConsole { |
| 24 |
|
| 25 |
const OPTION_KEY = ABJ_404_Solution_GscConfig::OPTION_KEY; |
| 26 |
const TOKEN_OPTION_KEY = ABJ_404_Solution_GscConfig::TOKEN_OPTION_KEY; |
| 27 |
const ERROR_OPTION_KEY = ABJ_404_Solution_GscConfig::ERROR_OPTION_KEY; |
| 28 |
const TRANSIENT_KEY = ABJ_404_Solution_GscConfig::TRANSIENT_KEY; |
| 29 |
const TRANSIENT_TTL = ABJ_404_Solution_GscConfig::TRANSIENT_TTL; |
| 30 |
|
| 31 |
const CRON_HOOK = ABJ_404_Solution_GscConfig::CRON_HOOK; |
| 32 |
const BACKGROUND_REFRESH_HOOK = ABJ_404_Solution_GscConfig::BACKGROUND_REFRESH_HOOK; |
| 33 |
const LOCK_TRANSIENT_KEY = ABJ_404_Solution_GscConfig::LOCK_TRANSIENT_KEY; |
| 34 |
const LOCK_TTL = ABJ_404_Solution_GscConfig::LOCK_TTL; |
| 35 |
const LAST_FETCH_OPTION_KEY = ABJ_404_Solution_GscConfig::LAST_FETCH_OPTION_KEY; |
| 36 |
const STALE_THRESHOLD = ABJ_404_Solution_GscConfig::STALE_THRESHOLD; |
| 37 |
|
| 38 |
const OAUTH_AUTH_URL = ABJ_404_Solution_GscConfig::OAUTH_AUTH_URL; |
| 39 |
const OAUTH_TOKEN_URL = ABJ_404_Solution_GscConfig::OAUTH_TOKEN_URL; |
| 40 |
const API_BASE_URL = ABJ_404_Solution_GscConfig::API_BASE_URL; |
| 41 |
const SCOPE = ABJ_404_Solution_GscConfig::SCOPE; |
| 42 |
|
| 43 |
/** Base URL of the centralized OAuth proxy Worker. */ |
| 44 |
const CENTRALIZED_AUTH_URL = ABJ_404_Solution_GscConfig::CENTRALIZED_AUTH_URL; |
| 45 |
|
| 46 |
const CENTRALIZED_CALLBACK_SECRET_TRANSIENT_PREFIX = ABJ_404_Solution_GscConfig::CENTRALIZED_CALLBACK_SECRET_TRANSIENT_PREFIX; |
| 47 |
const CENTRALIZED_CALLBACK_SECRET_TTL = ABJ_404_Solution_GscConfig::CENTRALIZED_CALLBACK_SECRET_TTL; |
| 48 |
|
| 49 |
/** @var ABJ_404_Solution_GscOAuthTokenStore */ |
| 50 |
private $oauthStore; |
| 51 |
|
| 52 |
/** @var ABJ_404_Solution_GscSearchAnalyticsClient */ |
| 53 |
private $searchAnalytics; |
| 54 |
|
| 55 |
/** @var ABJ_404_Solution_GscAdminSectionRenderer */ |
| 56 |
private $renderer; |
| 57 |
|
| 58 |
/** @param ABJ_404_Solution_Logging $logger */ |
| 59 |
public function __construct($logger) { |
| 60 |
$this->oauthStore = new ABJ_404_Solution_GscOAuthTokenStore(); |
| 61 |
$this->searchAnalytics = new ABJ_404_Solution_GscSearchAnalyticsClient($logger, $this->oauthStore); |
| 62 |
$this->renderer = new ABJ_404_Solution_GscAdminSectionRenderer($this->oauthStore, $this->searchAnalytics); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* OAuth credentials, token lifecycle, integration state, and last-error storage. |
| 67 |
* |
| 68 |
* @return ABJ_404_Solution_GscOAuthTokenStore |
| 69 |
*/ |
| 70 |
public function oauthStore(): ABJ_404_Solution_GscOAuthTokenStore { |
| 71 |
return $this->oauthStore; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Search Analytics querying, cache reads/writes, fetch locking, and background refresh. |
| 76 |
* |
| 77 |
* @return ABJ_404_Solution_GscSearchAnalyticsClient |
| 78 |
*/ |
| 79 |
public function searchAnalytics(): ABJ_404_Solution_GscSearchAnalyticsClient { |
| 80 |
return $this->searchAnalytics; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Renders the GSC admin settings/status card. |
| 85 |
* |
| 86 |
* @return ABJ_404_Solution_GscAdminSectionRenderer |
| 87 |
*/ |
| 88 |
public function renderer(): ABJ_404_Solution_GscAdminSectionRenderer { |
| 89 |
return $this->renderer; |
| 90 |
} |
| 91 |
} |
| 92 |
|