<?phpclass atmjs{Private $path = '/path/to/maps/remote '; The private $id = "must be modified here; Private $scripts = '; Private $debugId = '; Private $status = false; Private $domain = '; Private $isDebug = false; Private $port = 1234; Private $debugPath = '; Private $settings = '; Public Function Import ($id) {$this->id = $id; if (Preg_match ('/^ ([^:]+):([\d]+\.[ \d]+\. [\d]+]/', $id, $m)) {$route = $m [1]. ' /'. $m [2]; } else {return; } $filePath = $this->path. ' /'. $route. '. JSON '; $datas = @file_get_contents ($filePath); if (! $datas) {return; } $datas = Json_decode ($datas, true); if (!isset ($datas [' Settings ']) | |!isset ($datas) | |!isset ($datas [' Maps ']) | |!isset ($datas [' Maps '] [$id]) {RE Turn } $this->settings = $datas [' Settings ']; $this->json = $datas [' Maps '] [$id]; Get domain $this->setdomain (); $this->status = true; } Private Function SetDomain () {$settings = $this->settings; $param = $settings [' Debugparam ']; $debugId = $_request[$param]; If there is debugparam in the URL or post parameter, debug mode if (Isset ($debugId)) {$this->isdebug = true; If the debug parameter value is True, debug with 127.0.0.1//If not, the parameter value is assumed to be the specified debug address if ($debugId = = ' true ' | | empty ($DEBUGID)) { $debugId = $this->debugid = ' 127.0.0.1 '; }else{$debugId = $this->debugid = $debugId; } $port = $this->port = $settings [' Port ']; $domain = '/http '. $debugId. ': ' $port. ' /dev '; $this->debugpath = '/http '. $debugId. ': ' $port. ' /debug '; }else{$domain = $settings [' domain ']; } $this->domain = $domain; Public Function Loadjs () {//If the portal file is a CSS type, the Onlycss field value is True if ($this->json[' onlycss ']) {RE Turn } If there is an error, output an empty string if (! $this->status) {return; }//If it is debug mode if ($this->isdebug) {$DEBUGSRC = $this->debugpath. '? Id= '. $this->id. ' &type=js×tamp= '. Time (); echo implode ("\ n", Array (' <script type= "Text/javascript" id= "Atmjsnode" data-base= "'. $this->domain. ' "Src=" '. $debugSrc. ' " ></script> ', $this->getusetag ())); }else{Echo Implode (", Array ($this->getloadertag (), $this->getmaptag (), $this->getjstags (), $this->getusetag ())); }} Private Function Getusetag () {if (!empty ($this->scripts)) {$scripts = ', '. $this->scripts ; }else{$scripts = "; } $codes = ' Atmjs.use (\ '. $this->id. ') '. $scripts. ') '; Return ' <script type= ' Text/javascript > '. $codes. ' </script> '; } Private Function Getloadertag () {$json = $this->json; $uri = $json [' loader ']; if (!empty ($uri)) {$url = $this->domain. $uri; Return ' <script id= ' Atmjsnode "data-base=" '. $this->domain. ' type= ' text/javascript ' src= ' $url. ' " ></script> '; }else{return '; }} Private Function Getmaptag () {$json = $this->json; $map = $json [' map ']; if (!empty ($map)) {return ' <script type= ' text/javascript ' > '. $json [' Map ']. ' </script> '; }else{return '; }} Private Function Getjstags () {$json = $this->json; $js = $json [' JS ']; $arr = Array (); if (Isset ($js)) {foreach ($js as $uri) {$tag = $this->getjstag ($uri); Array_push ($arr, $tag); } return Implode (", $arr); }else{return '; }} Private Function Getjstag ($uRI) {$url = $this->domain. $uri; Return ' <script type= ' text/javascript "src=" '. $url. ' " ></script> '; The Public function Setjs ($scripts = ") {$this->scripts = $scripts; The Public Function loadcss () {///If there is an error, output an empty string if (! $this->status) {echo '; return;} If it is debug mode if ($this->isdebug) {$DEBUGSRC = $this->debugpath. '? Id= '. $this->id. ' &type=css&domain= '. $this->domain. ' ×tamp= '. Time (); Echo ' <link rel= "stylesheet" type= "Text/css" href= "'. $debugSrc. '/> '; }else{echo $this->getcsstags (); }} Private Function Getcsstags () {$json = $this->json; $css = $json [' CSS ']; $arr = Array (); if (Isset ($css)) {foreach ($css as $uri) {$tag = $this->getcsstag ($uri); Array_push ($arr, $tag); } return Implode (", $arr); }else{return '; }} Private Function Getcsstag ($uri) {$url = $this->domain. $uri; Return ' <link type= ' text/css "rel=" stylesheet "href=" '. $url. '/> '; }}
Examples of Use:
<?php
Require_once ('./atmjs.php ');
$ATMJS = new Atmjs;
$atmjs->import (' User/account:1.0.0/login ');
?>
<!doctype html>
<meta charset= "UTF-8" >
<title>Document</title>
<?php
$atmjs->loadcss ();
?>
<body>
<!--some HTML code-->
Some code
<?php
$scripts = <<<eot
function (Loginexport) {
Some code
}
EOT;
$atmjs->setjs ($scripts);
$atmjs->loadjs ();
?>
</body>
3. Generated page source code:
<!doctype html>
<meta charset= "UTF-8" >
<title>Document</title>
<link type= "Text/css" rel= "stylesheet" href= "Http://cn-style.gcimg.net/static/core/reset/1.0.0/reset_e5b6e95.css"/>
<link type= "Text/css" rel= "stylesheet" href= "Http://cn-style.gcimg.net/static/user/account/1.0.0/account_ 2e2d290.css "/>
<link type= "Text/css" rel= "stylesheet" href= "Http://cn-style.gcimg.net/static/user/account/1.0.0/css/login_ 9fa75f4.css "/>
<body>
<!--some HTML code-->
Some code
<script id= "Atmjsnode" data-base= "http://cn-style.gcimg.net/static" type= "Text/javascript" src= "/HTTP/ Cn-style.gcimg.net/static/lib/loader/1.0.0/loader_aa23401.js "></script>
<script type= "Text/javascript" >atmjs.setmap ({"_alias": {}, "Alias": {"User/account:1.0.0/other/ajax": "/user/ Account/1.0.0/other/ajax_49ac7f5.js "}," pkg ": {}," Cssdeps ": {}});</script>
<script type= "Text/javascript" src= "Http://cn-style.gcimg.net/static/user/account/1.0.0/account_8c2acc1.js" ></script>
<script type= "Text/javascript" src= "Http://cn-style.gcimg.net/static/user/account/1.0.0/exports/login_ 1074d04.js "></script>
<script type= "Text/javascript" >atmjs.use (' User/account:1.0.0/login ', function (Loginexport) {
Some code
}) </script>
</body>
3.3 ATM and background language collaboration PHP class and usage example