<?php
namespace Modules\Admin\Server; class Model extends \App\Mvc\ModelAbstract { public function getDirInformation($dir) { $ret = [ "totalSize" => 0, "totalItems" => 0, "hasData" => false, ]; if (!is_dir($dir)) { return $ret; } $dir = cleanPath($dir); foreach (scandir($dir) as $item) { $file = "$dir/$item"; if (in_array($item, ['.', '..'])) { continue; } if (is_dir($file)) { $data = $this->getDirInformation($file); $ret['totalSize'] += $data['totalSize']; $ret['totalItems'] += $data['totalItems']; $ret['hasData'] = $ret['hasData'] || $data['hasData']; } else { $ret['totalSize'] += filesize($file); $ret['totalItems'] ++; $ret['hasData'] = true; } } return $ret; } public function smarty_clearCache() { global $CFG; $smartyCompiledPath = $CFG['thirdParties']['smarty']['pathToCompiledTemplates']; return \Engine\Dir::delete($smartyCompiledPath); } public function smarty_getInformation() { global $CFG; $smartyCompiledPath = $CFG['thirdParties']['smarty']['pathToCompiledTemplates']; return $this->getDirInformation($smartyCompiledPath); } public function cachedRequests_clearCache() { global $CFG; $cachedRequests = $CFG['paths']['files'].'cachedRequests'; return \Engine\Dir::deleteContents($cachedRequests); } public function cachedRequests_getInformation() { global $CFG; $cachedRequests = $CFG['paths']['files'].'cachedRequests'; return $this->getDirInformation($cachedRequests); } public function js_clearCache() { global $CFG; $pathToJs = $CFG['paths']['files'].'public/js/'; return \Engine\Dir::deleteContents($pathToJs); } public function js_getInformation() { global $CFG; $pathToJs = $CFG['paths']['files'].'public/js/'; return $this->getDirInformation($pathToJs); } public function css_clearCache() { global $CFG; $pathToCss = $CFG['paths']['files'].'public/css/'; return \Engine\Dir::deleteContents($pathToCss); } public function css_getInformation() { global $CFG; $pathToCss = $CFG['paths']['files'].'public/css/'; return $this->getDirInformation($pathToCss); } public function fullDisk_clearCache() { return \Engine\Cache\General::getInstance('disk')->flush(); } public function fullDisk_getInformation() { $disk = new \Engine\Cache\Disk(); return $this->getDirInformation($disk->getPath()); } public function opcache_clearCache() { if (function_exists("opcache_reset")) { return opcache_reset(); } return true; } public function opcache_getInformation() { $ret = [ "totalSize" => 0, "totalItems" => 0, "hasData" => false, "hitRate" => 0.0, ]; if (function_exists("opcache_get_status")){ $opcacheStatus = opcache_get_status(); $ret['totalSize'] = $opcacheStatus['memory_usage']['used_memory']; $ret['totalItems'] = $opcacheStatus['opcache_statistics']['num_cached_scripts']; $ret['hasData'] = true; $ret['hitRate'] = $opcacheStatus['opcache_statistics']['opcache_hit_rate']; } return $ret; } public function apcu_clearCache() { if (function_exists("apcu_clear_cache")) { return apcu_clear_cache(); } return true; } public function apcu_getInformation() { $ret = [ "totalSize" => 0, "totalItems" => 0, "hasData" => false, "hitRate" => 0.0, ]; if (function_exists("apcu_cache_info")) { $apcuInfo = apcu_cache_info(); foreach ($apcuInfo['cache_list'] as $item) { $ret['totalItems'] ++; $ret['totalSize'] += $item['mem_size']; } if ($ret['totalItems']) { $ret['hasData'] = true; } if ($apcuInfo['num_hits'] + $apcuInfo['num_misses']) { $ret['hitRate'] = ($apcuInfo['num_hits'] / ($apcuInfo['num_hits'] + $apcuInfo['num_misses']) ) * 100; } } return $ret; } }