DiyViewUtils.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // +---------------------------------------------------------------------+
  3. // | NiuCloud | [ WE CAN DO IT JUST NiuCloud ]  |
  4. // +---------------------------------------------------------------------+
  5. // | Copy right 2019-2029 www.niucloud.com  |
  6. // +---------------------------------------------------------------------+
  7. // | Author | NiuCloud <niucloud@outlook.com>  |
  8. // +---------------------------------------------------------------------+
  9. // | Repository | https://github.com/niucloud/framework.git  |
  10. // +---------------------------------------------------------------------+
  11. declare (strict_types = 1);
  12. namespace app\event;
  13. /**
  14. * 自定义模板组件渲染
  15. */
  16. class DiyViewUtils
  17. {
  18. // 行为扩展的执行入口必须是run
  19. public function handle($data)
  20. {
  21. $port = [ 'app', 'addon' ];
  22. if (!empty($data['controller'])) {
  23. $class_name = '';
  24. $is_exist = false;
  25. foreach ($port as $k => $v) {
  26. if (!empty($data['addon_name'])) {
  27. $class_name = $v . '\\' . $data['addon_name'] . '\\component\\controller\\' . $data['controller'];
  28. } else {
  29. $class_name = $v . '\\component\\controller\\' . $data['controller'];
  30. }
  31. if (class_exists($class_name)) {
  32. $is_exist = true;
  33. break;
  34. }
  35. }
  36. if ($is_exist) {
  37. $class = new \ReflectionClass($class_name);
  38. $instance = $class->newInstanceArgs();
  39. return $instance->design();
  40. } else {
  41. var_dump("not found:" . $class_name);
  42. }
  43. }
  44. }
  45. }