refactor
This commit is contained in:
parent
2123b5464f
commit
b9aaff7931
18
src/Controller/EntrypointController.php
Normal file
18
src/Controller/EntrypointController.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class EntrypointController extends AbstractController
|
||||
{
|
||||
#[Route(path: '/', name: 'app_root', methods: Request::METHOD_GET)]
|
||||
public function __invoke(): Response
|
||||
{
|
||||
return $this->redirectToRoute('app_home');
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Forms\UploadFileForm;
|
||||
use App\Objects\UploadedFileData;
|
||||
use App\Service\FileSystemService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@ -12,25 +11,12 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class HomeController extends AbstractController
|
||||
{
|
||||
#[Route(path: '/', name: 'app_home', methods: [Request::METHOD_GET, Request::METHOD_POST])]
|
||||
public function __invoke(
|
||||
FileSystemService $fileSystemService,
|
||||
Request $request,
|
||||
): Response
|
||||
#[Route(path: '/files', name: 'app_home', methods: [Request::METHOD_GET])]
|
||||
public function __invoke(FileSystemService $fileSystemService): Response
|
||||
{
|
||||
$fileData = new UploadedFileData();
|
||||
$form = $this->createForm(UploadFileForm::class, $fileData)->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
dd($form->getData(), $form->getExtraData());
|
||||
$fileSystemService->uploadFile($fileData->file);
|
||||
|
||||
return $this->redirectToRoute('app_home');
|
||||
}
|
||||
|
||||
return $this->render('home.html.twig', [
|
||||
'content' => $fileSystemService->getDirs(),
|
||||
'fileForm' => $form,
|
||||
'fileForm' => $this->createForm(UploadFileForm::class),
|
||||
]);
|
||||
}
|
||||
}
|
31
src/Controller/UploadController.php
Normal file
31
src/Controller/UploadController.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Forms\UploadFileForm;
|
||||
use App\Objects\UploadedFileData;
|
||||
use App\Service\FileSystemService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class UploadController extends AbstractController
|
||||
{
|
||||
#[Route(path: '/upload', name: 'app_upload', methods: Request::METHOD_POST)]
|
||||
public function __invoke(
|
||||
FileSystemService $fileSystemService,
|
||||
Request $request,
|
||||
): Response
|
||||
{
|
||||
$fileData = new UploadedFileData();
|
||||
$form = $this->createForm(UploadFileForm::class, $fileData)->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$fileSystemService->uploadFile($fileData->file);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('app_home');
|
||||
}
|
||||
}
|
@ -5,12 +5,19 @@ namespace App\Forms;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
class UploadFileForm extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly UrlGeneratorInterface $urlGenerator)
|
||||
{
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('file', FileType::class, [
|
||||
$builder
|
||||
->setAction($this->urlGenerator->generate('app_upload'))
|
||||
->add('file', FileType::class, [
|
||||
'attr' => ['class' => 'hidden'],
|
||||
'multiple' => true,
|
||||
]);
|
||||
|
@ -2,8 +2,8 @@
|
||||
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
|
||||
<thead class="text-xs text-gray-700 uppercase bg-gray-200 dark:bg-gray-700 dark:text-gray-400">
|
||||
<tr>
|
||||
<th scope="col" class="px-6 py-3">
|
||||
-
|
||||
<th scope="col" class="px-6 py-3" style="width: 5%;">
|
||||
|
||||
</th>
|
||||
<th scope="col" class="px-6 py-3">
|
||||
name
|
||||
@ -33,4 +33,4 @@
|
||||
<button type="submit" class="hidden"></button>
|
||||
</label>
|
||||
</div>
|
||||
{{ form_end(fileForm) }}
|
||||
{{ form_end(fileForm) }}
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
{% block body %}
|
||||
<center class="container mt-5">
|
||||
<h1>Welcome to the File Explorer</h1>
|
||||
<p>Use the navigation bar to explore the files and directories.</p>
|
||||
{% include '_partials/_table.html.twig' %}
|
||||
</center>
|
||||
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user