public static function run($line) { if (preg_match_all('/(?<start>.*){{\\s*foreach\\s*\\((?<array>[\\w|\\.]+)\\s*as\\s*(?<var>\\w+)(\\s*=>\\s*(?<subVar>\\w+))?\\s*\\)\\s*}}(?<end>.*)/', $line, $matches)) { return Parse::run($matches); } return false; }
public static function run($line) { if (preg_match_all('/(?<start>.*)?{{\\s*include\\((?<file>[\\w.\\/]+)\\)\\s*}}(?<end>.*)/', $line, $matches)) { return Parse::run($matches); } return false; }
public static function run($line) { if (preg_match_all('/(?<start>[^\\{]*)\\s*{{(?<startQuickEsc>{)?\\s*(?<echo>\\w+(\\.\\w+)*)(?<escape>[\\|!](e|escape))?\\s*}}(?<endQuickEsc>})?(?<end>.*)/', $line, $match)) { return Parse::run($match); } return false; }
public static function run($line) { if (preg_match('/(?<start>.*){{\\s*endforeach;\\s*}}(?<end>.*)/', $line, $match)) { return Parse::run($match); } return false; }
public static function run($line) { if (preg_match_all('/(?<start>.*){{\\s*while\\((?<expr>.*)\\)\\s*}}(?<end>.*)/', $line, $matches)) { return Parse::run($matches); } return false; }
public static function run($line) { if (preg_match_all('/(?<start>.*)(?<statement>{{\\s*endif\\s*;\\s*}})(?<end>.*)/', $line, $matches)) { return Parse::run($matches); } return false; }
public static function run($line) { if (preg_match_all('/(?<start>.*){{\\s*(?<beforeInc>\\+\\+|--)?(?<variable>\\w+)(?<afterInc>\\+\\+|--)?\\s*}}(?<end>.*)/', $line, $match)) { if (!empty($match['beforeInc'][0]) || !empty($match['afterInc'][0])) { return Parse::run($match); } else { return false; } } return false; }
//默认配置 /** @constant 要被处理的源代码路径 */ define("CODE_PATH", "./src/obj/"); /** @constant tangram 代码路径 */ define("TANGRAM_PATH", "./src/"); /** @constant Tangram-base 所在目录 */ define("TANGRAM_BASE_DIR", "tangram/"); /** @constant Tangram命名空间 */ define("TANGRAM_NAMESPACE", "baidu"); /** @constant 处理的文件类型 */ define("FILETYPES", ".html,.htm,.js,.tpl"); //处理传进来的参数 $param = isset($argv) ? $argv : $_REQUEST; $paramsHandler = new HandleParams($param); $config = $paramsHandler->run(); //如果用户是通过浏览器访问,则显示web界面。否则为命令行模式 if ($config['type'] == "web") { $uiHandler = new Ui($config); $uiHandler->run(); } if (!empty($config["params"]) || $config['type'] == "commandline") { //解析用户的源代码,提取其中调用Tangram的代码 $parseHandler = new Parse($config); $parseRes = $parseHandler->run(); //分析用户调用的tangram源代码,得到用户需要的tangram模块 $indexHandler = new Index($parseRes, $config); $indexRes = $indexHandler->run(); //将用户用到的tangram模块打包返回给用户 $packHandler = new Pack($indexRes, $config); $packHandler->run(); }
<?php require_once "../../lib/parse.php"; define("TANGRAM_PATH", "../../src/tangram/"); define("CODE_PATH", "../../src/obj/"); define("TANGRAM_PREFIX", "baidu"); $obj = new Parse(array("params" => array())); $obj->run();
public static function run($line) { if (preg_match_all('/(?<start>.*)\\s*{{\\s*if\\s*\\((?<statement>.*)\\s*\\)\\s*}}(?<end>.*)/', $line, $matches)) { return Parse::run($matches); } }
/** * Indique la fin du fichier template. * Une fois appelé, le script parse le fichier template. * * @param integer $no_echo (default: 0) Indique s'il faut afficher le résultat par echo (défault) ou le renvoyer en sortie de fonction * * @return string Retourne le résultat du parsage si $no_echo=1 */ public function End($no_echo = 0) { $this->CurrentBlock = '/'; //On place le chemin à la racine $parse = new Parse($this); return $parse->run($no_echo); }