44namespace Sujan \Exporter ;
55
66
7- use Exception ;
8- use Sujan \Exporter \Contracts \ExporterContract ;
97
108class Export
119{
@@ -33,10 +31,13 @@ class Export
3331 * Array of content types
3432 */
3533 private $ contentTypes = [
36- '. csv ' => 'application/csv ' ,
37- '. xlsx ' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet '
34+ 'csv ' => 'application/csv ' ,
35+ 'xlsx ' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet '
3836 ];
3937
38+ /*
39+ * Content type
40+ */
4041 private $ contentType ;
4142
4243 /**
@@ -49,14 +50,18 @@ class Export
4950 */
5051 protected $ delimiter = "; " ;
5152
53+ /**
54+ * @param array | object $model
55+ * @param array $columns
56+ * @param string $filename
57+ */
5258 protected function setConfiguration ($ model , array $ columns , string $ filename )
5359 {
5460 $ this ->setModel ($ model );
5561 $ this ->setColumns ($ columns );
5662 $ this ->setHeading ($ columns );
5763 $ this ->setFilename ($ filename );
5864 $ this ->setContentType ();
59- $ this ->openOutputStream ();
6065 }
6166
6267 /**
@@ -102,18 +107,27 @@ public function setContentType()
102107
103108 if (!$ parts [0 ]) {
104109 $ this ->filename = $ this ->filename . '.csv ' ;
105- $ this ->contentType = $ this ->contentTypes ['. csv ' ];
110+ $ this ->contentType = $ this ->contentTypes ['csv ' ];
106111 } else {
107- $ this ->contentType = $ this ->contentTypes [strtolower ($ parts [0 ])];
112+ $ this ->contentType = $ this ->contentTypes [trim ( strtolower ($ parts [0 ]), ' . ' )];
108113 }
109114
110115 header ("Content-Type: {$ this ->contentType }" );
111116 header ("Content-Disposition: attachment; filename= {$ this ->filename }; " );
112117 }
113118
114- private function openOutputStream ()
119+ /**
120+ * Open the "output" stream
121+ */
122+ protected function openOutputStream ()
115123 {
116- // open the "output" stream
117124 $ this ->file = fopen ('php://output ' , 'w ' );
118125 }
126+
127+ /**
128+ * Close output stream
129+ */
130+ protected function closeOutputStream () {
131+ fclose ($ this ->file );
132+ }
119133}
0 commit comments