diff options
author | ignace nyamagana butera <nyamsprod@gmail.com> | 2014-02-22 11:36:00 +0100 |
---|---|---|
committer | ignace nyamagana butera <nyamsprod@gmail.com> | 2014-02-22 11:36:00 +0100 |
commit | 963d063b2a8818cabbfcb4e6d3200cc8d1a70647 (patch) | |
tree | 40a871d7d37685c09cf31593bf31aafc6b0b2ecb | |
parent | f4c2216536862a9d22fe1b6a457064a4e6ecd505 (diff) | |
parent | 5af539197a2d8bb7840bb59fa6f3054fac9ea8b9 (diff) | |
download | csv-963d063b2a8818cabbfcb4e6d3200cc8d1a70647.zip csv-963d063b2a8818cabbfcb4e6d3200cc8d1a70647.tar.gz csv-963d063b2a8818cabbfcb4e6d3200cc8d1a70647.tar.bz2 |
Merge pull request #15 from nyamsprod/open_mode_fix
remove validation resolves #14
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | src/AbstractCsv.php | 14 | ||||
-rw-r--r-- | src/Reader.php | 5 | ||||
-rw-r--r-- | src/Writer.php | 5 | ||||
-rw-r--r-- | test/WriterTest.php | 8 | ||||
-rw-r--r-- | test/foo.csv | 1 |
6 files changed, 1 insertions, 34 deletions
@@ -94,7 +94,7 @@ $writer = Writer::createFromString('john,doe,john.doe@example.com'); Both classes constructors take one optional parameter `$open_mode` representing the file open mode used by the PHP [fopen](http://php.net/manual/en/function.fopen.php) function. * The `Bakame\Csv\Writer` `$open_mode` default value is `w`. -* The `Bakame\Csv\Reader` `$open_mode` default value is `r`, and **no other value is possible**. So you don't need to explicitly set it. +* The `Bakame\Csv\Reader` `$open_mode` default value is `r`. The static method `createFromString` is to be use if your data is a string. This method takes no optional `$open_mode` parameter. diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php index 614f5c5..6c1b258 100644 --- a/src/AbstractCsv.php +++ b/src/AbstractCsv.php @@ -97,13 +97,6 @@ class AbstractCsv implements JsonSerializable, IteratorAggregate protected $encoding = 'UTF-8'; /** - * Open mode available flag - * - * @var array - */ - protected $available_open_mode = ['r', 'r+', 'w', 'w+', 'x', 'x+', 'a', 'a+', 'c', 'c+']; - - /** * The constructor * * @param mixed $path an SplFileInfo object or the path to a file @@ -177,13 +170,6 @@ class AbstractCsv implements JsonSerializable, IteratorAggregate return $path; } $open_mode = strtolower($open_mode); - if (! in_array($open_mode, $this->available_open_mode)) { - throw new InvalidArgumentException( - 'Invalid `$open_mode` value. Available values are : "' - .implode('", "', $this->available_open_mode).'"' - ); - } - if ($path instanceof SplFileInfo) { return $path->openFile($open_mode); } elseif (is_string($path)) { diff --git a/src/Reader.php b/src/Reader.php index f837598..8d82c03 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -52,11 +52,6 @@ class Reader extends AbstractCsv use IteratorQuery; /** - * {@inheritdoc} - */ - protected $available_open_mode = ['r']; - - /** * Intelligent Array Combine * * @param array $keys diff --git a/src/Writer.php b/src/Writer.php index d3e9ed0..c047953 100644 --- a/src/Writer.php +++ b/src/Writer.php @@ -47,11 +47,6 @@ class Writer extends AbstractCsv /** * {@inheritdoc} */ - protected $available_open_mode = ['r+', 'w', 'w+', 'x', 'x+', 'a', 'a+', 'c', 'c+']; - - /** - * {@inheritdoc} - */ public function __construct($path, $open_mode = 'w') { parent::__construct($path, $open_mode); diff --git a/test/WriterTest.php b/test/WriterTest.php index ccd45cd..3b4a39d 100644 --- a/test/WriterTest.php +++ b/test/WriterTest.php @@ -22,14 +22,6 @@ class WriterTest extends PHPUnit_Framework_TestCase $this->csv = new Writer(new SplTempFileObject); } - /** - * @expectedException InvalidArgumentException - */ - public function testConstructorWithWrongOpenMode() - { - new Writer('foo.csv', 'r'); - } - public function testInsert() { $expected = [ diff --git a/test/foo.csv b/test/foo.csv index 4307de4..0c85eae 100644 --- a/test/foo.csv +++ b/test/foo.csv @@ -1,2 +1 @@ -1,2,3 "john","doe","john.doe@example.com"
\ No newline at end of file |