*/ final class WebsitePushHandler implements PushEndpointHandlerInterface { /** * Fields the shared apply dereferences unconditionally; a payload missing any * of them is incomplete and rejected before the apply runs. * * @since 4.3.0 * @var string[] */ const REQUIRED_FIELDS = array( 'onboardingStatus', 'contractStatus', 'adsServing', 'createdAt' ); /** * {@inheritDoc} * * @since 4.3.0 * @return string */ public function endpoint() { return 'website'; } /** * {@inheritDoc} * * @since 4.3.0 * @return string */ public function event_type() { return 'wordpress.website.updated'; // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText -- Actirise API event-type identifier. } /** * {@inheritDoc} * * @since 4.3.0 * @return int[] */ public function supported_versions() { return array( 1 ); } /** * Apply a website-status update. * * The payload must be an object carrying at least the fields the shared apply * reads unconditionally ({@see self::REQUIRED_FIELDS}); anything else is a * schema error rejected with a 400 by the controller. Rejecting an incomplete * payload also guards the reused writer: an empty argument makes * check_website_status() fetch from the API (the page-load GET this story * removes), so a push must never reach it empty. * * @since 4.3.0 * @param mixed $data The website resource payload (contract §5.4). * @return bool True when the update was applied. */ public function apply( $data ) { if ( ! is_array( $data ) ) { return false; } foreach ( self::REQUIRED_FIELDS as $field ) { if ( ! isset( $data[ $field ] ) ) { return false; } } /** @var array $data The verified website resource (contract §5.4). */ AdminCore::check_website_status( $data ); return true; } }