custom/plugins/FroshTools/src/Controller/HealthController.php line 31

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Frosh\Tools\Controller;
  3. use Frosh\Tools\Components\Health\Checker\CheckerInterface;
  4. use Frosh\Tools\Components\Health\HealthCollection;
  5. use Frosh\Tools\Components\Health\PerformanceCollection;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. /**
  9. * @Route(path="/api/_action/frosh-tools", defaults={"_routeScope"={"api"}, "_acl"={"frosh_tools:read"}})
  10. */
  11. class HealthController
  12. {
  13. /** @var CheckerInterface[] */
  14. private iterable $healthCheckers;
  15. /** @var CheckerInterface[] */
  16. private iterable $performanceCheckers;
  17. public function __construct(iterable $healthCheckers, iterable $performanceCheckers)
  18. {
  19. $this->healthCheckers = $healthCheckers;
  20. $this->performanceCheckers = $performanceCheckers;
  21. }
  22. /**
  23. * @Route(path="/health/status", methods={"GET"}, name="api.frosh.tools.health.status")
  24. */
  25. public function status(): JsonResponse
  26. {
  27. $collection = new HealthCollection();
  28. foreach ($this->healthCheckers as $checker) {
  29. $checker->collect($collection);
  30. }
  31. return new JsonResponse($collection);
  32. }
  33. /**
  34. * @Route(path="/performance/status", methods={"GET"}, name="api.frosh.tools.performance.status")
  35. */
  36. public function performanceStatus(): JsonResponse
  37. {
  38. $collection = new PerformanceCollection();
  39. foreach ($this->performanceCheckers as $checker) {
  40. $checker->collect($collection);
  41. }
  42. return new JsonResponse($collection);
  43. }
  44. }