upgrade all with dice compatible
This commit is contained in:
+32
-26
@@ -6,21 +6,21 @@
|
||||
Desc. : Class cache css dan js aplikasi
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : March 16th, 2008.
|
||||
Last Modified : August 19th, 2026.
|
||||
Last Modified : August 21st, 2026.
|
||||
|
||||
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
//OK
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\webapp\Data;
|
||||
|
||||
use flight\Engine;
|
||||
use FilesystemIterator;
|
||||
use MatthiasMullie\Minify;
|
||||
use SplFileInfo;
|
||||
use \flight\Engine;
|
||||
use \flight\Session;
|
||||
use \FilesystemIterator;
|
||||
use \MatthiasMullie\Minify;
|
||||
use \SplFileInfo;
|
||||
|
||||
final class Cache {
|
||||
private $__cachedir = "";
|
||||
@@ -31,15 +31,16 @@ final class Cache {
|
||||
private $__rootdir = "";
|
||||
private $__ini = [];
|
||||
protected Engine $app;
|
||||
protected Session $session;
|
||||
protected array $__asset = [];
|
||||
|
||||
public function __construct(?Engine $app = null, array $asset = []) {
|
||||
$this->app = (empty($app) === true) ? Flight::app() : $app;
|
||||
$this->__asset = $asset;
|
||||
$rootdir = (defined('PROJECT_ROOT')) ? PROJECT_ROOT : $this->app->get('flight.root_dir');
|
||||
public function __construct(Engine $app, Session $session) {
|
||||
$this->app = $app;
|
||||
$this->session = $session;
|
||||
$rootdir = (defined('PROJECT_ROOT')) ? PROJECT_ROOT : $this->app->get('app.project_root');
|
||||
$this->__cachedir = $rootdir . '/public/chunks/';
|
||||
$this->__localedir = $rootdir . '/app/locale/';
|
||||
$this->__jsapp = $rootdir . '/app/scripts/';
|
||||
$this->__localedir = $rootdir . '/app/Scripts/locale/';
|
||||
$this->__jsapp = $rootdir . '/app/Scripts/';
|
||||
$this->__cssdir = __DIR__ . '/../../assets/css/';
|
||||
$this->__jsdir = __DIR__ . '/../../assets/js/';
|
||||
$this->__rootdir = $rootdir . '/';
|
||||
@@ -54,7 +55,11 @@ final class Cache {
|
||||
} else $this->__ini = parse_ini_file($this->__cachedir . "cache.ini", true);
|
||||
}
|
||||
|
||||
private function gen_file($mode = "index", $type = "css") {
|
||||
public function set_asset(array $asset = []): void {
|
||||
$this->__asset = $asset;
|
||||
}
|
||||
|
||||
private function gen_file(string $mode = "index", string $type = "css"): array {
|
||||
$itime = 0;
|
||||
$afile = [];
|
||||
if ($type == "css") {
|
||||
@@ -65,8 +70,8 @@ final class Cache {
|
||||
$afile[] = $_file->getRealPath();
|
||||
$itime += $_file->getMTime();
|
||||
}
|
||||
if (is_dir($this->__rootdir . 'app/css/')) {
|
||||
$iterator = new FilesystemIterator($this->__rootdir . 'app/css/', FilesystemIterator::SKIP_DOTS);
|
||||
if (is_dir($this->__rootdir . 'app/Styles/')) {
|
||||
$iterator = new FilesystemIterator($this->__rootdir . 'app/Styles/', FilesystemIterator::SKIP_DOTS);
|
||||
foreach ($iterator as $_file) {
|
||||
if ($_file->isFile()) {
|
||||
$afile[] = $_file->getRealPath();
|
||||
@@ -83,7 +88,7 @@ final class Cache {
|
||||
$itime += $_file->getMTime();
|
||||
}
|
||||
// add locale file
|
||||
$ljs = ($this->app->session()->get('__WEB_USER')['LOCALE'] ?? $this->app->session()->get('__WEB_APP')['DEF_LOCALE']).'.js';
|
||||
$ljs = ($this->session->get('__WEB_USER')['LOCALE'] ?? $this->session->get('__WEB_APP')['DEF_LOCALE']).'.js';
|
||||
if (is_dir($this->__localedir)) {
|
||||
$iterator = new \FilesystemIterator($this->__localedir, \FilesystemIterator::SKIP_DOTS);
|
||||
foreach ($iterator as $_file) {
|
||||
@@ -97,7 +102,8 @@ final class Cache {
|
||||
if ($mode === 'index') {
|
||||
if (is_dir($this->__jsapp)) {
|
||||
$dirIterator = new \RecursiveDirectoryIterator($this->__jsapp, \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$iterator = new \RecursiveIteratorIterator($dirIterator);
|
||||
$dirFilter = new \RecursiveCallbackFilterIterator($dirIterator, fn($curr, $key, $iter) => !($curr->isDir() && in_array($curr->getFilename(), ['locale'])));
|
||||
$iterator = new \RecursiveIteratorIterator($dirFilter);
|
||||
foreach ($iterator as $_file) {
|
||||
if ($_file->isFile() && !in_array($_file->getFilename(), ['login.js','display.js'])) {
|
||||
$afile[] = $_file->getRealPath();
|
||||
@@ -116,7 +122,7 @@ final class Cache {
|
||||
return [ $afile, $itime ];
|
||||
}
|
||||
|
||||
private function create_cache($type = "css", $afile = [], $cachefile = "") {
|
||||
private function create_cache(string $type = "css", array $afile = [], string $cachefile = ""): void {
|
||||
$contents = ''; $smini = null;
|
||||
$bpublic = ($this->app->request()->ip === '127.0.0.1') ? false : true;
|
||||
if ($bpublic == true) {
|
||||
@@ -139,7 +145,7 @@ final class Cache {
|
||||
file_put_contents($this->__cachedir . $cachefile, $contents);
|
||||
}
|
||||
|
||||
private function save_ini() {
|
||||
private function save_ini(): void {
|
||||
$content = "";
|
||||
foreach ($this->__ini as $key => $elem) {
|
||||
$content .= ($content==""?"":"\n"). "[".$key."]\n";
|
||||
@@ -151,7 +157,7 @@ final class Cache {
|
||||
file_put_contents($this->__cachedir . "cache.ini", $content);
|
||||
}
|
||||
|
||||
public function Cache($mode = "index") {
|
||||
public function Cache(string $mode = "index"): array {
|
||||
$is_modif = false;
|
||||
foreach (['css','js','app'] as $type) {
|
||||
[ $afile, $lastmod ] = $this->gen_file($mode, $type);
|
||||
@@ -174,17 +180,17 @@ final class Cache {
|
||||
}
|
||||
}
|
||||
|
||||
$session = $this->app->session();
|
||||
$aoption = $session->get('__WEB_APP');
|
||||
$auser = $session->get('__WEB_USER');
|
||||
$aoption = $this->session->get('__WEB_APP');
|
||||
$auser = $this->session->get('__WEB_USER');
|
||||
$nonce = $this->app->get('csp_nonce');
|
||||
$islog = user_logged($this->session);
|
||||
$_secret = $aoption['APP_CODE'] .";". $aoption['APP_SID'] .";". $this->app->request()->getVar('HTTP_HOST') .";". "http://".$this->app->request()->getVar('HTTP_HOST') .";". isMobile() .";". ($aoption['AUTH_LEVEL']?$aoption['AUTH_LEVEL']:0);
|
||||
$_suser = (user_logged()) ? $auser['Username'] .";". $auser['UserID'] .";". $auser['Grup_MenuID'] .";". $auser['Level'] : "nobody;999;999;9";
|
||||
$_suser = ($islog) ? $auser['Username'] .";". $auser['UserID'] .";". $auser['Grup_MenuID'] .";". $auser['Level'] : "nobody;999;999;9";
|
||||
|
||||
$acache['JSX'][] = '<script nonce="'.$nonce.'" type="text/javascript">';
|
||||
$acache['JSX'][] = 'FoniaJS.setConfig("'.base64_encode($_secret).'", "'.base64_encode($_suser).'");';
|
||||
$acache['JSX'][] = '$(document).ready(function(){';
|
||||
if (user_logged()) $acache['JSX'][] = 'FoniaJS.loadMenu();';
|
||||
if ($islog) $acache['JSX'][] = 'FoniaJS.loadMenu();';
|
||||
$acache['JSX'][] = '});';
|
||||
$acache['JSX'][] = '</script>';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user