Skip to content

IOFactory::identify() returns wrong value when there's a custom reader registered #4357

Closed
@marrch-caat

Description

@marrch-caat

When I create a custom reader class, say EchXlsxReader, and register it with registerReader() method, identify method behaves incorrect, returning the class name instead of the type for which it was registered. According to official docs, https://phpspreadsheet.readthedocs.io/en/latest/topics/reading-files/, the following code should work:

/**  Identify the type of $inputFileName  **/for 
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($inputFileName);
/**  Create a new Reader of the type that has been identified  **/
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
/**  Load $inputFileName to a Spreadsheet Object  **/
$spreadsheet = $reader->load($inputFileName);

But that really doesn't work:

// I register a custom reader to use for XLSX files innstead of standard one.
IOFactory::registerReader(IOFactory::READER_XLSX, EchXlsxReader::class);
...
// The following code will work fine:
$objPHPExcel = IOFactory::load($inputFileName);

// But the code from the mentioned sample fails:
$inputFileType = IOFactory::identify($inputFileName); //Successfully creates the reader and returns "EchXlsxReader"
$objReader = IOFactory::createReader($inputFileType); //Throws error, "No reader found for type EchXlsxReader"

According to the docs the behavior is incorrect, it works for built-in readers just because their (non-qualified) names are equal to the names of the types they read.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions