<?php

namespace Helpers\Cache;

class WinCache
{
    
    public function __construct()
    {
    }

    /**
     * variableTest
     *
     * @return bool
     */
    public static function variableTest() : bool
    {
        // TODO changer quand PHP à jour
        // return false;
        if (!\extension_loaded('wincache') || (isset($_SESSION['environnement']) && $_SESSION['environnement'] == 'nonregression')) {
            return true;
        }
        
        return ($_SESSION['_debug']=='true')?true:false;
    }

        
    /**
     * surchargeGetUcache
     *
     * @param  string $key
     * @return mixed
     */
    public static function surchargeGetUcache(string $key)
    {
        if (\Helpers\Cache\WinCache::variableTest() == true) {
            return [];
        } else {
            return \wincache_ucache_get($key);
        }
    }
    
    /**
     * surchargeSetUcache
     *
     * @param  string $key
     * @param  mixed $value
     * @param  mixed $ttl
     * @return bool
     */
    public static function surchargeSetUcache(string $key, $value, $ttl = 0) : bool
    {
        if (\Helpers\Cache\WinCache::variableTest() == true) {
            return true;
        } else {
            return \wincache_ucache_set($key, $value, $ttl);
        }
    }
    
    /**
     * surchargeUcacheExists
     *
     * @param  string $key
     * @return bool
     */
    public static function surchargeUcacheExists(string $key)
    {
        if (\Helpers\Cache\WinCache::variableTest() == true) {
            return false;
        } else {
            return \wincache_ucache_exists($key);
        }
    }
    
    /**
     * surchargeDeleteUcache
     *
     * @param  string $key
     * @return bool
     */
    public static function surchargeDeleteUcache(string $key) : bool
    {
        if (\Helpers\Cache\WinCache::variableTest() == true) {
            return false;
        } else {
            return \wincache_ucache_delete($key);
        }
    }
}
