This commit is contained in:
Simon Vieille 2015-03-09 20:06:08 +01:00
parent b180f00940
commit 4eb4568215

View file

@ -10,8 +10,6 @@ class Csv
private $enclosure; private $enclosure;
private $escape_char;
private $endline; private $endline;
private $datas; private $datas;
@ -24,11 +22,10 @@ class Csv
private $hasLegend = false; private $hasLegend = false;
public function __construct($delimiter = ';', $enclosure = '"', $escape_char = '\\', $endline = "\n", $encoding = 'UTF-8') public function __construct($delimiter = ';', $enclosure = '"', $endline = "\n", $encoding = 'UTF-8')
{ {
$this->setDelimiter($delimiter); $this->setDelimiter($delimiter);
$this->setEnclosure($enclosure); $this->setEnclosure($enclosure);
$this->setEscapeChar($escape_char);
$this->setEndLine($endline); $this->setEndLine($endline);
$this->setEncoding($encoding); $this->setEncoding($encoding);
$this->datas = array(0 => null); $this->datas = array(0 => null);
@ -57,6 +54,11 @@ class Csv
return $this->hasLegend; return $this->hasLegend;
} }
public function hasLegend()
{
return $this->hasLegend;
}
public function setLegend(array $values) public function setLegend(array $values)
{ {
$this->setHasLegend(true); $this->setHasLegend(true);
@ -114,15 +116,6 @@ class Csv
$this->enclose = $v; $this->enclose = $v;
} }
public function setEscapeChar($v)
{
if (!is_string($v)) {
throw new CsvInvalidParameterException(sprintf('"%s" is not a valid string.', $v));
}
$this->escape_char = $v;
}
public function getLegend() public function getLegend()
{ {
return $this->legend; return $this->legend;
@ -137,13 +130,13 @@ class Csv
{ {
$this->render = ""; $this->render = "";
if (isset($this->datas[0]) && $this->datas[0] !== null) { if ($this->datas[0] !== null) {
$this->append($this->datasToCsvLine($this->datas[0])); $this->append($this->datasToCsvLine($this->datas[0]));
} }
unset($this->datas[0]); unset($this->datas[0]);
foreach ($this->datas as $k => $v) { foreach ($this->datas as $v) {
$this->append($this->datasToCsvLine($v)); $this->append($this->datasToCsvLine($v));
} }
@ -160,7 +153,7 @@ class Csv
public function hasDatas() public function hasDatas()
{ {
return count($this->datas) > ($this->getHasLegend() ? 1 : 0); return count($this->datas) > 1;
} }
protected function datasToCsvLine($datas) protected function datasToCsvLine($datas)