-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathRequestDataProcessor.php
67 lines (55 loc) · 2.15 KB
/
RequestDataProcessor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Freshbitsweb\LaravelLogEnhancer;
class RequestDataProcessor
{
/**
* Adds additional request data to the log message.
*/
public function __invoke($record)
{
if (config('laravel_log_enhancer.log_input_data')) {
$record['extra']['inputs'] = request()->except(config('laravel_log_enhancer.ignore_input_fields'));
}
if (config('laravel_log_enhancer.log_request_headers')) {
$record['extra']['headers'] = request()->header();
}
if (config('laravel_log_enhancer.log_session_data')) {
$record['extra']['session'] = session()->all();
}
if (config('laravel_log_enhancer.log_git_data')) {
$record['extra']['git'] = $this->getGitDetails();
}
if (config('laravel_log_enhancer.log_app_details')) {
$record['extra']['Application Details'] = [
'Laravel Version' => app()::VERSION,
'PHP Version' => phpversion(),
'Config Cached' => app()->configurationIsCached() ? 'Yes' : 'No',
'Route Cached' => app()->routesAreCached() ? 'Yes' : 'No',
];
}
return $record;
}
public function getGitDetails()
{
$gitDetails = [];
$lastCommitDetails = `git show -s --format=%B`;
$gitDetails['Last Commit Message'] = preg_filter("/(.*?)\n*/s", '\\1', $lastCommitDetails);
$currentHeadDetails = `git branch -v --no-abbrev`;
if (
$currentHeadDetails &&
preg_match('{^\* (.+?)\s+([a-f0-9]{40})(?:\s|$)}m', $currentHeadDetails, $matches)
) {
$gitDetails['branch'] = $matches[1];
$gitDetails['commit'] = $matches[2];
}
$stagedChanges = `git diff --cached`;
if ($stagedChanges) {
$gitDetails['warning'][] = 'Last commit is dirty. Staged changes have been made since this commit.';
}
$unStagedChanges = `git diff`;
if ($unStagedChanges) {
$gitDetails['warning'][] = 'Last commit is dirty. (Un)staged changes have been made since this commit.';
}
return $gitDetails;
}
}