config = $this->validate_config( $config ); } /** * Returns an associative event containing the event attributes. * * @since 1.18.0. * * @return array The configuration in JSON-serializable format. */ #[\ReturnTypeWillChange] public function jsonSerialize() { return $this->config; } /** * Returns the measurement event configuration. * * @since 1.18.0. * * @return array The config. */ public function get_config() { return $this->config; } /** * Validates the configuration keys and value types. * * @since 1.18.0. * * @param array $config The event's configuration. * @return array The event's configuration. * @throws Exception Thrown when invalid keys or value type. */ private function validate_config( $config ) { $valid_keys = array( 'action', 'selector', 'on', 'metadata', ); foreach ( $config as $key => $value ) { if ( ! in_array( $key, $valid_keys, true ) ) { throw new Exception( 'Invalid configuration parameter: ' . $key ); } } if ( ! array_key_exists( 'metadata', $config ) ) { $config['metadata'] = null; } if ( array_key_exists( 'on', $config ) && 'DOMContentLoaded' === $config['on'] ) { $config['selector'] = ''; } foreach ( $valid_keys as $key ) { if ( ! array_key_exists( $key, $config ) ) { throw new Exception( 'Missed configuration parameter: ' . $key ); } } return $config; } }