createReaderForFile doesn't create reader (bug?)

Topics: Developer Forum
Mar 23, 2010 at 11:38 PM

I looked through the discussions to see if some reported this already, since it seems that someone would have run into this already. This is what I have from IOFactory.php:

switch (strtolower($pathinfo['extension'])) {

 

case 'xlsx': $reader = self::createReader('Excel2007'); break;

case 'xls': $reader = self::createReader('Excel5'); break;

case 'ods': $reader = self::createReader('OOCalc'); break;

case 'slk': $reader = self::createReader('SYLK'); break;

case 'xml': $reader = self::createReader('Excel2003XML'); break;

case 'csv': break;

default: break; }

if ($reader->canRead($pFilename)) { return $reader; }

 

switch (strtolower($pathinfo['extension'])) {
case 'xlsx':
$reader = self::createReader('Excel2007');
break;
case 'xls':
$reader = self::createReader('Excel5');
break;
case 'ods':
$reader = self::createReader('OOCalc');
break;
case 'slk':
$reader = self::createReader('SYLK');
break;
case 'xml':
$reader = self::createReader('Excel2003XML');
break;
case 'csv':
// Do nothing
// We must not try to use CSV reader since it loads
// all files including Excel files etc.
break;
default:
break;
}
// Let's see if we are lucky
if ($reader->canRead($pFilename)) {
return $reader;
}

The problem is that if the extension is either .csv or isn't any of the above that create a reader then the reader won't be the appropriate object. Am I missing something here? I'm surprised that no one has run into this already. I don't have a good grasp of the code but it seems that the check should only occur if reader is actually an object. Inserting a $reader = false at the top of the function and then doing:

if( $reader && $reader->canRead)  should fix the problem...

 

Coordinator
Mar 24, 2010 at 11:35 PM

Thanks for pointing this out.

This fix has actually been made in the latest SVN code