From 31431e3c63fbc1977df14341fd6f1f82494fe56d Mon Sep 17 00:00:00 2001 From: Akex <a.plokhikh.sas@gmail.com> Date: Tue, 9 Apr 2024 02:49:48 +0500 Subject: [PATCH] make controller --- public/helloWorld.html | 10 +++++++++ src/Controller/ReadLogFileController.php | 28 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 public/helloWorld.html create mode 100644 src/Controller/ReadLogFileController.php diff --git a/public/helloWorld.html b/public/helloWorld.html new file mode 100644 index 0000000..a47038f --- /dev/null +++ b/public/helloWorld.html @@ -0,0 +1,10 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <title>Title</title> +</head> +<body> +hello World +</body> +</html> \ No newline at end of file diff --git a/src/Controller/ReadLogFileController.php b/src/Controller/ReadLogFileController.php new file mode 100644 index 0000000..f62e6a2 --- /dev/null +++ b/src/Controller/ReadLogFileController.php @@ -0,0 +1,28 @@ +<?php + +namespace App\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Attribute\Route; + +class ReadLogFileController extends AbstractController +{ + /** + * Принимает путь до файла, + * проверÑет, что файл ÑущеÑтвует и выводит пользователю веÑÑŒ контент файла + * (файл можешь Ñоздать любой) + * + * @param string $filePath путь до файла + * @return Response */ + #[Route('/read/{filePath}', name: 'app_read_log_file', methods: ['GET'])] + public function index(string $filePath): Response + { + $fileSystem = new Filesystem(); + if (!$fileSystem->exists($filePath)) { + return new Response('File not found', Response::HTTP_NOT_FOUND); + } + + return new Response(file_get_contents($filePath), Response::HTTP_OK); + } +} -- GitLab