Files
ulthon_admin/app/admin/controller/xhprof/Watch.php

73 lines
1.9 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\admin\controller\xhprof;
use app\common\controller\AdminController;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnotation;
use think\App;
/**
* XHProf 函数监控规则管理
* regex 为 PCRE对被调用函数名匹配保存前校验编译合法性
* 防止非法正则打爆导入任务的规则编译。
*
* @ControllerAnnotation(title="XHProf 函数监控规则")
*/
class Watch extends AdminController
{
use \app\admin\traits\Curd {
\app\admin\traits\Curd::add as curdAdd;
\app\admin\traits\Curd::edit as curdEdit;
}
public function __construct(App $app)
{
parent::__construct($app);
$this->model = new \app\admin\model\XhprofWatch();
$this->assign('select_list_status', $this->model::SELECT_LIST_STATUS, true);
}
/**
* @NodeAnotation(title="添加")
*/
public function add()
{
if ($this->request->isPost()) {
$this->validateWatchRegex((string) $this->request->post('regex', ''));
}
return $this->curdAdd();
}
/**
* @NodeAnotation(title="编辑")
*/
public function edit($id)
{
if ($this->request->isPost()) {
$this->validateWatchRegex((string) $this->request->post('regex', ''));
}
return $this->curdEdit($id);
}
/**
* 校验 PCRE 正则合法性(与导入任务 compileWatchRegexes 同一判据).
*/
protected function validateWatchRegex(string $regex): void
{
if ($regex === '') {
$this->error('正则不能为空');
}
error_clear_last();
if (@preg_match($regex, '') === false) {
$error = error_get_last();
$message = $error !== null ? $error['message'] : preg_last_error_msg();
$this->error('正则非法(必须带定界符,如 ~think\\\\db\\\\.*~' . $message);
}
}
}