@@ -3,6 +3,9 @@ |
||
| 3 | 3 | |
| 4 | 4 | interface ISerializer |
| 5 | 5 | { |
| 6 | + /** |
|
| 7 | + * @return boolean |
|
| 8 | + */ |
|
| 6 | 9 | public function supportsType($type); |
| 7 | 10 | public function serializeData($type, $array); |
| 8 | 11 | } |
@@ -7,9 +7,9 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | public function supportsType($type) |
| 9 | 9 | { |
| 10 | - foreach($this->types as $t) |
|
| 10 | + foreach ($this->types as $t) |
|
| 11 | 11 | { |
| 12 | - if(strcasecmp($t, $type) === 0) |
|
| 12 | + if (strcasecmp($t, $type) === 0) |
|
| 13 | 13 | { |
| 14 | 14 | return true; |
| 15 | 15 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public function serializeData($type, $array) |
| 21 | 21 | { |
| 22 | - if($this->supportsType($type) === false) |
|
| 22 | + if ($this->supportsType($type) === false) |
|
| 23 | 23 | { |
| 24 | 24 | return null; |
| 25 | 25 | } |
@@ -7,18 +7,18 @@ |
||
| 7 | 7 | |
| 8 | 8 | public function serializeData($type, $array) |
| 9 | 9 | { |
| 10 | - if($this->supportsType($type) === false) |
|
| 10 | + if ($this->supportsType($type) === false) |
|
| 11 | 11 | { |
| 12 | 12 | return null; |
| 13 | 13 | } |
| 14 | - if(count($array) === 0) |
|
| 14 | + if (count($array) === 0) |
|
| 15 | 15 | { |
| 16 | 16 | return null; |
| 17 | 17 | } |
| 18 | 18 | $data = $this->getArray($array); |
| 19 | 19 | ob_start(); |
| 20 | 20 | $df = fopen("php://output", 'w'); |
| 21 | - foreach($data as $row) |
|
| 21 | + foreach ($data as $row) |
|
| 22 | 22 | { |
| 23 | 23 | fputcsv($df, $row); |
| 24 | 24 | } |
@@ -5,9 +5,9 @@ discard block |
||
| 5 | 5 | { |
| 6 | 6 | public function supportsType($type) |
| 7 | 7 | { |
| 8 | - foreach($this->types as $t) |
|
| 8 | + foreach ($this->types as $t) |
|
| 9 | 9 | { |
| 10 | - if(strcasecmp($t, $type) === 0) |
|
| 10 | + if (strcasecmp($t, $type) === 0) |
|
| 11 | 11 | { |
| 12 | 12 | return true; |
| 13 | 13 | } |
@@ -18,42 +18,42 @@ discard block |
||
| 18 | 18 | protected function getArray(&$array) |
| 19 | 19 | { |
| 20 | 20 | $res = array(); |
| 21 | - if(is_object($array)) |
|
| 21 | + if (is_object($array)) |
|
| 22 | 22 | { |
| 23 | 23 | $array = get_object_vars($array); |
| 24 | 24 | } |
| 25 | 25 | $first = reset($array); |
| 26 | 26 | $keys = false; |
| 27 | - if(is_array($first)) |
|
| 27 | + if (is_array($first)) |
|
| 28 | 28 | { |
| 29 | 29 | $keys = array_keys($first); |
| 30 | 30 | } |
| 31 | - else if(is_object($first)) |
|
| 31 | + else if (is_object($first)) |
|
| 32 | 32 | { |
| 33 | 33 | $keys = array_keys(get_object_vars($first)); |
| 34 | 34 | } |
| 35 | 35 | $colCount = count($keys); |
| 36 | 36 | $res[] = $keys; |
| 37 | - foreach($array as $row) |
|
| 37 | + foreach ($array as $row) |
|
| 38 | 38 | { |
| 39 | 39 | $tmp = array(); |
| 40 | - if(is_object($row)) |
|
| 40 | + if (is_object($row)) |
|
| 41 | 41 | { |
| 42 | 42 | $row = get_object_vars($row); |
| 43 | 43 | } |
| 44 | - if(!is_array($row)) |
|
| 44 | + if (!is_array($row)) |
|
| 45 | 45 | { |
| 46 | 46 | $row = array($row); |
| 47 | 47 | } |
| 48 | - for($j = 0; $j < $colCount; $j++) |
|
| 48 | + for ($j = 0; $j < $colCount; $j++) |
|
| 49 | 49 | { |
| 50 | 50 | $colName = $keys[$j]; |
| 51 | - if(isset($row[$colName])) |
|
| 51 | + if (isset($row[$colName])) |
|
| 52 | 52 | { |
| 53 | 53 | $value = $row[$colName]; |
| 54 | - if(is_object($value)) |
|
| 54 | + if (is_object($value)) |
|
| 55 | 55 | { |
| 56 | - switch($colName) |
|
| 56 | + switch ($colName) |
|
| 57 | 57 | { |
| 58 | 58 | case '_id': |
| 59 | 59 | $value = $value->{'$id'}; |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | break; |
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | - else if(is_array($value)) |
|
| 66 | + else if (is_array($value)) |
|
| 67 | 67 | { |
| 68 | 68 | $value = implode(',', $value); |
| 69 | 69 | } |
@@ -27,8 +27,7 @@ discard block |
||
| 27 | 27 | if(is_array($first)) |
| 28 | 28 | { |
| 29 | 29 | $keys = array_keys($first); |
| 30 | - } |
|
| 31 | - else if(is_object($first)) |
|
| 30 | + } else if(is_object($first)) |
|
| 32 | 31 | { |
| 33 | 32 | $keys = array_keys(get_object_vars($first)); |
| 34 | 33 | } |
@@ -62,14 +61,12 @@ discard block |
||
| 62 | 61 | $value = json_encode($value); |
| 63 | 62 | break; |
| 64 | 63 | } |
| 65 | - } |
|
| 66 | - else if(is_array($value)) |
|
| 64 | + } else if(is_array($value)) |
|
| 67 | 65 | { |
| 68 | 66 | $value = implode(',', $value); |
| 69 | 67 | } |
| 70 | 68 | $tmp[] = $value; |
| 71 | - } |
|
| 72 | - else |
|
| 69 | + } else |
|
| 73 | 70 | { |
| 74 | 71 | $tmp[] = false; |
| 75 | 72 | } |