@@ -53,7 +53,7 @@ public function encode($data, $format, array $context = array())
5353 {
5454 $ handle = fopen ('php://temp, ' , 'w+ ' );
5555
56- if (!\is_array ($ data )) {
56+ if (!( \is_array ($ data) || $ data instanceof \Traversable )) {
5757 $ data = array (array ($ data ));
5858 } elseif (empty ($ data )) {
5959 $ data = array (array ());
@@ -185,10 +185,10 @@ public function supportsDecoding($format)
185185 /**
186186 * Flattens an array and generates keys including the path.
187187 */
188- private function flatten (array $ array , array &$ result , string $ keySeparator , string $ parentKey = '' , bool $ escapeFormulas = false )
188+ private function flatten ($ array , array &$ result , string $ keySeparator , string $ parentKey = '' , bool $ escapeFormulas = false )
189189 {
190190 foreach ($ array as $ key => $ value ) {
191- if (\is_array ($ value )) {
191+ if (\is_array ($ value ) || $ value instanceof \Traversable ) {
192192 $ this ->flatten ($ value , $ result , $ keySeparator , $ parentKey .$ key .$ keySeparator , $ escapeFormulas );
193193 } else {
194194 if ($ escapeFormulas && \in_array (substr ($ value , 0 , 1 ), $ this ->formulasStartCharacters , true )) {
@@ -219,7 +219,7 @@ private function getCsvOptions(array $context)
219219 /**
220220 * @return string[]
221221 */
222- private function extractHeaders (array $ data )
222+ private function extractHeaders ($ data )
223223 {
224224 $ headers = array ();
225225 $ flippedHeaders = array ();
0 commit comments