$context Mutated in place by the build's stages. * @return array{bytes: int|null, source: string} */ public static function forSubpage(string $subpage, array &$context): array { if (!ABJ_404_Solution_AdminTableResponseParts::rendersTablePart($subpage)) { return self::noSize(self::SOURCE_SUBPAGE_UNSUPPORTED); } try { $view = function_exists('abj_service_optional') ? abj_service_optional('view') : null; $viewReadService = function_exists('abj_service_optional') ? abj_service_optional('view_read_service') : null; if (!is_object($view) || !is_object($viewReadService)) { return self::noSize(self::SOURCE_SERVICES_UNAVAILABLE); } $tableResponse = ABJ_404_Solution_AdminTableResponseParts::build( array( 'part' => 'table', 'subpage' => $subpage, 'view' => $view, 'viewReadService' => $viewReadService, 'queryTimeoutSeconds' => self::QUERY_BUDGET_SECONDS, ), $context ); // Through the SAME encoder the endpoint emits with, not a raw // json_encode(). A payload the encoder recovers -- substituted // invalid UTF-8, a partial-output fallback -- is one the endpoint // really would have delivered, and measuring it with json_encode() // reports `false` and throws away the size on exactly the degraded // sites this measurement exists to explain. An error envelope is // the one strategy that is NOT a table, so its bytes are not the // number being asked for. $encoded = ABJ_404_Solution_JsonResponseEncoder::encode($tableResponse); if (!$encoded->carriesPayload() || strlen($encoded->json()) === 0) { return self::noSize(self::SOURCE_ENCODE_FAILED); } return array('bytes' => strlen($encoded->json()), 'source' => self::SOURCE_MEASURED); } catch (Throwable $e) { // Unconditional; abj404_logPhpFallback() is defined at plugin // entry, before any class here can be autoloaded. abj404_logPhpFallback( 'ajax-checkpoint', 'Table response-size measurement failed: ' . $e->getMessage()); return self::noSize(self::SOURCE_BUILD_FAILED); } } /** * The no-size answer, carrying the reason it is the answer. * * @return array{bytes: int|null, source: string} */ private static function noSize(string $reason): array { return array('bytes' => null, 'source' => $reason); } }