*/ final class CmpConfigPushHandler implements PushEndpointHandlerInterface { /** * {@inheritDoc} * * @since 4.3.0 * @return string */ public function endpoint() { return 'cmp-config'; } /** * {@inheritDoc} * * @since 4.3.0 * @return string */ public function event_type() { return 'wordpress.cmp_config.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 pushed configuration. * * Two rejections, both answered with a `400` that leaves the event unmarked * so the API can redeliver: * * - a payload that is not the documented envelope, which is a schema error; * - a push landing on an install that is not enrolled, which is a mistake on * the sending side. Applying it would rewrite the consent configuration of * a site that never opted in, and the `400` puts the signal where the * mistake is. * * Everything past that — the version comparison and the write — belongs to * {@see \Actirise\Includes\FastCmp\ConfigSync::apply_pushed()}, which owns the * held version and the fingerprint the comparison needs. Keeping it there is * what lets the push, the reconciliation read and the save leave identical * state behind. * * @since 4.3.0 * @param mixed $data The event payload. * @return bool */ public function apply( $data ) { if ( ! is_array( $data ) || ! isset( $data['version'] ) || ! is_numeric( $data['version'] ) ) { return false; } // `config` is always present on the wire — the operation keeps null values // rather than skipping them — so its absence is a malformed payload, not a // configuration the API does not hold. if ( ! array_key_exists( 'config', $data ) ) { return false; } if ( ! ConfigSync::armed() ) { return false; } $sync = new ConfigSync(); return $sync->apply_pushed( $data ); } }