Skip to content

Commit 68fb919

Browse files
committed
27: Cleaned up code
1 parent 79c2bef commit 68fb919

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ In order to make this behave as both a Drupal module and a Synfony bundle, we us
131131
// minimum to make this module/bundle work.
132132
"doctrine/dbal": "^3 || ^4",
133133
"doctrine/orm": "^2.8 || ^3",
134+
// These are required by Drupal 9 later
134135
"symfony/cache": "^6 || ^7",
136+
"symfony/http-foundation": "^6 || ^7",
137+
"symfony/http-kernel": "^6 || ^7",
138+
"symfony/mime": "^6 || ^7",
139+
"symfony/routing": "^6 || ^7",
135140
"twig/twig": "^3"
136141
},
137142
"autoload": {

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"doctrine/dbal": "^3 || ^4",
88
"doctrine/orm": "^2.8 || ^3",
99
"symfony/cache": "^6 || ^7",
10+
"symfony/http-foundation": "^6 || ^7",
1011
"symfony/http-kernel": "^6 || ^7",
12+
"symfony/mime": "^6 || ^7",
13+
"symfony/routing": "^6 || ^7",
1114
"twig/twig": "^3"
1215
},
1316
"require-dev": {

src/TidyFeedbackHelper.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2121
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
2222
use Symfony\Component\HttpKernel\KernelEvents;
23+
use Symfony\Component\Mime\MimeTypes;
2324
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2425
use Symfony\Component\Yaml\Yaml;
2526
use Twig\Environment;
@@ -153,15 +154,17 @@ public function createAssetResponse(string $asset): Response
153154
throw new NotFoundHttpException();
154155
}
155156

156-
$response = new BinaryFileResponse($filename, headers: [
157-
'content-type' => match (pathinfo($filename, PATHINFO_EXTENSION)) {
158-
'css' => 'text/css',
159-
'js' => 'text/javascript',
160-
'svg' => 'image/svg+xml',
161-
'png' => 'image/png',
162-
default => throw new NotFoundHttpException(),
163-
},
164-
],
157+
$ext = pathinfo($filename, PATHINFO_EXTENSION);
158+
$mimeTypes = new MimeTypes();
159+
$types = $mimeTypes->getMimeTypes($ext);
160+
if (empty($types)) {
161+
throw new NotFoundHttpException();
162+
}
163+
$response = new BinaryFileResponse(
164+
$filename,
165+
headers: [
166+
'content-type' => reset($types),
167+
],
165168
autoEtag: true, autoLastModified: true
166169
);
167170

0 commit comments

Comments
 (0)