示例#1
0
namespace infrajs\template;

use infrajs\load\Load;
use infrajs\event\Event;
use infrajs\config\Config;
use infrajs\sequence\Sequence;
use infrajs\path\Path;
use infrajs\path\URN;
use infrajs\view\view;
//Template::$conf['root']=URN::getAbsRoot();
//Sequence::set(Template::$scope, array('~root'), Template::$conf['root']);
Template::$fs['load'] = function ($src) {
    return Load::loadTEXT($src);
};
$fn2 = function ($name = null) {
    return $conf = Config::pub($name);
};
Sequence::set(Template::$scope, array('infra', 'config'), $fn2);
Sequence::set(Template::$scope, array('Config', 'get'), $fn2);
Event::one('Controller.oninit', function () {
    Template::$scope['~conf'] = Config::get();
});
$fn3 = function () {
    return View::getPath();
};
Sequence::set(Template::$scope, array('infra', 'view', 'getPath'), $fn3);
$fn4 = function () {
    return View::getHost();
};
Sequence::set(Template::$scope, array('infra', 'view', 'getHost'), $fn4);
$fn5 = function ($s) {
示例#2
0
文件: js.php 项目: infrajs/config
<?php

use infrajs\load\Load;
use infrajs\config\Config;
use infrajs\router\Router;
use infrajs\ans\Ans;
if (!is_file('vendor/autoload.php')) {
    chdir('../../../');
    require_once 'vendor/autoload.php';
    Router::init();
}
$js = 'if (!window.infra) window.infra={}; if (!window.infrajs) window.infrajs={}; infra.conf=(' . Load::json_encode(Config::pub()) . '); ';
$js .= 'infra.config = function (name){ if(!name)return infra.conf; return infra.conf[name]; };';
$js .= 'window.Config = {}; Config.get = infra.config; Config.conf = infra.conf;';
return Ans::js($js);