@@ -59,6 +59,7 @@ public function create(
59
59
$ dir = $ this ->_filesystem ->getDirectoryWrite ($ baseDir );
60
60
$ isFile = false ;
61
61
$ file = null ;
62
+ $ fileContent = $ this ->getFileContent ($ content );
62
63
if (is_array ($ content )) {
63
64
if (!isset ($ content ['type ' ]) || !isset ($ content ['value ' ])) {
64
65
throw new \InvalidArgumentException ("Invalid arguments. Keys 'type' and 'value' are required. " );
@@ -76,11 +77,7 @@ public function create(
76
77
->setHeader ('Pragma ' , 'public ' , true )
77
78
->setHeader ('Cache-Control ' , 'must-revalidate, post-check=0, pre-check=0 ' , true )
78
79
->setHeader ('Content-type ' , $ contentType , true )
79
- ->setHeader (
80
- 'Content-Length ' ,
81
- $ contentLength === null ? strlen ($ this ->getFileContent ($ content )) : $ contentLength ,
82
- true
83
- )
80
+ ->setHeader ('Content-Length ' , $ contentLength === null ? strlen ($ fileContent ) : $ contentLength , true )
84
81
->setHeader ('Content-Disposition ' , 'attachment; filename=" ' . $ fileName . '" ' , true )
85
82
->setHeader ('Last-Modified ' , date ('r ' ), true );
86
83
@@ -92,7 +89,7 @@ public function create(
92
89
echo $ stream ->read (1024 );
93
90
}
94
91
} else {
95
- $ dir ->writeFile ($ fileName , $ this -> getFileContent ( $ content ) );
92
+ $ dir ->writeFile ($ fileName , $ fileContent );
96
93
$ file = $ fileName ;
97
94
$ stream = $ dir ->openFile ($ fileName , 'r ' );
98
95
while (!$ stream ->eof ()) {
@@ -114,9 +111,9 @@ public function create(
114
111
* @param string|array $content
115
112
* @return string
116
113
*/
117
- private function getFileContent ($ content )
114
+ private function getFileContent ($ content ): string
118
115
{
119
- if (isset ($ content ['type ' ]) && $ content ['type ' ] == 'string ' ) {
116
+ if (isset ($ content ['type ' ]) && $ content ['type ' ] === 'string ' ) {
120
117
return $ content ['value ' ];
121
118
}
122
119
0 commit comments