1 | <?php |
||
2 | |||
3 | namespace ControleOnline\Controller; |
||
4 | |||
5 | use ControleOnline\Entity\File; |
||
6 | use Symfony\Component\HttpFoundation\HeaderUtils; |
||
0 ignored issues
–
show
|
|||
7 | use Symfony\Component\HttpFoundation\StreamedResponse; |
||
0 ignored issues
–
show
The type
Symfony\Component\HttpFoundation\StreamedResponse was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
8 | use Symfony\Component\HttpFoundation\Request; |
||
0 ignored issues
–
show
The type
Symfony\Component\HttpFoundation\Request was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
9 | use Symfony\Component\HttpKernel\KernelInterface; |
||
0 ignored issues
–
show
The type
Symfony\Component\HttpKernel\KernelInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
10 | use Doctrine\ORM\EntityManagerInterface; |
||
0 ignored issues
–
show
The type
Doctrine\ORM\EntityManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
11 | |||
12 | use Symfony\Component\HttpFoundation\JsonResponse; |
||
0 ignored issues
–
show
The type
Symfony\Component\HttpFoundation\JsonResponse was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
13 | |||
14 | |||
15 | |||
16 | class GetFileDataAction |
||
17 | { |
||
18 | /** |
||
19 | * Entity Manager |
||
20 | * |
||
21 | * @var EntityManagerInterface |
||
22 | */ |
||
23 | private $manager = null; |
||
24 | |||
25 | /** |
||
26 | * Synfony Kernel |
||
27 | * |
||
28 | * @var KernelInterface |
||
29 | */ |
||
30 | private $kernel; |
||
31 | |||
32 | public function __construct(EntityManagerInterface $entityManager, KernelInterface $appKernel) |
||
33 | { |
||
34 | $this->kernel = $appKernel; |
||
35 | $this->manager = $entityManager; |
||
36 | } |
||
37 | |||
38 | public function __invoke(File $data, Request $request) |
||
39 | { |
||
40 | |||
41 | try { |
||
42 | $file = $data; |
||
43 | //$file = $this->manager->getRepository(File::class)->findOneBy(['url' => $request->getPathInfo()]); |
||
44 | if (!$file) |
||
0 ignored issues
–
show
|
|||
45 | throw new \Exception('Not found', 404); |
||
46 | |||
47 | |||
48 | $content = $file->getContent(); |
||
49 | $response = new StreamedResponse(function () use ($content) { |
||
50 | fputs(fopen('php://output', 'wb'), $content); |
||
51 | }); |
||
52 | |||
53 | $fileType = $file->getFileType(); |
||
54 | $ext = $file->getExtension(); |
||
55 | if ($ext == 'svg') { |
||
56 | $response->headers->set('Content-Type', 'image/svg+xml'); |
||
57 | } else { |
||
58 | $response->headers->set('Content-Type', "$fileType/$ext"); |
||
59 | } |
||
60 | |||
61 | if ($fileType == 'image') |
||
62 | $disposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_INLINE, basename($request->getPathInfo())); |
||
63 | else |
||
64 | $disposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, basename($request->getPathInfo())); |
||
65 | |||
66 | $response->headers->set('Content-Disposition', $disposition); |
||
67 | |||
68 | return $response; |
||
69 | } catch (\Exception $e) { |
||
70 | return new JsonResponse([ |
||
71 | 'response' => [ |
||
72 | 'data' => [], |
||
73 | 'count' => 0, |
||
74 | 'error' => $e->getMessage(), |
||
75 | 'success' => false, |
||
76 | ], |
||
77 | ]); |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths