Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding option to specify extension along with file path. Adding unit …

…test for this permatation
  • Loading branch information...
commit 812600ad6f1f846d0e657d322468097494c37048 1 parent 325e865
@IamSmith authored
View
14 PhpReader.php
@@ -14,16 +14,24 @@ class PhpReader {
const OPTION_IGNORE_HEADER_ROW = 1;
- static function getReader($pathToFile) {
+ static function getReader($pathToFile, $extensionOverride = null) {
$options = func_get_args();
+ if (is_numeric($extensionOverride)) {
+ $extensionOverride = null;
+ }
+
if (!file_exists($pathToFile)) {
throw new FileDoesntExistException("'$pathToFile' doesn't exist");
}
- $extension = PhpReader::determineFileType($pathToFile);
- $className = ucfirst($extension);
+ if ($extensionOverride == null) {
+ $extension = PhpReader::determineFileType($pathToFile);
+ } else {
+ $extension = strtolower($extensionOverride);
+ }
+ $className = ucfirst($extension);
return ExtensionFactory::$className($pathToFile, $options);
}
View
3  Test/Files/testFileNoExtension
@@ -0,0 +1,3 @@
+"Title","FirstName","LastName","EmailAddress","Date","DateOfBirth"
+"","Karoly","Sefel","xxxx@gmail.com","2012-03-30 22:52:34.185199","1985-02-13 00:00:00"
+"","Julian","Webb","xxxx@msn.com","2012-03-30 22:52:34.253219","1970-01-01 00:00:00"
View
7 Test/PhpReaderTest.php
@@ -124,4 +124,11 @@ public function testLargeXlsxFile() {
$this->assertLessThan(10, $timeTaken);
}
+ public function testExtensionOverrideFile() {
+ $reader = PhpReader::getReader("Test/Files/testFileNoExtension", "csv");
+ foreach ($reader as $rowNumber => $rowData) {
+
+ }
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.