From 92e9823191c841c13067448fe416b3070d2ded18 Mon Sep 17 00:00:00 2001 From: Mathieu Ducrot Date: Wed, 5 Jun 2024 18:00:46 +0200 Subject: [PATCH] ApiCallMonitor::getProcessMonitor getter + start and end method adjustement --- CHANGELOG.md | 8 ++++++++ src/Monitoring/ApiCallMonitor.php | 13 +++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b57780..ff5cfd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ CHANGELOG for 1.x =================== +## v1.4.2 - (2024-06-05) +### Added +- `ApiCallMonitor::getProcessMonitor` getter to access the ProcessMonitor instance through it + +### Changed +- `ApiCallMonitor::start` add **$flush** param to match `ProcessMonitor::start` definition +- `ApiCallMonitor::end` use Symfony Response const instead of hard coded value for the isSuccess check, also expand the range to >= 100 and < 400 + ## v1.4.1 - (2024-05-29) ### Fixed - `DateUtils::millisecondsToString` int type cast when calling **secondsToString** to fix the deprecated: Implicit conversion from float diff --git a/src/Monitoring/ApiCallMonitor.php b/src/Monitoring/ApiCallMonitor.php index e3a2be6..4613fcd 100644 --- a/src/Monitoring/ApiCallMonitor.php +++ b/src/Monitoring/ApiCallMonitor.php @@ -3,8 +3,8 @@ namespace Smart\CoreBundle\Monitoring; use Smart\CoreBundle\Entity\ApiCallInterface; -use Smart\CoreBundle\Entity\ProcessInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; /** * @author Mathieu Ducrot @@ -15,9 +15,9 @@ public function __construct(private readonly ProcessMonitor $processMonitor) { } - public function start(ApiCallInterface $apiCall, Request $request): ApiCallInterface + public function start(ApiCallInterface $apiCall, Request $request, bool $flush = false): ApiCallInterface { - $this->processMonitor->start($apiCall); + $this->processMonitor->start($apiCall, $flush); $apiCall->setMethod($request->getMethod()); $apiCall->setRouteUrl($request->getUri()); $apiCall->setType($request->attributes->get('_route')); @@ -29,6 +29,11 @@ public function start(ApiCallInterface $apiCall, Request $request): ApiCallInter public function end(ApiCallInterface $apiCall, int $statusCode, bool $flush = true): void { $apiCall->setStatusCode($statusCode); - $this->processMonitor->end($apiCall, $statusCode >= 200 && $statusCode < 300, $flush); + $this->processMonitor->end($apiCall, $statusCode >= Response::HTTP_CONTINUE && $statusCode < Response::HTTP_BAD_REQUEST, $flush); + } + + public function getProcessMonitor(): ProcessMonitor + { + return $this->processMonitor; } }