<commit_before><?php

class kPermissionManager implements kObjectCreatedEventConsumer, kObjectChangedEventConsumer
{
	// -------------------
	// -- Class members --
	// -------------------
		
	const GLOBAL_CACHE_KEY_PREFIX = 'kPermissionManager_'; // Prefix added for all key names stored in the APC cache
	
	private static $map = array(); // Local map of permission items allowed for the current role
	
	const API_ACTIONS_ARRAY_NAME    = 'api_actions';      // name of $map's api actions array
	const API_PARAMETERS_ARRAY_NAME = 'api_parameters';   // name of $map's api parameters array
	const PARTNER_GROUP_ARRAY_NAME  = 'partner_group';    // name of $map's partner group array
	const PERMISSION_NAMES_ARRAY    = 'permission_names'; // name of $map's permission names array
			
	private static $initialized = false; // map already initialized or not
	private static $useCache = true;     // use cache or not
	
	private static $ksUserId = null;
	private static $adminSession = false; // is admin session
	private static $ksPartnerId = null;
	private static $requestedPartnerId = null;
	private static $ksString = null;
	private static $roleIds = null;
	private static $operatingPartnerId = null;
	
	/**
	 * @var Partner
	 */
	private static $operatingPartner = null;
	
	/**
	 * @var kuser
	 */
	private static $kuser = null;
		
	
	// ----------------------------
	// -- Cache handling methods --
	// ----------------------------
	
	
	private static function useCache()
	{
		if (self::$useCache && function_exists('apc_fetch') && function_exists('apc_store'))
		{
			return true;
		}
		return false;	
	}
	
	/**
	 * @param int $roleId
	 * @return cache key name for the given role id
	 */
	private static function getRoleIdKey($roleId, $partnerId)
	{
		if (is_null($roleId)) {
			$roleId = 'null';
		}
		if (is_null($partnerId)) {
			$partnerId = 'null';
		}
		$key = 'role_'.$roleId.'_partner_'.$partnerId;
		return $key;
	}
	
	/**
	 * Get value from cache for the given key
	 * @param string $key
	 */
	private static function getFromCache($key)
	{
		if (!self::useCache())
		{
			return null;
		}
		$key = self::GLOBAL_CACHE_KEY_PREFIX.$key; // add prefix to given key
		$value = apc_fetch($key); // try to fetch from cache
		if ($value) {
			KalturaLog::debug("Found an APC cache value for key [$key]");
			$value = unserialize($value);
			return $value;
		}
		else {
			KalturaLog::debug("No APC cache value found for key [$key]");
			return null;
		}
	}
	
	/**
	 * 
	 * Store given value in cache for with the given key as an identifier
	 * @param string $key
	 * @param string $value
	 */
	private static function storeInCache($key, $value)
	{
		if (!self::useCache())
		{
			return false;
		}
		$key = self::GLOBAL_CACHE_KEY_PREFIX.$key; // add prefix to given key
		$value = serialize($value);
		$success = apc_store($key, $value, kConf::get('apc_cache_ttl')); // try to store in cache
<commit_msg>added TODO comments<commit_after><?php

class kPermissionManager implements kObjectCreatedEventConsumer, kObjectChangedEventConsumer
{
	// -------------------
	// -- Class members --
	// -------------------
		
	const GLOBAL_CACHE_KEY_PREFIX = 'kPermissionManager_'; // Prefix added for all key names stored in the APC cache
	
	private static $map = array(); // Local map of permission items allowed for the current role
	
	const API_ACTIONS_ARRAY_NAME    = 'api_actions';      // name of $map's api actions array
	const API_PARAMETERS_ARRAY_NAME = 'api_parameters';   // name of $map's api parameters array
	const PARTNER_GROUP_ARRAY_NAME  = 'partner_group';    // name of $map's partner group array
	const PERMISSION_NAMES_ARRAY    = 'permission_names'; // name of $map's permission names array
			
	private static $initialized = false; // map already initialized or not
	private static $useCache = true;     // use cache or not
	
	private static $ksUserId = null;
	private static $adminSession = false; // is admin session
	private static $ksPartnerId = null;
	private static $requestedPartnerId = null;
	private static $ksString = null;
	private static $roleIds = null;
	private static $operatingPartnerId = null;
	
	/**
	 * @var Partner
	 */
	private static $operatingPartner = null;
	
	/**
	 * @var kuser
	 */
	private static $kuser = null;
		
	
	// ----------------------------
	// -- Cache handling methods --
	// ----------------------------
	
	
	private static function useCache()
	{
		if (self::$useCache && function_exists('apc_fetch') && function_exists('apc_store'))
		{
			return true;
		}
		return false;	
	}
	
	/**
	 * @param int $roleId
	 * @return cache key name for the given role id
	 */
	private static function getRoleIdKey($roleId, $partnerId)
	{
		if (is_null($roleId)) {
			$roleId = 'null';
		}
		if (is_null($partnerId)) {
			$partnerId = 'null';
		}
		$key = 'role_'.$roleId.'_partner_'.$partnerId;
		return $key;
	}
	
	/**
	 * Get value from cache for the given key
	 * @param string $key
	 */
	private static function getFromCache($key)
	{
		if (!self::useCache())
		{
			return null;
		}
		$key = self::GLOBAL_CACHE_KEY_PREFIX.$key; // add prefix to given key
		$value = apc_fetch($key); // try to fetch from cache
		if ($value) {
			KalturaLog::debug("Found an APC cache value for key [$key]");
			$value = unserialize($value); // TODO: check - serialize/unserialize may not be needed as APC can save full objects
			return $value;
		}
		else {
			KalturaLog::debug("No APC cache value found for key [$key]");
			return null;
		}
	}
	
	/**
	 * 
	 * Store given value in cache for with the given key as an identifier
	 * @param string $key
	 * @param string $value
	 */
	private static function storeInCache($key, $value)
	{
		if (!self::useCache())
		{
			return false;
		}
		$key = self::GLOBAL_CACHE_KEY_PREFIX.$key; // add prefix to given key
		$value = serialize($value); // TODO: check - serialize/unserialize may not be needed as APC can save full objects
		$success = apc_store($key, $value, kConf::get('apc_cache_ttl')); // try to store in cache

{'fraction_non_alphanumeric': 0.14748081414748082, 'fraction_numerical': 0.0, 'mean_word_length': 2.957095709570957, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1878055', 'n_tokens_mistral': 2013, 'n_tokens_neox': 1834, 'n_words': 588}