diff --git a/compose.override.yaml b/compose.override.yaml deleted file mode 100644 index 4ddb3ffd8fa24f4670b13289d2637365cfd35ba0..0000000000000000000000000000000000000000 --- a/compose.override.yaml +++ /dev/null @@ -1,19 +0,0 @@ -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 ### diff --git a/compose.yaml b/compose.yaml deleted file mode 100644 index dd791d9702ef6ad10496751e8443df9846f2ab65..0000000000000000000000000000000000000000 --- a/compose.yaml +++ /dev/null @@ -1,26 +0,0 @@ -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 ### diff --git a/config/services.yaml b/config/services.yaml index 2d6a76f94dce138741e2d63ae83a11c1879031d9..c18468a7cbc5f2154eb15a3b1bf350f76974203a 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -21,4 +21,4 @@ services: - '../src/Kernel.php' # add more service definitions when explicit configuration is needed - # please note that last definitions always *replace* previous ones + # please note that last definitions always *replace* previous ones \ No newline at end of file diff --git a/src/Action/Functions.php b/src/Action/Functions.php index e1625b17f3756cdf36607481814d3cd1ff8c619e..b91efe4ec867b3095a18e30f5ea518aaf379c09a 100644 --- a/src/Action/Functions.php +++ b/src/Action/Functions.php @@ -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 diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 3396331167525f8f0ac06943cdb69ee833bbc1e1..0570b8c12483ca4d268fe202b76e3957a5570358 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -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; + } } diff --git a/templates/home.html.twig b/templates/home.html.twig index 381475858820376677bcc3e573c1f0ae94515a4a..6ac2ed411b7b94d81ab8ceb44755c2679df94bf3 100644 --- a/templates/home.html.twig +++ b/templates/home.html.twig @@ -1,3 +1,3 @@ {% block body %} -

Кол-во дней между датами: {{ count }}

+

{{ text }}

{% endblock %} \ No newline at end of file