HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: /home/mirz4654/public_html/wp-content/plugins/wp-rocket/inc/classes/traits/trait-memoize.php
<?php
namespace WP_Rocket\Traits;

/**
 * Statically store values.
 *
 * @since  3.3
 * @author Grégory Viguier
 */
trait Memoize {

	/**
	 * Store the values.
	 *
	 * @var    array
	 * @since  3.3
	 * @access private
	 * @author Grégory Viguier
	 */
	private static $memoized = [];

	/**
	 * Tell if a value is memoized.
	 *
	 * @since  3.3
	 * @access public
	 * @author Grégory Viguier
	 *
	 * @param  string $method Name of the method.
	 * @param  array  $args   Arguments passed to the parent method. It is used to build a hash.
	 * @return bool
	 */
	final public static function is_memoized( $method, $args = [] ) {
		$hash = self::get_memoize_args_hash( $args );
		return isset( self::$memoized[ $method ][ $hash ] );
	}

	/**
	 * Get a stored value.
	 *
	 * @since  3.3
	 * @access public
	 * @author Grégory Viguier
	 *
	 * @param  string $method Name of the method.
	 * @param  array  $args   Arguments passed to the parent method. It is used to build a hash.
	 * @return mixed
	 */
	final public static function get_memoized( $method, $args = [] ) {
		$hash = self::get_memoize_args_hash( $args );
		return isset( self::$memoized[ $method ][ $hash ] ) ? self::$memoized[ $method ][ $hash ] : null;
	}

	/**
	 * Cache a value.
	 *
	 * @since  3.3
	 * @access public
	 * @author Grégory Viguier
	 *
	 * @param  string $method Name of the method.
	 * @param  array  $args   Arguments passed to the parent method. It is used to build a hash.
	 * @param  mixed  $value  Value to store.
	 * @return mixed          The stored value.
	 */
	final public static function memoize( $method, $args = [], $value = null ) {
		$hash = self::get_memoize_args_hash( $args );

		if ( ! isset( self::$memoized[ $method ] ) ) {
			self::$memoized[ $method ] = [];
		}

		self::$memoized[ $method ][ $hash ] = $value;
		return self::$memoized[ $method ][ $hash ];
	}

	/**
	 * Create a hash based on an array of arguments.
	 *
	 * @since  3.3
	 * @access private
	 * @author Grégory Viguier
	 *
	 * @param  array $args An array of arguments.
	 * @return string
	 */
	final private static function get_memoize_args_hash( $args ) {
		if ( [] === $args ) {
			return 'd751713988987e9331980363e24189ce'; // `md5( json_encode( [] ) )`
		}

		return md5( call_user_func( 'json_encode', $args ) );
	}
}