Skip to content

Commit 92324dd

Browse files
authored
Merge pull request #21 from spotlibs/feature/exploration
Feature/exploration
2 parents 615e259 + be13ce5 commit 92324dd

File tree

22 files changed

+863
-42
lines changed

22 files changed

+863
-42
lines changed

bootstrap/app.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525

2626
$app->withFacades();
2727

28+
$app->singleton(
29+
Illuminate\Contracts\Debug\ExceptionHandler::class,
30+
Spotlibs\PhpLib\Exceptions\Handler::class
31+
);
32+
2833
// $app->withEloquent();
2934

3035
/*

config/logging.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
return [
4+
'default' => env('LOG_CHANNEL', 'stack'),
5+
'channels' => [
6+
'runtime' => [
7+
'driver' => 'single',
8+
'formatter' => Monolog\Formatter\LineFormatter::class,
9+
'formatter_with' => [
10+
'format' => "[%datetime%] ::".getenv('APP_NAME').".".getenv('APP_ENV').".%level_name%:: %message%\n",
11+
],
12+
'path' => storage_path('logs/runtime.log'),
13+
'level' => 'debug'
14+
],
15+
'activity' => [
16+
'driver' => 'single',
17+
'formatter' => Monolog\Formatter\LineFormatter::class,
18+
'formatter_with' => [
19+
'format' => "[%datetime%] ::".getenv('APP_NAME').".".getenv('APP_ENV').".%level_name%:: %message%\n",
20+
],
21+
'path' => storage_path('logs/activity.log'),
22+
'level' => 'debug'
23+
],
24+
'worker' => [
25+
'driver' => 'single',
26+
'formatter' => Monolog\Formatter\LineFormatter::class,
27+
'formatter_with' => [
28+
'format' => "[%datetime%] ::".getenv('APP_NAME').".".getenv('APP_ENV').".%level_name%:: %message%\n",
29+
],
30+
'path' => storage_path('logs/worker.log'),
31+
'level' => 'debug'
32+
]
33+
]
34+
];

phpcs.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
<rule ref="Generic.PHP.RequireStrictTypes" />
2020
<file>src/</file>
2121
<exclude-pattern>tests/</exclude-pattern>
22-
<exclude-pattern>vendor</exclude-pattern>
23-
<exclude-pattern>resources</exclude-pattern>
22+
<exclude-pattern>config/</exclude-pattern>
23+
<exclude-pattern>vendor/</exclude-pattern>
24+
<exclude-pattern>resources/</exclude-pattern>
2425
<exclude-pattern>database/</exclude-pattern>
2526
<exclude-pattern>storage/</exclude-pattern>
2627
<exclude-pattern>bootstrap/</exclude-pattern>

phpunit.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<directory>tests</directory>
1818
</testsuite>
1919
</testsuites>
20+
<php>
21+
<env name="APP_NAME" value="SPOTLIBS_MICROSERVICE"/>
22+
<env name="APP_ENV" value="local"/>
23+
</php>
2024

2125
<coverage cacheDirectory=".phpunit.cache/code-coverage"
2226
processUncoveredFiles="true">

src/Exceptions/Handler.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use Exception;
1919
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
20-
use Illuminate\Support\Facades\Log;
20+
use Spotlibs\PhpLib\Logs\Log;
2121
use Illuminate\Auth\Access\AuthorizationException;
2222
use Illuminate\Database\Eloquent\ModelNotFoundException;
2323
use Illuminate\Database\QueryException;
@@ -28,6 +28,7 @@
2828
use Spotlibs\PhpLib\Exceptions\DataNotFoundException;
2929
use Spotlibs\PhpLib\Responses\StdResponse;
3030
use Throwable;
31+
use TypeError;
3132

3233
/**
3334
* Class Handler
@@ -64,12 +65,16 @@ class Handler extends ExceptionHandler
6465
*/
6566
public function report(Throwable $exception)
6667
{
67-
// parent::report($exception);
68+
$logData = [
69+
'exception_code' => $exception->getCode(),
70+
'message' => $exception->getMessage(),
71+
'line' => $exception->getLine(),
72+
'file' => $exception->getFile(),
73+
'requestID' => app()->request->header('X-Request-ID') ?? null
74+
];
6875
if (!$exception instanceof ExceptionInterface && !$exception instanceof NotFoundHttpException && !$exception instanceof ValidationException) {
6976
if (!config('app.debug')) {
70-
$message = '[' . $exception->getCode() . '] "' . $exception->getMessage() . '" on line ';
71-
$message .= $exception->getLine() . ' of file ' . $exception->getFile() . ' [requestID:' . (app()->request->header('X-Request-ID') ?? null) . ']';
72-
Log::channel('runtime')->error($message);
77+
Log::runtime()->error($logData);
7378
} else {
7479
parent::report($exception);
7580
}

src/Libraries/RestClient.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use GuzzleHttp\Client;
1919
use GuzzleHttp\Promise\PromiseInterface;
2020
use GuzzleHttp\Psr7\Response;
21-
use Spotlibs\PhpLib\Services\ContextService;
21+
use Spotlibs\PhpLib\Services\Context;
2222
use StdClass;
2323

2424
/**
@@ -30,26 +30,25 @@
3030
* @license https://mit-license.org/ MIT License
3131
* @link https://github.com/spotlibs
3232
*/
33-
3433
class RestClient extends Client
3534
{
3635
private array $header;
3736
private string $method;
3837
private int $timeout;
3938
private bool $verify;
4039
private ?Response $response;
41-
private ContextService $contextService;
40+
private Context $contextService;
4241

4342
/**
44-
* Create a new controller instance.
43+
* Create a new RestClient instance.
4544
*
4645
* @return self
4746
*/
4847
public function __construct()
4948
{
5049
parent::__construct();
5150

52-
$this->contextService = app(ContextService::class);
51+
$this->contextService = app(Context::class);
5352

5453
$this->header = [];
5554
$this->method = $this->contextService->get('method') ?? 'POST';
@@ -191,7 +190,7 @@ public function setTimeout(int $timeout): void
191190
* @param string $uri URI to request
192191
* @param string $method request method (POST, GET, etc)
193192
*
194-
* @return void
193+
* @return StdClass
195194
*/
196195
public function call(mixed $jsonBody, string $base_uri, string $uri = '/', string $method = ''): StdClass
197196
{

0 commit comments

Comments
 (0)