Calling URI * */ public function __construct($url){ $this->page = isset($url['page']) ? $url['page'] : ''; $this->page = preg_match('/^@[a-z]+$/', $this->page) ? substr($this->page, 1) : null; } /* Generate _SERVER.js * */ public function server(){ header('Content-Type: text/javascript; charset=utf-8'); echo "window._SERVER = ".json_encode([ 'session' => [ 'name' => $_SESSION['CAS']['login'], 'connected' => isset($_SESSION['AUTH']) ? count($_SESSION['AUTH']) > 0 : false, 'departments' => array_map(function($d){ return [ 'id' => $d['idDep'], 'label' => $d['labelDep']]; }, $_SESSION['AvailableDepartments']), 'department_id' => $_SESSION['CurrentDepartmentId'], 'version' => $_SESSION['VERSION'] ] ])."\n"; } /* Manage bundle hash * */ public function bundle(){ if( is_null($this->page) ) include __PUBLIC__.'/page/404.php'; /* (1) Extract /public_html/js/ all .js files */ $js_scripts = glob(__PUBLIC__.'/js/bundle/'.$this->page.'@*.js'); /* (2) If match pattern 'bundle@home@*.js' */ foreach($js_scripts as $fname){ $bname = basename($fname); // if match -> load it and exit header("Location: /js/bundle/$bname"); die(); } /* (3) If nothing found */ include __PUBLIC__.'/page/404.php'; } /* POST-CALL * */ public function __destruct(){ } }