Files
shop-platform/src/app/event/diy/DiyViewUtils.php
2025-10-29 15:32:26 +08:00

46 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace app\event\diy;
use ReflectionClass;
use ReflectionException;
/**
* 自定义模板组件渲染
*/
class DiyViewUtils
{
/**
* 行为扩展的执行入口必须是run
* @param $data
* @return mixed | void
* @throws ReflectionException
*/
public function handle($data)
{
$port = [ 'app', 'addon' ];
if (!empty($data[ 'name' ])) {
$class_name = '';
$is_exist = false;
foreach ($port as $k => $v) {
if (!empty($data[ 'addon_name' ])) {
$class_name = $v . '\\' . $data[ 'addon_name' ] . '\\component\\controller\\' . $data[ 'name' ];
} else {
$class_name = $v . '\\component\\controller\\' . $data[ 'name' ];
}
if (class_exists($class_name)) {
$is_exist = true;
break;
}
}
if ($is_exist) {
$class = new ReflectionClass($class_name);
$instance = $class->newInstanceArgs();
return $instance->design();
} else {
var_dump("not found" . $class_name);
}
}
}
}