<?php

    namespace App\System\Basic;

    class beCache {
        static $bePath = "",$bePrefix = "";

        //@ioncube.dk beEncrypt("be_diyocp","beSetParams") -> "a85b4e98a32f2ed0241050fe3c935f6f" RANDOM
        public static function beSetParams($path = "",$prefix = "be"){   
            self::$bePath = BE_APPPATH.$path;
            self::$bePrefix = $prefix;
        }
        //@ioncube.dk beEncrypt("be_diyocp","beGetCache") -> "a19a50e43230728c52b083e664be3acf" RANDOM
        public static function beGetCache($name = ""){
            $file = self::$bePath."/".$name.".".self::$bePrefix."cache".".php";
            return file_get_contents($file);
        }
        //@ioncube.dk beEncrypt("be_diyocp","beCacheExist") -> "5ddf35003c5c3c2060f52f84c813dd90" RANDOM
        public static function beCacheExist($name = ""){
            $file = self::$bePath."/".$name.".".self::$bePrefix."cache".".php";
            return file_exists($file);
        }
        //@ioncube.dk beEncrypt("be_diyocp","beSetCache") -> "8a8265691f0d2b18e7a56a5922863b21" RANDOM
        public static function beSetCache($name = "",$value = ""){
            file_put_contents(self::$bePath."/".$name.".".self::$bePrefix."cache".".php",$value);
        }
        //@ioncube.dk beEncrypt("be_diyocp","beClearCache") -> "e99ea5bbba599e3dbcf772e25a871a9b" RANDOM
        public function beClearCache($type = "view"){
            switch($type){
                case "view" :
                    foreach(glob(BE_APPPATH."resources/cache/views/*") as $file){
                        if(strpos($file,".") !== false){
                            unlink($file);   
                        }
                    }
                    break;
                case "view_compiled" :
                    foreach(glob(BE_APPPATH."resources/cache/views/compiled/*") as $file){
                        if(strpos($file,".") !== false){
                            unlink($file);   
                        }
                    }
                    break;
            }
        }
        //@ioncube.dk beEncrypt("be_diyocp","beDeleteCache") -> "030380647a2e7a930a005f89ddaecbf4" RANDOM
        public static function beDeleteCache($names){
            if(is_string($names)){
                $names = [$names];
            }
            foreach($names as $name){
                unlink(self::$bePath."/".$name.".".self::$bePrefix."cache".".php");
            }
        }
    }
?>