DETAILS
%s', e(print_r($value, true)) ); } return; } /** * Highlights a line of php code with php syntax highlighting * * @param string $str * @return string */ function phpSyntaxHighlight(string $str): string { $regexes = [ 'control' => '/\b(for|foreach|while|class |extends|yield from|yield|echo|fn|implements|try|catch|finally|throw|new|instanceof| parent|final|function|return|unset|static|public|protected|private|count|global|if|else|else if|intval|int|array)\b/', 'bool' => '/(\bnull\b|\btrue\b|\bfalse\b)/', 'string' => [ 'pattern' => '/(\221[^\221]*\221|\222[^\222]*\222)/', 'before' => fn ($s) => str_replace(''', "\221", str_replace('"', "\222", $s)), 'after' => fn ($s) => str_replace("\221", ''', str_replace("\222", '"', $s)), ], 'number' => [ 'pattern' => '/(=\(\s)?(\d+)(?=(\s|;|,|\)|=))/', 'replace' => '$2', 'before' => fn ($s) => str_replace(''', '\'', $s), 'after' => fn ($s) => str_replace('\'', ''', $s), ], 'bracket' => '/(\(|\)|\[|\]|\{|\})/', 'variable' => '/(\$[a-z]\w*)/', ]; if (preg_match('/(^\s*?\*|^\s*?\*\/|^\s*?\/\*|^\s*?\/\/|^\s*?#)/', $str)) { return sprintf('%s', $str); } foreach ($regexes as $label => $regex) { if (is_string($regex)) { $str = preg_replace($regex, '$1', $str); continue; } $str = preg_replace( $regex['pattern'], sprintf('%s', $label, $regex['replace'] ?? '$1'), isset($regex['before']) ? $regex['before']($str) : $str ); $str = isset($regex['after']) ? $regex['after']($str) : $str; } return $str; } /** * Converts an array of lines into a html snippet of code * * @param array $snippet * @param int|null $highlight * @return string */ function makeSnippet(array $snippet, string $file, ?int $highlight = null): string { return implode( "\n", array_reduce( array_keys($snippet), function (array $carry, $key) use ($snippet, $file, $highlight) { $carry[] = sprintf( '
| = e(trans('system::lang.event_log.details.http_method')) ?> | = e($value['environment']['method']) ?> |
|---|---|
| = e(trans('system::lang.event_log.details.url')) ?> | = e($value['environment']['url']) ?> |
| = e(trans('system::lang.event_log.details.user_agent')) ?> | = e($value['environment']['userAgent']) ?> |
| = e(trans('system::lang.event_log.details.client_ip')) ?> | = e($value['environment']['ip']) ?> |