From 31431e3c63fbc1977df14341fd6f1f82494fe56d Mon Sep 17 00:00:00 2001 From: Akex Date: Tue, 9 Apr 2024 02:49:48 +0500 Subject: [PATCH 1/3] 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 @@ + + + + + Title + + +hello World + + \ 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 @@ +exists($filePath)) { + return new Response('File not found', Response::HTTP_NOT_FOUND); + } + + return new Response(file_get_contents($filePath), Response::HTTP_OK); + } +} -- GitLab From 106913cf399e003f9bf1c52679a10eb946389e08 Mon Sep 17 00:00:00 2001 From: "Alex. Plokhikh" Date: Tue, 16 Apr 2024 04:30:36 +0500 Subject: [PATCH 2/3] add reader action and controller --- src/Actions/ReadLogFileAction.php | 26 ++++++++++++++++++++++++ src/Controller/ReadLogFileController.php | 13 ++++++------ 2 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 src/Actions/ReadLogFileAction.php diff --git a/src/Actions/ReadLogFileAction.php b/src/Actions/ReadLogFileAction.php new file mode 100644 index 0000000..ba63dd7 --- /dev/null +++ b/src/Actions/ReadLogFileAction.php @@ -0,0 +1,26 @@ +exists($filePath)) { - return new Response('File not found', Response::HTTP_NOT_FOUND); + try { + return new Response($action->act($filePath)); + } catch (\Exception $exception) { + return new Response('Searching file not found :/', 422); } - - return new Response(file_get_contents($filePath), Response::HTTP_OK); } } -- GitLab From b77df9d723244238983f1e9adeecf3709f7d8c64 Mon Sep 17 00:00:00 2001 From: "Alex. Plokhikh" Date: Wed, 17 Apr 2024 10:58:59 +0500 Subject: [PATCH 3/3] chenge logic to get and read files --- src/Controller/ReadLogFileController.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Controller/ReadLogFileController.php b/src/Controller/ReadLogFileController.php index 263ab11..809cf64 100644 --- a/src/Controller/ReadLogFileController.php +++ b/src/Controller/ReadLogFileController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Actions\ReadLogFileAction; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; @@ -13,15 +14,16 @@ class ReadLogFileController extends AbstractController * проверяет, что файл существует и выводит пользователю весь контент файла * (файл можешь создать любой) * - * @param string $filePath путь до файла - * @return Response */ - #[Route('/read/{filePath}', name: 'app_read_log_file', methods: ['GET'])] - public function index(string $filePath, ReadLogFileAction $action): Response + * @param Request $request + * @param ReadLogFileAction $action + * @return Response + */ + #[Route('/read', name: 'app_read_log_file', methods: ['POST'])] + public function index(Request $request, ReadLogFileAction $action): Response { - try { - return new Response($action->act($filePath)); - } catch (\Exception $exception) { - return new Response('Searching file not found :/', 422); - } + $file = $request->files->get("File"); + return new Response($action->act($file->getPathname())); } -} + + } + -- GitLab