Skip to content

Commit

Permalink
Bug fix #213 and #208
Browse files Browse the repository at this point in the history
- Remove the @deprecate message from the Reader class #208
- Bug fix internal Reader::getRow when used with a StreamIterator #213
  • Loading branch information
nyamsprod committed Feb 22, 2017
1 parent ef7eef7 commit 8992405
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 48 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

All Notable changes to `Csv` will be documented in this file

## 8.2.1 - 2017-02-22

### Added

- None

### Deprecated

- None

### Fixed

- internal `Reader::getRow` when using a `StreamIterator` [issue #213](https://github.com/thephpleague/csv/issues/213)
- Removed `@deprecated` from selected methods [issue #208](https://github.com/thephpleague/csv/issues/213)

### Removed

- None

## 8.2.0 - 2017-01-25

### Added
Expand Down
4 changes: 0 additions & 4 deletions src/Modifier/QueryFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ trait QueryFilter
/**
* Stripping BOM setter
*
* DEPRECATION WARNING! This method will be removed in the next major point release
*
* @deprecated deprecated since version 8.2
*
* @param bool $status
*
* @return $this
Expand Down
24 changes: 0 additions & 24 deletions src/Modifier/RowFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ public function addFormatter(callable $callable)
/**
* Remove a formatter from the collection
*
* DEPRECATION WARNING! This method will be removed in the next major point release
*
* @deprecated deprecated since version 8.2
*
* @param callable $callable
*
* @return $this
Expand All @@ -73,10 +69,6 @@ public function removeFormatter(callable $callable)
/**
* Detect if the formatter is already registered
*
* DEPRECATION WARNING! This method will be removed in the next major point release
*
* @deprecated deprecated since version 8.2
*
* @param callable $callable
*
* @return bool
Expand All @@ -89,10 +81,6 @@ public function hasFormatter(callable $callable)
/**
* Remove all registered formatter
*
* DEPRECATION WARNING! This method will be removed in the next major point release
*
* @deprecated deprecated since version 8.2
*
* @return $this
*/
public function clearFormatters()
Expand Down Expand Up @@ -127,10 +115,6 @@ abstract protected function validateString($str);
/**
* Remove a validator from the collection
*
* DEPRECATION WARNING! This method will be removed in the next major point release
*
* @deprecated deprecated since version 8.2
*
* @param string $name the validator name
*
* @return $this
Expand All @@ -146,10 +130,6 @@ public function removeValidator($name)
/**
* Detect if a validator is already registered
*
* DEPRECATION WARNING! This method will be removed in the next major point release
*
* @deprecated deprecated since version 8.2
*
* @param string $name the validator name
*
* @return bool
Expand All @@ -164,10 +144,6 @@ public function hasValidator($name)
/**
* Remove all registered validators
*
* DEPRECATION WARNING! This method will be removed in the next major point release
*
* @deprecated deprecated since version 8.2
*
* @return $this
*/
public function clearValidators()
Expand Down
32 changes: 12 additions & 20 deletions src/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Iterator;
use League\Csv\Modifier\MapIterator;
use LimitIterator;
use SplFileObject;

/**
* A class to manage extracting and filtering a CSV
Expand Down Expand Up @@ -50,10 +49,6 @@ public function fetchAll(callable $callable = null)
/**
* Fetch the next row from a result set
*
* DEPRECATION WARNING! This method will be removed in the next major point release
*
* @deprecated deprecated since version 8.2
*
* @param callable|null $callable a callable function to be applied to each Iterator item
*
* @return Iterator
Expand Down Expand Up @@ -83,10 +78,6 @@ protected function applyCallable(Iterator $iterator, callable $callable = null)
/**
* Applies a callback function on the CSV
*
* DEPRECATION WARNING! This method will be removed in the next major point release
*
* @deprecated deprecated since version 8.2
*
* The callback function must return TRUE in order to continue
* iterating over the iterator.
*
Expand Down Expand Up @@ -166,6 +157,7 @@ public function fetchColumn($column_index = 0, callable $callable = null)
* DEPRECATION WARNING! This method will be removed in the next major point release
*
* @deprecated deprecated since version 8.2
* @see Reader::fetchPairs
*
* Fetches an associative array of all rows as key-value pairs (first
* column is the key, second column is the value).
Expand Down Expand Up @@ -226,10 +218,6 @@ public function fetchPairs($offset_index = 0, $value_index = 1, callable $callab
/**
* Fetch the next row from a result set
*
* DEPRECATION WARNING! This method will be removed in the next major point release
*
* @deprecated deprecated since version 8.2
*
* The rows are presented as associated arrays
* The callable function will be applied to each row
*
Expand Down Expand Up @@ -329,19 +317,23 @@ protected function isValidKey($value)
protected function getRow($offset)
{
$fileObj = $this->getIterator();
$fileObj->setFlags(SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY);
$iterator = new LimitIterator($fileObj, $offset, 1);
$iterator->rewind();
$line = $iterator->current();

if (empty($line)) {
$row = $iterator->current();
if (empty($row)) {
throw new InvalidArgumentException('the specified row does not exist or is empty');
}

if (0 === $offset && $this->isBomStrippable()) {
$line = mb_substr($line, mb_strlen($this->getInputBOM()));
if (0 !== $offset || !$this->isBomStrippable()) {
return $row;
}

$bom_length = mb_strlen($this->getInputBOM());
$row[0] = mb_substr($row[0], $bom_length);
if ($this->enclosure == mb_substr($row[0], 0, 1) && $this->enclosure == mb_substr($row[0], -1, 1)) {
$row[0] = mb_substr($row[0], 1, -1);
}

return str_getcsv($line, $this->delimiter, $this->enclosure, $this->escape);
return $row;
}
}

0 comments on commit 8992405

Please sign in to comment.