From 07a54729b1a75ed860fa078cdb43de1fd27e2cce Mon Sep 17 00:00:00 2001 From: Constantin Simonis Date: Thu, 5 Dec 2024 10:50:12 +0100 Subject: [PATCH] add route parameter for dirs --- src/Controller/HomeController.php | 12 +++++++++--- src/Service/FileSystemService.php | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 22efda8..0b824d6 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -11,11 +11,17 @@ use Symfony\Component\Routing\Attribute\Route; class HomeController extends AbstractController { - #[Route(path: '/files', name: 'app_home', methods: [Request::METHOD_GET])] - public function __invoke(FileSystemService $fileSystemService): Response + #[Route( + path: '/files/{dirs?}', + name: 'app_home', + requirements: ['dirs' => '.+'], + defaults: ['dirs' => ''], + methods: [Request::METHOD_GET] + )] + public function __invoke(FileSystemService $fileSystemService, string $dirs): Response { return $this->render('home.html.twig', [ - 'content' => $fileSystemService->getDirs(), + 'content' => $fileSystemService->getDirs($dirs), 'fileForm' => $this->createForm(UploadFileForm::class), ]); } diff --git a/src/Service/FileSystemService.php b/src/Service/FileSystemService.php index d6cb8f6..6df4667 100644 --- a/src/Service/FileSystemService.php +++ b/src/Service/FileSystemService.php @@ -20,10 +20,10 @@ class FileSystemService /** * @return DirContent[] */ - public function getDirs(): array + public function getDirs(string $dirs): array { $finder = new Finder(); - $finder->in($this->dir); + $finder->in($this->dir . '/' . $dirs); $contents = [];