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/automatewoo/includes/Factory.php
<?php
// phpcs:ignoreFile

namespace AutomateWoo;

/**
 * @class Factory
 * @since 2.9
 */
abstract class Factory {

	/** @var array - must NOT be declared in child class  */
	static $cache = [];

	/** @var string - must be declared in child class */
	static $model;


	/**
	 * Fetches the object type from factories array
	 * @return string
	 */
	static function get_object_type() {

		$class = get_called_class();
		$factories = array_flip( Factories::get_factories() );

		if ( ! isset( $factories[ $class ] ) ) {
			return false;
		}

		return $factories[ $class ];
	}


	/**
	 * @param integer $object_id
	 * @return Model|bool|mixed
	 */
	static function get( $object_id ) {
		$object_id = Clean::id( $object_id );

		if ( ! $object_id ) {
			return false;
		}

		if ( static::is_cached( $object_id ) ) {
			return static::get_cached( $object_id );
		}

		/** @var Model $object */
		$object = new static::$model( $object_id );

		if ( ! $object || ! $object->exists ) {
			static::cache_nonexistent_object( $object_id );
			return false;
		}

		return $object;
	}


	/**
	 * @deprecated
	 * @param $object
	 * @return Model|bool
	 */
	static function load( $object ) {
		wc_deprecated_function( __METHOD__, '5.2.0' );

		return $object;
	}



	/**
	 * Setup cache array for type
	 */
	static function setup_cache() {
		if ( ! isset( self::$cache[ static::get_object_type() ] ) )  {
			self::$cache[ static::get_object_type() ] = [];
		}
	}


	/**
	 * Does the object existing the cache, returns true if the object is false in the cache
	 * @param $object_id
	 * @return bool
	 */
	static function is_cached( $object_id ) {
		static::setup_cache();
		return isset( self::$cache[ static::get_object_type() ][ $object_id ] );
	}


	/**
	 * @param $object_id
	 * @return bool|Model
	 */
	static function get_cached( $object_id ) {
		static::setup_cache();

		if ( ! isset( self::$cache[ static::get_object_type() ][$object_id] ) ) {
			return false;
		}

		return static::$cache[ static::get_object_type() ][ $object_id ];
	}


	/**
	 * Cache the fact that the object does not exist
	 * @param $object_id
	 */
	static function cache_nonexistent_object( $object_id ) {
		static::setup_cache();
		self::$cache[ static::get_object_type() ][ $object_id ] = false;
	}


	/**
	 * @param Model $object
	 */
	static function update_cache( $object ) {
		static::setup_cache();

		if ( ! is_a( $object, 'AutomateWoo\Model' ) ) {
			return;
		}

		static::$cache[ static::get_object_type() ][ $object->get_id() ] = $object;
	}


	/**
	 * @param Model $object
	 */
	static function clean_cache( $object ) {
		static::setup_cache();

		if ( ! is_a( $object, 'AutomateWoo\Model' ) ) {
			return;
		}

		if ( isset( self::$cache[ static::get_object_type() ][ $object->get_id() ] ) ) {
			unset( self::$cache[ static::get_object_type() ][ $object->get_id() ] );
		}

	}


	/**
	 * Clears cache property for object based on new and existing values
	 *
	 * @since 3.4.2
	 * @param Model $object
	 * @param string $prop
	 * @param string $group
	 */
	static function clear_cached_prop( $object, $prop, $group ) {
		if ( isset( $object->original_data[$prop] ) ) {
			Cache::delete( $object->original_data[$prop], $group ); // clear old value, important if the value has changed
		}

		if ( isset( $object->data[$prop] ) ) {
			Cache::delete( $object->data[$prop], $group ); // clear for new value, important for newly created carts for example
		}
	}

}