Uname: Linux premium294.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
Software: LiteSpeed
PHP version: 8.1.32 [ PHP INFO ] PHP os: Linux
Server Ip: 104.21.64.1
Your Ip: 216.73.216.223
User: mjbynoyq (1574) | Group: mjbynoyq (1570)
Safe Mode: OFF
Disable Function:
NONE

name : class-fw-access-key.php
<?php if (!defined('FW')) die('Forbidden');

/**
 * Used in public callbacks to allow call only from known caller
 * 
 * For e.g. Inside some class is created an instance of FW_Access_Key with unique key 'whatever',
 * so nobody else can create another instance with same key, only that class owns that unique key.
 * Some public callback (function or method) that wants to allow to be called only by that class,
 * sets an requirement that some parameter should be an instance on FW_Access_Key and its key should be 'whatever'
 * 
 * function my_function(FW_Access_Key $key, $another_parameter) {
 *  if ($key->get_key() !== 'whatever') {
 *      trigger_error('Call denied', E_USER_ERROR);
 *  }
 * 
 *  //...
 * }
 */
final class FW_Access_Key
{
	private static $created_keys = array();

	private $key;
	
	final public function get_key()
	{
		return $this->key;
	}

	/**
	 * @param string $unique_key unique
	 */
	final public function __construct($unique_key)
	{
		if (isset(self::$created_keys[$unique_key])) {
			trigger_error('Key "'. $unique_key .'" already defined', E_USER_ERROR);
		}
		
		self::$created_keys[$unique_key] = true;
		
		$this->key = $unique_key;
	}
}
© 2025 XylotrechusZ