add links to enter / exit folders

Reviewed-on: sites/file-explorer#5
This commit is contained in:
2024-12-05 10:58:30 +00:00
parent bf226d7e3f
commit a574c3a89a
8 changed files with 66 additions and 14 deletions

View File

@ -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),
]);
}

View File

@ -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 = [];

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace App\Service\Twig;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class RoutingService
{
public function __construct(private UrlGeneratorInterface $urlGenerator)
{
}
public function goBack(Request $request): string
{
$dirsString = $request->attributes->get('dirs', '');
$dirs = explode('/', $dirsString);
array_pop($dirs);
return $this->urlGenerator->generate('app_home', ['dirs' => implode('/', $dirs)]);
}
}