From dd80058baf3aab647ab190ec904d5be6395aacd0 Mon Sep 17 00:00:00 2001 From: "a.shamavov" <a.shamavov@iqdev.digital> Date: Tue, 9 Apr 2024 10:47:44 +0500 Subject: [PATCH] add readLogFile --- .../994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5 | 0 .idea/sonarlint/issuestore/index.pb | 4 +++- .../994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5 | 0 .idea/sonarlint/securityhotspotstore/index.pb | 4 +++- public/files/text.txt | 2 ++ src/Controller/HomeController.php | 24 ++++++++++++++----- templates/home.html.twig | 2 +- 7 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 .idea/sonarlint/issuestore/9/9/994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5 create mode 100644 .idea/sonarlint/securityhotspotstore/9/9/994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5 create mode 100644 public/files/text.txt diff --git a/.idea/sonarlint/issuestore/9/9/994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5 b/.idea/sonarlint/issuestore/9/9/994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb index bc34c28..dae00e9 100644 --- a/.idea/sonarlint/issuestore/index.pb +++ b/.idea/sonarlint/issuestore/index.pb @@ -8,4 +8,6 @@ V C assets/bootstrap.js,0\3\03141036569b5869397180192f8b98c1360e1556 E -assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19 \ No newline at end of file +assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19 +E +public/files/text.txt,9\9\994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5 \ No newline at end of file diff --git a/.idea/sonarlint/securityhotspotstore/9/9/994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5 b/.idea/sonarlint/securityhotspotstore/9/9/994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/index.pb b/.idea/sonarlint/securityhotspotstore/index.pb index bc34c28..dae00e9 100644 --- a/.idea/sonarlint/securityhotspotstore/index.pb +++ b/.idea/sonarlint/securityhotspotstore/index.pb @@ -8,4 +8,6 @@ V C assets/bootstrap.js,0\3\03141036569b5869397180192f8b98c1360e1556 E -assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19 \ No newline at end of file +assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19 +E +public/files/text.txt,9\9\994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5 \ No newline at end of file diff --git a/public/files/text.txt b/public/files/text.txt new file mode 100644 index 0000000..3ba1fcf --- /dev/null +++ b/public/files/text.txt @@ -0,0 +1,2 @@ +Раз, два, три, четыре, +пÑÑ‚ÑŒ, шеÑÑ‚ÑŒ, Ñемь, воÑемь. \ No newline at end of file diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index adf7c3d..51d19fa 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -12,14 +12,26 @@ use Symfony\Component\Routing\Attribute\Route; class HomeController extends AbstractController { - private function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int { - return date_diff($dateStart, $dateEnd)->format("%a") ; + private function readLogFile(string $fileName): string { + $filePath = $this->getParameter('kernel.project_dir') . "/public/files/" . $fileName; + if (file_exists($filePath)) { + $text = ""; + $file = fopen($filePath, "r"); + while(!feof($file)) { + $line = fgets($file); + $text .= $line; + } + fclose($file); + return $text; + } + return "Такого файла не ÑущеÑтвует."; } - #[Route('/{startDate}/{endDate}', name: 'home')] // 01-01-2024 - public function home(string $startDate, string $endDate): Response + + #[Route('/{fileName}', name: 'home')] + public function home(string $fileName): Response // text.txt { - $countDays = $this->diffDays(new DateTimeImmutable($startDate), new DateTimeImmutable($endDate)); - return $this->render('home.html.twig', ['count' => $countDays]); + $text = $this->readLogFile($fileName); + return $this->render('home.html.twig', ['text' => $text]); } } diff --git a/templates/home.html.twig b/templates/home.html.twig index 3814758..6ac2ed4 100644 --- a/templates/home.html.twig +++ b/templates/home.html.twig @@ -1,3 +1,3 @@ {% block body %} - <h1>Кол-во дней между датами: {{ count }}</h1> + <h1>{{ text }}</h1> {% endblock %} \ No newline at end of file -- GitLab