Skip to content
Snippets Groups Projects
ReadLogFileController.php 1001 B
Newer Older
Akex's avatar
Akex committed
<?php

namespace App\Controller;
use App\Actions\ReadLogFileAction;
Akex's avatar
Akex committed
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
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, ReadLogFileAction $action): Response
Akex's avatar
Akex committed
    {
        try {
            return new Response($action->act($filePath));
        } catch (\Exception $exception) {
            return new Response('Searching file not found :/', 422);
Akex's avatar
Akex committed
        }
    }
}