summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md7
-rw-r--r--src/AbstractCsv.php5
-rw-r--r--src/Config/Controls.php4
-rw-r--r--src/Config/Factory.php4
-rw-r--r--src/Config/Output.php72
-rw-r--r--src/Config/StreamFilter.php2
-rw-r--r--src/Iterator/MapIterator.php2
-rw-r--r--src/Iterator/Query.php2
-rw-r--r--src/Reader.php5
-rw-r--r--src/Writer.php2
-rw-r--r--test/CsvTest.php4
11 files changed, 59 insertions, 50 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8f171f3..a733d08 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,18 +5,21 @@ All Notable changes to `League\Csv` will be documented in this file
### Added
-- `Writer::DISABLE_NULL_HANDLING` To completely remove null handling when inserting new data.
+- `Writer::NULL_HANDLING_DISABLED` To completely remove null handling when inserting new data.
- `Writer::useValidation` To enable/disabled complete validation when inserting new data.
+- The following outputting methods (`toXML`, `toHTML`) can be modified using `Reader` extracting methods.
### Fixed
- `AbstractCSV::createFromString` now accepts `$newline` a second argument to specify the last added new line character. To better work with interoperability.
-- All output methods (`toXML`, `toHTML`, `output`, `__toString`) can be modified using `Reader` extract methods.
+- `AbstractCSV::detectDelimiterList` index keys now represents the total number of occurences of the found delimiter.
+
## 6.3.0 - 2015-01-21
### Added
+
- `AbstractCSV::setOutputBOM`
- `AbstractCSV::getOutputBOM`
- `AbstractCSV::getInputBOM`
diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php
index a792c4f..c09773c 100644
--- a/src/AbstractCsv.php
+++ b/src/AbstractCsv.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.3.0
+* @version 7.0.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
@@ -155,6 +155,9 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
return $obj;
}
+ /**
+ * {@inheritdoc}
+ */
protected function getOutputIterator()
{
return $this->getIterator();
diff --git a/src/Config/Controls.php b/src/Config/Controls.php
index 6479d88..ba2aeee 100644
--- a/src/Config/Controls.php
+++ b/src/Config/Controls.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.3.0
+* @version 7.0.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
@@ -141,7 +141,7 @@ trait Controls
arsort($res, SORT_NUMERIC);
- return array_keys(array_filter($res));
+ return array_flip(array_filter($res));
}
/**
diff --git a/src/Config/Factory.php b/src/Config/Factory.php
index 00f69b2..80eef38 100644
--- a/src/Config/Factory.php
+++ b/src/Config/Factory.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.X.X
+* @version 7.0.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
@@ -21,7 +21,7 @@ use SplTempFileObject;
* A trait to facilate class instantiation
*
* @package League.csv
- * @since 6.4.0
+ * @since 7.0.0
*
*/
trait Factory
diff --git a/src/Config/Output.php b/src/Config/Output.php
index ed84ca0..dcdd5f4 100644
--- a/src/Config/Output.php
+++ b/src/Config/Output.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.3.0
+* @version 7.0.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
@@ -42,21 +42,11 @@ trait Output
/**
* Return the CSV Iterator
*
- * @return \SplFileObject
+ * @return \Iterator
*/
abstract protected function getOutputIterator();
/**
- * JsonSerializable Interface
- *
- * @return array
- */
- public function jsonSerialize()
- {
- return iterator_to_array($this->convertToUtf8($this->getOutputIterator()), false);
- }
-
- /**
* Set the CSV encoding charset
*
* @param string $str
@@ -122,10 +112,8 @@ trait Output
*/
public function output($filename = null)
{
- $iterator = $this->getOutputIterator();
- $iterator->rewind();
//@codeCoverageIgnoreStart
- if (! is_null($filename) && self::isValidString($filename)) {
+ if (! is_null($filename)) {
$filename = trim($filename);
$filename = filter_var($filename, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
header("Content-Type: application/octet-stream");
@@ -133,6 +121,8 @@ trait Output
header('Content-Disposition: attachment; filename="'.$filename);
}
//@codeCoverageIgnoreEnd
+ $iterator = $this->getIterator();
+ $iterator->rewind();
echo $this->bom;
$iterator->fpassthru();
}
@@ -151,6 +141,37 @@ trait Output
}
/**
+ * JsonSerializable Interface
+ *
+ * @return array
+ */
+ public function jsonSerialize()
+ {
+ return iterator_to_array($this->convertToUtf8($this->getIterator()), false);
+ }
+
+ /**
+ * Convert Csv file into UTF-8
+ *
+ * @return \Traversable
+ */
+ protected function convertToUtf8(Traversable $iterator)
+ {
+ if (strpos($this->encodingFrom, 'UTF-8') !== false) {
+ return $iterator;
+ }
+
+ return new MapIterator($iterator, function ($row) {
+ foreach ($row as &$value) {
+ $value = mb_convert_encoding($value, 'UTF-8', $this->encodingFrom);
+ }
+ unset($value);
+
+ return $row;
+ });
+ }
+
+ /**
* Return a HTML table representation of the CSV Table
*
* @param string $class_name optional classname
@@ -193,25 +214,4 @@ trait Output
return $doc;
}
-
- /**
- * Convert Csv file into UTF-8
- *
- * @return \Traversable
- */
- protected function convertToUtf8(Traversable $iterator)
- {
- if (strpos($this->encodingFrom, 'UTF-8') !== false) {
- return $iterator;
- }
-
- return new MapIterator($iterator, function ($row) {
- foreach ($row as &$value) {
- $value = mb_convert_encoding($value, 'UTF-8', $this->encodingFrom);
- }
- unset($value);
-
- return $row;
- });
- }
}
diff --git a/src/Config/StreamFilter.php b/src/Config/StreamFilter.php
index 330f62d..cf2aa8f 100644
--- a/src/Config/StreamFilter.php
+++ b/src/Config/StreamFilter.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.3.0
+* @version 7.0.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
diff --git a/src/Iterator/MapIterator.php b/src/Iterator/MapIterator.php
index 9077a3e..5e837ca 100644
--- a/src/Iterator/MapIterator.php
+++ b/src/Iterator/MapIterator.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.3.0
+* @version 7.0.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
diff --git a/src/Iterator/Query.php b/src/Iterator/Query.php
index f732af7..cb405cb 100644
--- a/src/Iterator/Query.php
+++ b/src/Iterator/Query.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.3.0
+* @version 7.0.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
diff --git a/src/Reader.php b/src/Reader.php
index 7952875..3986720 100644
--- a/src/Reader.php
+++ b/src/Reader.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.3.0
+* @version 7.0.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
@@ -61,6 +61,9 @@ class Reader extends AbstractCsv
return $iterator;
}
+ /**
+ * {@inheritdoc}
+ */
protected function getOutputIterator()
{
$iterator = $this->getIterator();
diff --git a/src/Writer.php b/src/Writer.php
index f19b4b4..6a7067c 100644
--- a/src/Writer.php
+++ b/src/Writer.php
@@ -4,7 +4,7 @@
*
* @license http://opensource.org/licenses/MIT
* @link https://github.com/thephpleague/csv/
-* @version 6.3.0
+* @version 7.0.0
* @package League.csv
*
* For the full copyright and license information, please view the LICENSE
diff --git a/test/CsvTest.php b/test/CsvTest.php
index 5dc79c2..2172cf2 100644
--- a/test/CsvTest.php
+++ b/test/CsvTest.php
@@ -112,7 +112,7 @@ class CsvTest extends PHPUnit_Framework_TestCase
public function testDetectDelimiterList()
{
- $this->assertSame([','], $this->csv->detectDelimiterList());
+ $this->assertSame([4 => ','], $this->csv->detectDelimiterList());
}
public function testBOMSettings()
@@ -176,7 +176,7 @@ class CsvTest extends PHPUnit_Framework_TestCase
$data->fputcsv(['toto', 'tata', 'tutu']);
$csv = Writer::createFromFileObject($data);
- $this->assertSame(['|', ';'], $csv->detectDelimiterList(5, ['|']));
+ $this->assertSame([12 => '|', 4 => ';'], $csv->detectDelimiterList(5, ['|']));
}
/**