Browse Source

clean code and add PSR compliance

develop
Simon Vieille 2 months ago
parent
commit
aa9c2422ae
Signed by: deblan <simon@deblan.fr> GPG Key ID: 03383D15A1D31745
10 changed files with 20 additions and 29 deletions
  1. +2
    -0
      .env
  2. +1
    -0
      config/services.yaml
  3. +6
    -2
      src/Controller/CameraController.php
  4. +2
    -1
      src/Controller/EventController.php
  5. +2
    -1
      src/Controller/HygrometryApiController.php
  6. +2
    -2
      src/Controller/MonitoringApiController.php
  7. +2
    -1
      src/Controller/MonitoringController.php
  8. +0
    -20
      src/Controller/MotionApiController.php
  9. +2
    -1
      src/Controller/TemperatureApiController.php
  10. +1
    -1
      templates/camera.html.twig

+ 2
- 0
.env View File

@@ -31,3 +31,5 @@ APP_SECRET=f040dfea5e5e9d096302582577d2e3c8
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7
###< doctrine/doctrine-bundle ###

CAMERA1_URL=https://terrarium/camera

+ 1
- 0
config/services.yaml View File

@@ -5,6 +5,7 @@
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
motion_snapshots_directory: "motion/snapshots"
camera1_url: "%env(CAMERA1_URL)%"

services:
# default configuration for services in *this* file


+ 6
- 2
src/Controller/CameraController.php View File

@@ -6,14 +6,18 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Filesystem\Filesystem;
use App\Motion\SnapshotRepository;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Response;

class CameraController extends AbstractController
{
/**
* @Route("/camera", name="camera")
*/
public function camera()
public function camera(ParameterBagInterface $params): Response
{
return $this->render('camera.html.twig');
return $this->render('camera.html.twig', [
'camera1_url' => $params->get('camera1_url'),
]);
}
}

+ 2
- 1
src/Controller/EventController.php View File

@@ -8,13 +8,14 @@ use Symfony\Component\Filesystem\Filesystem;
use App\Motion\SnapshotRepository;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class EventController extends AbstractController
{
/**
* @Route("/events/{date}", name="events")
*/
public function events(SnapshotRepository $snapshotRepository, string $date = null)
public function events(SnapshotRepository $snapshotRepository, string $date = null): Response
{
$date = $date ?? date('Y-m-d');



+ 2
- 1
src/Controller/HygrometryApiController.php View File

@@ -8,13 +8,14 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use App\Validator\ApiValidator;
use App\Entity\Hygrometry;
use Symfony\Component\HttpFoundation\JsonResponse;

class HygrometryApiController extends AbstractController
{
/**
* @Route("/api/hygrometry/create", name="api_hygrometry_create", methods={"POST"})
*/
public function create(Request $request, ApiValidator $validator, \Swift_Mailer $mailer): Response
public function create(Request $request, ApiValidator $validator, \Swift_Mailer $mailer): JsonResponse
{
if ('application/json' === $request->getContentType()) {
return $this->json([], 400);


+ 2
- 2
src/Controller/MonitoringApiController.php View File

@@ -14,7 +14,7 @@ class MonitoringApiController extends AbstractController
/**
* @Route("/api/monitoring/temperature", name="api_monitoring_temperature", methods={"GET"})
*/
public function temperature(Request $request, TemperatureRepository $repository)
public function temperature(Request $request, TemperatureRepository $repository): JsonResponse
{
$labels = [];
$datasets = [];
@@ -59,7 +59,7 @@ class MonitoringApiController extends AbstractController
/**
* @Route("/api/monitoring/hygrometry", name="api_monitoring_hygrometry", methods={"GET"})
*/
public function hygrometry(Request $request, HygrometryRepository $repository)
public function hygrometry(Request $request, HygrometryRepository $repository): JsonResponse
{
$labels = [];
$datasets = [];


+ 2
- 1
src/Controller/MonitoringController.php View File

@@ -6,13 +6,14 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Filesystem\Filesystem;
use App\Motion\SnapshotRepository;
use Symfony\Component\HttpFoundation\Response;

class MonitoringController extends AbstractController
{
/**
* @Route("/", name="charts")
*/
public function charts()
public function charts(): Response
{
return $this->render('charts.html.twig');
}


+ 0
- 20
src/Controller/MotionApiController.php View File

@@ -1,20 +0,0 @@
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class MotionApiController extends AbstractController
{
/**
* @Route("/api/motion/hook", name="api_motion_hook")
*/
public function hook(Request $request): Response
{
return new Response();
}
}

+ 2
- 1
src/Controller/TemperatureApiController.php View File

@@ -8,13 +8,14 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use App\Validator\ApiValidator;
use App\Entity\Temperature;
use Symfony\Component\HttpFoundation\JsonResponse;

class TemperatureApiController extends AbstractController
{
/**
* @Route("/api/temperature/create", name="api_temperature_create", methods={"POST"})
*/
public function create(Request $request, ApiValidator $validator, \Swift_Mailer $mailer): Response
public function create(Request $request, ApiValidator $validator, \Swift_Mailer $mailer): JsonResponse
{
if ('application/json' === $request->getContentType()) {
return $this->json([], 400);


+ 1
- 1
templates/camera.html.twig View File

@@ -5,7 +5,7 @@
{% block body %}
<div class="container">
<div class="camera-wrapper">
<img src="https://api:WFVbTdZbad1EGC3vtwazECVqVzaD@terrarium-proxy.deblan.fr/proxy/camera1" class="box camera" alt="Caméra 1">
<img src="{{ camera1_url }}" class="box camera" alt="Caméra 1">
</div>
</div>
{% endblock %}

Loading…
Cancel
Save