Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions app/Plugins/PluginBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\View\FileViewFinder;

use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;

use App\Models\Common\Numbers;
use App\Traits\ConnectMailTrait;
Expand Down Expand Up @@ -38,10 +39,66 @@ public function __construct()
*/
public function ccErrorHandler($errno, $errstr, $errfile, $errline)
{
// deprecated は例外化せずログのみ出力する
if (in_array($errno, [E_DEPRECATED, E_USER_DEPRECATED], true)) {
$this->logDeprecated($errno, $errstr, $errfile, $errline);
return true;
}

// 例外を投げる。
throw new \ErrorException($errstr, $errno, 0, $errfile, $errline);
}

/**
* deprecated のログ出力
*/
private function logDeprecated($errno, $errstr, $errfile, $errline)
{
// Log 出力中の再帰的なエラーハンドラ呼び出しを避けるためのガード
// static なので同一リクエスト内では状態が保持され、2回目以降は即 return する
static $logging = false;
if ($logging) {
return;
}

$logging = true;
try {
$context = [
'message' => $errstr,
'file' => $errfile,
'line' => $errline,
'errno' => $errno,
'environment' => app()->environment(),
'php' => PHP_VERSION,
];

if (app()->bound('request')) {
$request = app('request');
$context += [
'method' => $request->method(),
'path' => $request->path(),
'route' => optional($request->route())->getName(),
];
}

$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 8);
$context['trace'] = array_map(function ($frame) {
return sprintf(
'%s:%s %s%s%s',
$frame['file'] ?? '[internal]',
$frame['line'] ?? '-',
$frame['class'] ?? '',
$frame['type'] ?? '',
$frame['function'] ?? ''
);
}, array_slice($trace, 1));

Log::warning('PHP deprecated', $context);
} finally {
$logging = false;
}
}

// プラグインの対象者(User or Manager):view ファイルの呼び出しでディレクトリ判定に使用するため。
// var $plugin_target = null;

Expand Down