common.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. use think\angular\Angular;
  3. header('Content-Type: text/html; charset=utf-8;');
  4. ini_set("display_errors", "On");
  5. error_reporting(E_ALL | E_STRICT);
  6. // 开始时间
  7. $start_time = microtime(true);
  8. require '../src/Angular.php';
  9. // 配置
  10. $config = [
  11. 'debug' => true, // 是否开启调试, 开启调试会实时生成缓存
  12. 'tpl_path' => './view/', // 模板根目录
  13. 'tpl_suffix' => '.html', // 模板后缀
  14. 'tpl_cache_path' => './cache/', // 模板缓存目录
  15. 'tpl_cache_suffix' => '.php', // 模板后缀
  16. 'attr' => 'php-', // 标签前缀
  17. 'max_tag' => 10000, // 标签的最大解析次数
  18. ];
  19. // 自定义扩展, 打印变量的值
  20. Angular::extend('dump', function ($content, $param, $angular) {
  21. $old = $param['html'];
  22. $new = '<pre>';
  23. unset($param[0], $param[1], $param[2], $param[3], $param[4], $param[5]);
  24. $new .= '<?php var_dump(' . $param['value'] . '); ?>';
  25. // var_dump($angular->config);
  26. $new .= '</pre>';
  27. return str_replace($old, $new, $content);
  28. });
  29. // 自定义扩展, 变量+1
  30. Angular::extend('inc', function ($content, $param, $angular) {
  31. $old = $param['html'];
  32. $new = '<?php ' . $param['value'] . '++; ?>';
  33. $new .= Angular::removeExp($old, $param['exp']);
  34. return str_replace($old, $new, $content);
  35. });
  36. // 自定义扩展, 变量-1
  37. Angular::extend('dec', function ($content, $param, $angular) {
  38. $old = $param['html'];
  39. $new = '<?php ' . $param['value'] . '--; ?>';
  40. $new .= Angular::removeExp($old, $param['exp']);
  41. return str_replace($old, $new, $content);
  42. });
  43. function load($key)
  44. {
  45. return include './data/' . $key . '.php';
  46. }
  47. // 实例化
  48. $view = new Angular($config);
  49. // 导航
  50. $navs = load('navs');
  51. $view->assign('navs', $navs);
  52. $view->assign('start_time', $start_time);