Skip to content

Commit

Permalink
[Fix] Ingore request without content-type and add a switch configurat…
Browse files Browse the repository at this point in the history
…ion to turn off this package
  • Loading branch information
TsaiKoga committed Aug 3, 2020
1 parent 8adbc8f commit 5c2c25c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<p align="center">
<a link="https://packagist.org/packages/tsaikoga/performance-printer" style="text-decoration:none;">
<img src="https://img.shields.io/badge/stable-v1.0.0-brightgreen" alt="Unstable">
<img src="https://img.shields.io/badge/stable-v1.0.1-brightgreen" alt="Unstable">
</a>
<a link="https://packagist.org/packages/tsaikoga/performance-printer" style="text-decoration:none;">
<img src="https://img.shields.io/badge/unstable-dev--master-blue" alt="Unstable">
Expand Down Expand Up @@ -79,6 +79,9 @@ return [
// The connections
'connections' => ['mysql'],
],

// enable this package or disable it
'enable' => true,
];
```

Expand Down
3 changes: 3 additions & 0 deletions config/PerformancePrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@
// The connections
'connections' => ['mysql'],
],

// enable this package
'enable' => true,
];
2 changes: 1 addition & 1 deletion src/Printer/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function outputRequest()
$request = $this->request->server();
$this->writeln("<question>[ {$request['REQUEST_METHOD']} ]</question> <info>{$request['REQUEST_URI']}</info>");
if (in_array($request['REQUEST_METHOD'], ['POST', 'PUT', 'PATCH'])) {
$this->writeln("<question>[ Content-Type ]</question> : {$request['HTTP_CONTENT_TYPE']} ");
if (isset($request['HTTP_CONTENT_TYPE'])) $this->writeln("<question>[ Content-Type ]</question> : {$request['HTTP_CONTENT_TYPE']} ");
$this->writeln($this->request->getContent());
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/PrinterServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ public function boot()
], 'config');
}
$this->mergeConfigFrom(dirname(__DIR__).'/config/PerformancePrinter.php', 'performance_printer');

foreach (config('performance_printer')['query']['connections'] as $conn) {
DB::connection($conn)->enableQueryLog();
if (config('performance_printer')['enable']) {
foreach (config('performance_printer')['query']['connections'] as $conn) {
DB::connection($conn)->enableQueryLog();
}
Event::listen(RequestHandled::class, function ($event) {
$printer_manager = new PrinterManager(config('performance_printer'));
$printer_manager->print($event);
});
}
Event::listen(RequestHandled::class, function ($event) {
$printer_manager = new PrinterManager(config('performance_printer'));
$printer_manager->print($event);
});
}
}
}

0 comments on commit 5c2c25c

Please sign in to comment.