ptut-vhost/build/router/controller/js.php

76 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
namespace router\controller;
class js{
private $page;
/* PRE-CALL
*
* @url<String> 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['NAME'],
'connected' => isset($_SESSION['AUTH']) ? count($_SESSION['AUTH']) > 0 : false
]
])."\n";
}
/* Manage bundle hash
*
*/
public function bundle(){
2018-02-20 16:45:02 +00:00
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 */
2018-02-20 16:45:02 +00:00
include __PUBLIC__.'/page/404.php';
}
/* POST-CALL
*
*/
public function __destruct(){
}
}