Commit 8b933093 authored by Nikita Chernykh's avatar Nikita Chernykh
Browse files

Merge branch 'PTPS_Controller_8' into 'main'

Ptps controller 8

See merge request !8
parents 634b261b de0b4a88
Loading
Loading
Loading
Loading

compose.override.yaml

deleted100644 → 0
+0 −19
Original line number Diff line number Diff line
version: '3'

services:
###> doctrine/doctrine-bundle ###
  database:
    ports:
      - "5432"
###< doctrine/doctrine-bundle ###

###> symfony/mailer ###
  mailer:
    image: axllent/mailpit
    ports:
      - "1025"
      - "8025"
    environment:
      MP_SMTP_AUTH_ACCEPT_ANY: 1
      MP_SMTP_AUTH_ALLOW_INSECURE: 1
###< symfony/mailer ###

compose.yaml

deleted100644 → 0
+0 −26
Original line number Diff line number Diff line
version: '3'

services:
###> doctrine/doctrine-bundle ###
  database:
    image: postgres:${POSTGRES_VERSION:-16}-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-app}
      # You should definitely change the password in production
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!}
      POSTGRES_USER: ${POSTGRES_USER:-app}
    healthcheck:
      test: ["CMD", "pg_isready"]
      timeout: 5s
      retries: 5
      start_period: 60s
    volumes:
      - database_data:/var/lib/postgresql/data:rw
      # You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
      # - ./docker/db/data:/var/lib/postgresql/data:rw
###< doctrine/doctrine-bundle ###

volumes:
###> doctrine/doctrine-bundle ###
  database_data:
###< doctrine/doctrine-bundle ###
+24 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Action;

use Exception;
use RuntimeException;
use DateTimeImmutable;
use DateTime;
use DatePeriod;
@@ -132,4 +133,27 @@ class Functions
        $dateInterval = date_diff($dateStart, $dateEnd);
        return (int)$dateInterval->format("%a") ;
    }

    /**
     * Напиши функцию, которая принимает путь до файла,
     * проверяет, что файл существует и выводит пользователю весь контент файла
     * (файл можешь создать любой)
     * @param string $filePath путь до файла
     * @return string
     * @throws RuntimeException
     */
    public function readLogFile(string $filePath): string
    {
        if (file_exists($filePath)) {
            $text = "";
            $file = fopen($filePath, 'rb');
            while(!feof($file)) {
                $line = fgets($file);
                $text .= $line;
            }
            fclose($file);
            return $text;
        }
        throw new RuntimeException("File not found: $filePath");
    }
}
 No newline at end of file
+12 −0
Original line number Diff line number Diff line
@@ -14,7 +14,9 @@ use App\Requests\{
};
use DateTimeImmutable;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;

class HomeController extends AbstractController
@@ -91,4 +93,14 @@ class HomeController extends AbstractController
            return new Response($e->getMessage());
        }
    }

    #[Route('/readLogFile', name: 'readLogFile')]
    public function readLogFile(Request $request): Response
    {
        $file = $request->files->get('file');
        $text = $this->functions->readLogFile($file->getRealPath());
        $response = new JsonResponse($text);
        $response->setEncodingOptions(JSON_UNESCAPED_UNICODE);
        return $response;
    }
}
+1 −1
Original line number Diff line number Diff line
{% block body %}
    <h1>Кол-во дней между датами: {{ count }}</h1>
    <h1>{{ text }}</h1>
{% endblock %}
 No newline at end of file
+1 −1

File changed.

Contains only whitespace changes.

Loading