summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/AbstractCsv.php2
-rw-r--r--src/Config/Controls.php28
-rw-r--r--src/Iterator/Filter.php14
-rw-r--r--src/Iterator/SortBy.php14
-rw-r--r--src/Reader.php31
-rw-r--r--src/Writer.php19
-rw-r--r--test/CsvTest.php6
-rw-r--r--test/ReaderTest.php10
-rw-r--r--test/WriterTest.php6
9 files changed, 115 insertions, 15 deletions
diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php
index 94f0883..f493919 100644
--- a/src/AbstractCsv.php
+++ b/src/AbstractCsv.php
@@ -169,7 +169,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
public function getIterator()
{
$obj = $this->path;
- if (! $obj instanceof SplTempFileObject) {
+ if (! $obj instanceof SplFileObject) {
$obj = new SplFileObject($this->getStreamFilterPath(), $this->open_mode);
}
$obj->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
diff --git a/src/Config/Controls.php b/src/Config/Controls.php
index 7306a56..e38e6f0 100644
--- a/src/Config/Controls.php
+++ b/src/Config/Controls.php
@@ -21,7 +21,7 @@ use League\Csv\Iterator\MapIterator;
* A trait to configure and check CSV file and content
*
* @package League.csv
- * @since 6.0.0
+ * @since 5.5.0
*
*/
trait Controls
@@ -175,6 +175,32 @@ trait Controls
}
/**
+ * DEPRECATION WARNING! This method will be removed in the next major point release
+ *
+ * @deprecated deprecated since version 5.5
+ *
+ * @param string $str
+ *
+ * @return self
+ */
+ public function setEncoding($str)
+ {
+ return $this->setEncodingFrom($str);
+ }
+
+ /**
+ * DEPRECATION WARNING! This method will be removed in the next major point release
+ *
+ * @deprecated deprecated since version 5.5
+ *
+ * @return string
+ */
+ public function getEncoding()
+ {
+ return $this->getEncodingFrom();
+ }
+
+ /**
* Set the CSV encoding charset
*
* @param string $str
diff --git a/src/Iterator/Filter.php b/src/Iterator/Filter.php
index dc032e7..f279a97 100644
--- a/src/Iterator/Filter.php
+++ b/src/Iterator/Filter.php
@@ -33,6 +33,20 @@ trait Filter
protected $iterator_filters = [];
/**
+ * DEPRECATION WARNING! This method will be removed in the next major point release
+ *
+ * @deprecated deprecated since version 5.1
+ *
+ * @param callable $callable
+ *
+ * @return self
+ */
+ public function setFilter(callable $callable)
+ {
+ return $this->addFilter($callable);
+ }
+
+ /**
* Set the Iterator filter method
*
* @param callable $callable
diff --git a/src/Iterator/SortBy.php b/src/Iterator/SortBy.php
index b59d92d..ad462d2 100644
--- a/src/Iterator/SortBy.php
+++ b/src/Iterator/SortBy.php
@@ -33,6 +33,20 @@ trait SortBy
protected $iterator_sort_by = [];
/**
+ * DEPRECATION WARNING! This method will be removed in the next major point release
+ *
+ * @deprecated deprecated since version 5.2
+ *
+ * @param callable $callable
+ *
+ * @return self
+ */
+ public function setSortBy(callable $callable)
+ {
+ return $this->addSortBy($callable);
+ }
+
+ /**
* Set an Iterator sorting callable function
*
* @param callable $callable
diff --git a/src/Reader.php b/src/Reader.php
index ebcde2f..b3a2360 100644
--- a/src/Reader.php
+++ b/src/Reader.php
@@ -185,6 +185,23 @@ class Reader extends AbstractCsv
}
/**
+ * DEPRECATION WARNING! This method will be removed in the next major point release
+ *
+ * @deprecated deprecated since version 5.5
+ *
+ * @param integer $column_index field Index
+ * @param callable $callable a callable function to be applied to each value to be return
+ *
+ * @return array
+ *
+ * @throws \InvalidArgumentException If the column index is not a positive integer or 0
+ */
+ public function fetchCol($column_index = 0, callable $callable = null)
+ {
+ return $this->fetchColumn($column_index, $callable);
+ }
+
+ /**
* Return a single column from the CSV data
*
* @param integer $column_index field Index
@@ -215,6 +232,20 @@ class Reader extends AbstractCsv
}
/**
+ * DEPRECATION WARNING! This method will be removed in the next major point release
+ *
+ * @deprecated deprecated since version 5.5
+ *
+ * @param string $open_mode the file open mode flag
+ *
+ * @return \League\Csv\Writer object
+ */
+ public function getWriter($open_mode = 'r+')
+ {
+ return $this->newWriter($open_mode);
+ }
+
+ /**
* Create a {@link Writer} instance from a {@link Reader} object
*
* @param string $open_mode the file open mode flag
diff --git a/src/Writer.php b/src/Writer.php
index 215fd86..8602fed 100644
--- a/src/Writer.php
+++ b/src/Writer.php
@@ -15,6 +15,7 @@ namespace League\Csv;
use Traversable;
use SplFileObject;
use InvalidArgumentException;
+use RuntimeException;
use OutOfBoundsException;
/**
@@ -278,7 +279,7 @@ class Writer extends AbstractCsv
$data = $this->validateRow($data);
$data = $this->sanitizeColumnsContent($data);
if (! $this->isColumnsCountConsistent($data)) {
- throw new InvalidArgumentException(
+ throw new RuntimeException(
'You are trying to add '.count($data).' columns to a CSV
that requires '.$this->columns_count.' columns per row.'
);
@@ -315,11 +316,25 @@ class Writer extends AbstractCsv
}
/**
+ * DEPRECATION WARNING! This method will be removed in the next major point release
+ *
+ * @deprecated deprecated since version 5.5
+ *
+ * @param string $open_mode the file open mode flag
+ *
+ * @return \League\Csv\Reader object
+ */
+ public function getReader($open_mode = 'r+')
+ {
+ return $this->newReader($open_mode);
+ }
+
+ /**
* Create a {@link Reader} instance from a {@link Writer} object
*
* @param string $open_mode the file open mode flag
*
- * @return \League\Csv\Writer object
+ * @return \League\Csv\Reader object
*/
public function newReader($open_mode = 'r+')
{
diff --git a/test/CsvTest.php b/test/CsvTest.php
index 2898180..cc6c9c7 100644
--- a/test/CsvTest.php
+++ b/test/CsvTest.php
@@ -164,10 +164,10 @@ class CsvTest extends PHPUnit_Framework_TestCase
public function testEncoding()
{
$expected = 'iso-8859-15';
- $this->csv->setEncodingFrom($expected);
- $this->assertSame(strtoupper($expected), $this->csv->getEncodingFrom());
+ $this->csv->setEncoding($expected);
+ $this->assertSame(strtoupper($expected), $this->csv->getEncoding());
- $this->csv->setEncodingFrom('');
+ $this->csv->setEncoding('');
}
public function testToString()
diff --git a/test/ReaderTest.php b/test/ReaderTest.php
index 54deea4..fb3f919 100644
--- a/test/ReaderTest.php
+++ b/test/ReaderTest.php
@@ -68,7 +68,7 @@ class ReaderTest extends PHPUnit_Framework_TestCase
$func = function ($row) {
return ! in_array('jane', $row);
};
- $this->csv->addFilter($func);
+ $this->csv->setFilter($func);
$this->assertCount(1, $this->csv->fetchAll());
@@ -94,7 +94,7 @@ class ReaderTest extends PHPUnit_Framework_TestCase
$func = function ($rowA, $rowB) {
return strcmp($rowA[0], $rowB[0]);
};
- $this->csv->addSortBy($func);
+ $this->csv->setSortBy($func);
$this->assertSame(array_reverse($this->expected), $this->csv->fetchAll());
$this->csv->addSortBy($func);
@@ -111,7 +111,7 @@ class ReaderTest extends PHPUnit_Framework_TestCase
$func = function ($rowA, $rowB) {
return strcmp($rowA[0], $rowB[0]);
};
- $csv->addSortBy($func);
+ $csv->setSortBy($func);
$this->assertSame([
['john', 'doe', 'john.doe@example.com'],
['john', 'doe', 'john.doe@example.com']
@@ -178,7 +178,7 @@ class ReaderTest extends PHPUnit_Framework_TestCase
public function testFetchCol()
{
- $this->assertSame(['john', 'jane'], $this->csv->fetchColumn(0));
+ $this->assertSame(['john', 'jane'], $this->csv->fetchCol(0));
$this->assertSame(['john', 'jane'], $this->csv->fetchColumn());
}
@@ -276,7 +276,7 @@ EOF;
public function testGetWriter2()
{
- $csv = (new Reader(__DIR__.'/foo.csv'))->newWriter('a+');
+ $csv = (new Reader(__DIR__.'/foo.csv'))->getWriter('a+');
$this->assertInstanceOf('\League\Csv\Writer', $csv);
}
}
diff --git a/test/WriterTest.php b/test/WriterTest.php
index 86db64a..ff67e73 100644
--- a/test/WriterTest.php
+++ b/test/WriterTest.php
@@ -115,7 +115,7 @@ class WriterTest extends PHPUnit_Framework_TestCase
}
/**
- * @expectedException InvalidArgumentException
+ * @expectedException RuntimeException
*/
public function testColumsCountConsistency()
{
@@ -127,7 +127,7 @@ class WriterTest extends PHPUnit_Framework_TestCase
}
/**
- * @expectedException InvalidArgumentException
+ * @expectedException RuntimeException
*/
public function testAutoDetectColumnsCount()
{
@@ -189,7 +189,7 @@ class WriterTest extends PHPUnit_Framework_TestCase
$this->csv->insertOne($row);
}
- $reader = $this->csv->newReader();
+ $reader = $this->csv->getReader();
$this->assertSame(['john', 'doe', 'john.doe@example.com'], $reader->fetchOne(0));
}
}