Skip to content
Snippets Groups Projects
Commit a817a270 authored by Nikita Chernykh's avatar Nikita Chernykh
Browse files

Merge branch 'PTPS|Controller_8' into 'main'

make controller

See merge request !8
parents 1482daa5 b77df9d7
No related branches found
No related tags found
1 merge request!8make controller
<!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
<?php
namespace App\Actions;
use Exception;
class ReadLogFileAction
{
/**
* Принимает путь до файла,
* проверяет, что файл существует и выводит пользователю весь контент файла
* (файл можешь создать любой)
*
* @param string $filePath путь до файла
* @return false|string
* @throws Exception при отсутсвии фаила по переданному пути
*/
public function act(string $filePath)
{
if (!file_exists($filePath)) {
throw new Exception("По данному пути ничего не найдено: $filePath");
}
return file_get_contents($filePath);
}
}
<?php
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;
class ReadLogFileController extends AbstractController
{
/**
* Принимает путь до файла,
* проверяет, что файл существует и выводит пользователю весь контент файла
* (файл можешь создать любой)
*
* @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
{
$file = $request->files->get("File");
return new Response($action->act($file->getPathname()));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment