@@ -23,8 +23,7 @@ public static function fromXml(int $status, string $xml): ResponseInterface
23
23
24
24
public static function fromCsv (int $ status , string $ csv ): ResponseInterface
25
25
{
26
- $ response = self ::from ($ status , 'text/csv ' , $ csv );
27
- return $ response ->withHeader ('Content-Type ' , 'text/csv ' );
26
+ return self ::from ($ status , 'text/csv ' , $ csv );
28
27
}
29
28
30
29
public static function fromHtml (int $ status , string $ html ): ResponseInterface
@@ -38,6 +37,17 @@ public static function fromObject(int $status, $body): ResponseInterface
38
37
return self ::from ($ status , 'application/json ' , $ content );
39
38
}
40
39
40
+ public static function fromFile (int $ status , string $ filename ): ResponseInterface
41
+ {
42
+ $ psr17Factory = new Psr17Factory ();
43
+ $ response = $ psr17Factory ->createResponse ($ status );
44
+ $ stream = $ psr17Factory ->createStreamFromFile ($ filename );
45
+ $ response = $ response ->withBody ($ stream );
46
+ $ response = $ response ->withHeader ('Content-Type ' , mime_content_type (basename ($ filename )));
47
+ $ response = $ response ->withHeader ('Content-Length ' , filesize ($ filename ));
48
+ return $ response ;
49
+ }
50
+
41
51
private static function from (int $ status , string $ contentType , string $ content ): ResponseInterface
42
52
{
43
53
$ psr17Factory = new Psr17Factory ();
0 commit comments