Commit c45b4980 authored by Александр Плохих's avatar Александр Плохих 🌔
Browse files

chenge login to read file from req

parent 702c998d
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace App\Controller;

use App\Actions\ReadFileLineByLineAction;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

@@ -15,20 +16,21 @@ class ReadFileLineByLineController extends AbstractController
     *
     * @param string $filePath путь до файла
     * @return Response  */
    #[Route('/readbyline/{filePath}', name: 'app_read_file_line_by_line')]
    #[Route('/readbyline', name: 'app_read_file_line_by_line', methods: ['POST'])]
    public function index(
        string $filePath,
        Request $request,
        ReadFileLineByLineAction $action
    ) : Response {
        $file = "";
        $file = $request->files->get('File');
        $content = "";
        try{
            foreach ($action->act($filePath) as $line) {
                $file .= $line;
            foreach ($action->act($file->getRealPath()) as $line) {
                $content .= $line;
            }
        } catch (\Exception $exception) {
            return new Response($exception->getMessage(), Response::HTTP_NOT_FOUND);
        }

        return new Response($file, Response::HTTP_OK);
        return new Response($content);
    }
}