-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathFeedResultsAction.php
More file actions
53 lines (45 loc) · 1.64 KB
/
Copy pathFeedResultsAction.php
File metadata and controls
53 lines (45 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
namespace Setono\SyliusFeedPlugin\Controller\Admin;
use League\Flysystem\FileAttributes;
use League\Flysystem\FilesystemOperator;
use Setono\SyliusFeedPlugin\Model\FeedInterface;
use Setono\SyliusFeedPlugin\Repository\FeedRepositoryInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Twig\Environment;
/**
* Admin per-context results view (§13): lists the feed's generated files in canonical storage with
* download links to the public route.
*/
final class FeedResultsAction
{
public function __construct(
private readonly FeedRepositoryInterface $feedRepository,
private readonly FilesystemOperator $feedFilesystem,
private readonly Environment $twig,
) {
}
public function __invoke(int|string $id): Response
{
$feed = $this->feedRepository->find($id);
if (!$feed instanceof FeedInterface) {
throw new NotFoundHttpException(sprintf('There is no feed with id "%s"', $id));
}
$files = [];
foreach ($this->feedFilesystem->listContents((string) $feed->getCode(), false) as $item) {
if (!$item instanceof FileAttributes) {
continue;
}
$files[] = [
'filename' => basename($item->path()),
'size' => $item->fileSize(),
'lastModified' => $item->lastModified(),
];
}
return new Response($this->twig->render('@SetonoSyliusFeedPlugin/admin/feed/results.html.twig', [
'feed' => $feed,
'files' => $files,
]));
}
}