@@ -23,8 +23,7 @@ public static function fromXml(int $status, string $xml): ResponseInterface
2323
2424 public static function fromCsv (int $ status , string $ csv ): ResponseInterface
2525 {
26- $ response = self ::from ($ status , 'text/csv ' , $ csv );
27- return $ response ->withHeader ('Content-Type ' , 'text/csv ' );
26+ return self ::from ($ status , 'text/csv ' , $ csv );
2827 }
2928
3029 public static function fromHtml (int $ status , string $ html ): ResponseInterface
@@ -38,6 +37,17 @@ public static function fromObject(int $status, $body): ResponseInterface
3837 return self ::from ($ status , 'application/json ' , $ content );
3938 }
4039
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+
4151 private static function from (int $ status , string $ contentType , string $ content ): ResponseInterface
4252 {
4353 $ psr17Factory = new Psr17Factory ();
0 commit comments