Conditions | 4 |
Paths | 4 |
Total Lines | 23 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
28 | public function __invoke( |
||
29 | object $data, |
||
30 | string $property, |
||
31 | Request $request, |
||
32 | UploadableAnnotationReader $annotationReader, |
||
33 | UploadableHelper $uploadableHelper |
||
34 | ) { |
||
35 | if (!$annotationReader->isConfigured($data)) { |
||
36 | throw new InvalidArgumentException(sprintf('%s is not an uploadable resource. It should not be configured to use %s.', \get_class($data), __CLASS__)); |
||
37 | } |
||
38 | |||
39 | try { |
||
40 | $file = $uploadableHelper->getFile($data, $property); |
||
41 | } catch (InvalidArgumentException $e) { |
||
42 | // Property not configured, convert to not found URL |
||
43 | throw new NotFoundHttpException($e->getMessage()); |
||
44 | } |
||
45 | |||
46 | if (!$file) { |
||
|
|||
47 | throw new NotFoundHttpException('File not found.'); |
||
48 | } |
||
49 | |||
50 | return new BinaryFileResponse($file); |
||
51 | } |
||
53 |