-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from MacPaw/develop
New Release
- Loading branch information
Showing
16 changed files
with
254 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ on: | |
|
||
jobs: | ||
run: | ||
runs-on: ubuntu-18.04 | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
|
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
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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SymfonyHealthCheckBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use SymfonyHealthCheckBundle\Check\CheckInterface; | ||
|
||
abstract class BaseController extends AbstractController | ||
{ | ||
/** | ||
* @var array<CheckInterface> | ||
*/ | ||
private array $checks = []; | ||
private ?int $customResponseCode = null; | ||
|
||
abstract public function check(): JsonResponse; | ||
|
||
public function addHealthCheck(CheckInterface $check): void | ||
{ | ||
$this->checks[] = $check; | ||
} | ||
|
||
public function setCustomResponseCode(?int $code): void | ||
{ | ||
$this->customResponseCode = $code; | ||
} | ||
|
||
protected function checkAction(): JsonResponse | ||
{ | ||
$checkResult = $this->performCheck(); | ||
$responseCode = $this->determineResponseCode($checkResult); | ||
|
||
return new JsonResponse($checkResult, $responseCode); | ||
} | ||
|
||
protected function performCheck(): array | ||
{ | ||
return array_map( | ||
fn($healthCheck) => $healthCheck->check()->toArray(), | ||
$this->checks | ||
); | ||
} | ||
|
||
protected function determineResponseCode(array $results): int | ||
{ | ||
$code = $this->customResponseCode; | ||
$responseCode = Response::HTTP_OK; | ||
|
||
if (null !== $code) { | ||
foreach ($results as $result) { | ||
if (!$result['result']) { | ||
$responseCode = $code; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return $responseCode; | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -8,5 +8,4 @@ | |
|
||
class SymfonyHealthCheckBundle extends Bundle | ||
{ | ||
|
||
} |
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
Oops, something went wrong.