一、open_basedir 不能再写 /tmp(7.4 池子把白名单收紧,Monolog/EasyWeChat 会抛异常)
- addons/shopro/library/Wechat.php:easywechat 日志改到 runtime/easywechat/
- addons/epay/library/Yansongda/Supports/Logger.php:epay 日志默认路径改到 runtime/epay/
- application/admin/library/traits/Backend.php:CSV 导入临时文件改到 runtime/temp/
二、implode 参数反序(7.4 起 E_DEPRECATED,TP5 会抛异常)
- application/api/controller/Datas.php
- application/index/controller/wms/Pda.php
- 另修正 Wms.php 中 1 处(拆分面单提示)
三、null 取下标(7.4 起 "Trying to access array offset on value of type null")
- 覆盖 71 个文件 135 行:find()/value()/json_decode()/redis get 等结果未判空即取下标处,
统一 (\['k'] ?? null) 兜底;foreach 目标用 ?? [];in_array/count 等数组参数用 ?? []
- 涉及 api/*、admin/shopro/*、addons/shopro/*、addons/epay/*、index/wms/* 等
四、嵌套三元未加括号(7.4 弃用)
- application/index/controller/wms/Wms.php getPackingprice 2 处,补括号后与旧版本解析顺序一致
验证:74 个文件、148 行改动,逐行括号/引号配平与 HEAD 一致,未改动 vendor/ 与 thinkphp/;
剩余扫描命中均为写目标、unset、或已被 if(!\){error()} 拦截的假阳性。
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
245 lines
5.3 KiB
PHP
245 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace Yansongda\Supports;
|
|
|
|
use Exception;
|
|
use Monolog\Formatter\FormatterInterface;
|
|
use Monolog\Formatter\LineFormatter;
|
|
use Monolog\Handler\AbstractHandler;
|
|
use Monolog\Handler\RotatingFileHandler;
|
|
use Monolog\Handler\StreamHandler;
|
|
use Monolog\Logger as BaseLogger;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
/**
|
|
* @method void emergency($message, array $context = array())
|
|
* @method void alert($message, array $context = array())
|
|
* @method void critical($message, array $context = array())
|
|
* @method void error($message, array $context = array())
|
|
* @method void warning($message, array $context = array())
|
|
* @method void notice($message, array $context = array())
|
|
* @method void info($message, array $context = array())
|
|
* @method void debug($message, array $context = array())
|
|
* @method void log($message, array $context = array())
|
|
*/
|
|
class Logger
|
|
{
|
|
/**
|
|
* Logger instance.
|
|
*
|
|
* @var LoggerInterface
|
|
*/
|
|
protected $logger;
|
|
|
|
/**
|
|
* formatter.
|
|
*
|
|
* @var \Monolog\Formatter\FormatterInterface
|
|
*/
|
|
protected $formatter;
|
|
|
|
/**
|
|
* handler.
|
|
*
|
|
* @var AbstractHandler
|
|
*/
|
|
protected $handler;
|
|
|
|
/**
|
|
* config.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $config = [
|
|
'file' => null,
|
|
'identify' => 'yansongda.supports',
|
|
'level' => BaseLogger::DEBUG,
|
|
'type' => 'daily',
|
|
'max_files' => 30,
|
|
];
|
|
|
|
/**
|
|
* Forward call.
|
|
*
|
|
* @author yansongda <me@yansongda.cn>
|
|
*
|
|
* @param string $method
|
|
* @param array $args
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function __call($method, $args): void
|
|
{
|
|
call_user_func_array([$this->getLogger(), $method], $args);
|
|
}
|
|
|
|
/**
|
|
* Set logger.
|
|
*
|
|
* @author yansongda <me@yansongda.cn>
|
|
*/
|
|
public function setLogger(LoggerInterface $logger): Logger
|
|
{
|
|
$this->logger = $logger;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Return the logger instance.
|
|
*
|
|
* @author yansongda <me@yansongda.cn>
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function getLogger(): LoggerInterface
|
|
{
|
|
if (is_null($this->logger)) {
|
|
$this->logger = $this->createLogger();
|
|
}
|
|
|
|
return $this->logger;
|
|
}
|
|
|
|
/**
|
|
* Make a default log instance.
|
|
*
|
|
* @author yansongda <me@yansongda.cn>
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function createLogger(): BaseLogger
|
|
{
|
|
$handler = $this->getHandler();
|
|
|
|
$handler->setFormatter($this->getFormatter());
|
|
|
|
$logger = new BaseLogger($this->config['identify']);
|
|
|
|
$logger->pushHandler($handler);
|
|
|
|
return $logger;
|
|
}
|
|
|
|
/**
|
|
* setFormatter.
|
|
*
|
|
* @author yansongda <me@yansongda.cn>
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function setFormatter(FormatterInterface $formatter): self
|
|
{
|
|
$this->formatter = $formatter;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* getFormatter.
|
|
*
|
|
* @author yansongda <me@yansongda.cn>
|
|
*/
|
|
public function getFormatter(): FormatterInterface
|
|
{
|
|
if (is_null($this->formatter)) {
|
|
$this->formatter = $this->createFormatter();
|
|
}
|
|
|
|
return $this->formatter;
|
|
}
|
|
|
|
/**
|
|
* createFormatter.
|
|
*
|
|
* @author yansongda <me@yansongda.cn>
|
|
*/
|
|
public function createFormatter(): LineFormatter
|
|
{
|
|
return new LineFormatter(
|
|
"%datetime% > %channel%.%level_name% > %message% %context% %extra%\n\n",
|
|
null,
|
|
false,
|
|
true
|
|
);
|
|
}
|
|
|
|
/**
|
|
* setHandler.
|
|
*
|
|
* @author yansongda <me@yansongda.cn>
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function setHandler(AbstractHandler $handler): self
|
|
{
|
|
$this->handler = $handler;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* getHandler.
|
|
*
|
|
* @author yansongda <me@yansongda.cn>
|
|
*
|
|
* @throws \Exception
|
|
*/
|
|
public function getHandler(): AbstractHandler
|
|
{
|
|
if (is_null($this->handler)) {
|
|
$this->handler = $this->createHandler();
|
|
}
|
|
|
|
return $this->handler;
|
|
}
|
|
|
|
/**
|
|
* createHandler.
|
|
*
|
|
* @author yansongda <me@yansongda.cn>
|
|
*
|
|
* @throws \Exception
|
|
*
|
|
* @return \Monolog\Handler\RotatingFileHandler|\Monolog\Handler\StreamHandler
|
|
*/
|
|
public function createHandler(): AbstractHandler
|
|
{
|
|
$file = $this->config['file'] ?? (defined('RUNTIME_PATH') ? RUNTIME_PATH . 'epay' . DIRECTORY_SEPARATOR . $this->config['identify'] . '.log' : sys_get_temp_dir().'/logs/'.$this->config['identify'].'.log');
|
|
$dir = dirname($file);
|
|
if (!is_dir($dir)) {
|
|
@mkdir($dir, 0755, true);
|
|
}
|
|
|
|
if ('single' === $this->config['type']) {
|
|
return new StreamHandler($file, $this->config['level']);
|
|
}
|
|
|
|
return new RotatingFileHandler($file, $this->config['max_files'], $this->config['level']);
|
|
}
|
|
|
|
/**
|
|
* setConfig.
|
|
*
|
|
* @author yansongda <me@yansongda.cn>
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function setConfig(array $config): self
|
|
{
|
|
$this->config = array_merge($this->config, $config);
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* getConfig.
|
|
*
|
|
* @author yansongda <me@yansongda.cn>
|
|
*/
|
|
public function getConfig(): array
|
|
{
|
|
return $this->config;
|
|
}
|
|
}
|