Revert "Fix PHP Fatal error "Method Icinga\File\Csv::__toString() must not throw an exception in /vagrant/test/php/library/Icinga/File/CsvTest.php on line 35""

This reverts commit f2fdd7f39df759ff27c9c133f40bbcae14820708.
This commit is contained in:
Alexander Klimov 2014-06-27 12:31:09 +02:00
parent 22e13ce282
commit 4b72e1b54f

View File

@ -5,7 +5,6 @@
namespace Icinga\File; namespace Icinga\File;
use Icinga\Data\Browsable; use Icinga\Data\Browsable;
use Exception;
class Csv class Csv
{ {
@ -28,24 +27,20 @@ class Csv
public function __toString() public function __toString()
{ {
try { $first = true;
$first = true; $csv = '';
$csv = ''; foreach ($this->query->getQuery()->fetchAll() as $row) {
foreach ($this->query->getQuery()->fetchAll() as $row) { if ($first) {
if ($first) { $csv .= implode(',', array_keys((array) $row)) . "\r\n";
$csv .= implode(',', array_keys((array) $row)) . "\r\n"; $first = false;
$first = false;
}
$out = array();
foreach ($row as & $val) {
$out[] = '"' . $val . '"';
}
$csv .= implode(',', $out) . "\r\n";
} }
$out = array();
return $csv; foreach ($row as & $val) {
} catch (Exception $e) { $out[] = '"' . $val . '"';
return (string) $e; }
$csv .= implode(',', $out) . "\r\n";
} }
return $csv;
} }
} }