HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/html/ielts-store/wp-content/plugins/woocommerce-zapier/legacy/Payload/Base/Base.php
<?php

namespace OM4\Zapier\Payload\Base;

use ArrayAccess;
use Countable;
use Iterator;
use IteratorAggregate;
use OM4\Zapier\Exception\IncompletePayloadException;
use OM4\Zapier\Exception\InvalidPropertyException;
use OM4\Zapier\Exception\InvalidTypeException;
use OM4\Zapier\Exception\JsonErrorException;
use OM4\Zapier\Payload\Contract;

defined( 'ABSPATH' ) || exit;

/**
 * All Payload class inherit from this.
 *
 * @deprecated 2.0.0
 */
abstract class Base implements Contract {

	/**
	 * Sanitize & validate properties to proper types to use in a Payload.
	 *
	 * @param   string $key              Name of property to validate.
	 * @param   mixed  $value            The property to validate.
	 * @throws  InvalidTypeException     Type not allowed for accessed property.
	 * @throws  InvalidPropertyException Accessing non-existent property.
	 * @return  void
	 */
	abstract protected function validate( $key, $value );

	/**
	 * Convert the Object to an array.
	 *
	 * @return  array The array representation of the class data.
	 */
	abstract protected function get_properties();

	/**
	 * Convert the Object to an array.
	 *
	 * @return  array The array representation of the class data.
	 */
	final public function to_array() {
		return $this->jsonSerialize();
	}

	/**
	 * Return the object as array and an array of unfilled properties.
	 *
	 * @param   array  $buffer     The array to search for properties with null value.
	 * @param   string $parent_key Parent key name to create dot notation style names.
	 * @return  array              The array of the class data, and The array of missing keys.
	 */
	final protected function proper_array_and_nulls( $buffer, $parent_key = '' ) {
		$nulls = array();
		array_walk(
			$buffer,
			function ( &$value, $key ) use ( &$nulls, $parent_key ) {
				$value = $value instanceof self ? $value->to_array() : $value;
				if ( is_null( $value ) ) {
					$nulls[] = $parent_key . $key;
				} elseif ( is_array( $value ) ) {
					list( , $child_nulls ) = $this->proper_array_and_nulls( $value, $parent_key . $key . '.' );
					$nulls                 = array_merge( $nulls, $child_nulls );
				}
			}
		);
		return array( $buffer, $nulls );
	}

	/**
	 * Convert the Object to JSON string.
	 *
	 * @throws  JsonErrorException Error in JSON conversion.
	 * @return  string             The JSON representation of the class data.
	 */
	final public function to_json() {
		$buffer = json_encode( $this->jsonSerialize() );
		if ( false === $buffer ) {
			throw new JsonErrorException( get_called_class(), json_last_error() );
		}
		return $buffer;
	}

	/**
	 * Getting information how well the object filled with actual data
	 *
	 * @return  bool True if object fully filled, false otherwise.
	 */
	final public function is_complete() {
		list( , $nulls ) = $this->proper_array_and_nulls( $this->get_properties() );
		return empty( $nulls );
	}

	/**
	 * Collecting the properties which left null
	 *
	 * @return  array Array of not filled property names.
	 */
	public function list_unfilled_properties() {
		list( , $nulls ) = $this->proper_array_and_nulls( $this->get_properties() );
		return $nulls;
	}

	/**
	 * Specify data which should be serialized to JSON using the JsonSerializable interface
	 *
	 * @throws IncompletePayloadException Payload not completely filled.
	 * @return mixed                      Data which can be serialized by json_encode.
	 */
	final public function jsonSerialize() {
		list( $buffer, $nulls ) = $this->proper_array_and_nulls( $this->get_properties() );
		if ( ! empty( $nulls ) ) {
			throw new IncompletePayloadException( get_called_class(), $nulls );
		}
		return $buffer;
	}
}