-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ApiCallMonitor for managing ApiCallInterface monitoring
- Loading branch information
1 parent
8989304
commit 8c8bb36
Showing
3 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Monitoring; | ||
|
||
use Smart\CoreBundle\Entity\ApiCallInterface; | ||
use Smart\CoreBundle\Entity\ProcessInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
class ApiCallMonitor | ||
{ | ||
public function __construct(private readonly ProcessMonitor $processMonitor) | ||
{ | ||
} | ||
|
||
public function start(ApiCallInterface $apiCall, Request $request): ProcessInterface | ||
{ | ||
$this->processMonitor->start($apiCall); | ||
$apiCall->setMethod($request->getMethod()); | ||
$apiCall->setRouteUrl($request->getUri()); | ||
$apiCall->setType($request->attributes->get('_route')); | ||
$apiCall->setInputData($request->request->all()); | ||
|
||
return $apiCall; | ||
} | ||
|
||
public function end(ApiCallInterface $apiCall, int $statusCode, bool $flush = true): void | ||
{ | ||
$apiCall->setStatusCode($statusCode); | ||
$this->processMonitor->end($apiCall, $statusCode >= 200 && $statusCode < 300, $flush); | ||
} | ||
} |