libpairtwo/src/IOFactory.php
Jeroen De Meerleer 7442df191e ENHANCEMENT: Compatibility with Pairtwo-5
Filestructure of pairtwo-5 files are identical to pairtwo-6
2019-05-28 10:20:06 +02:00

37 lines
845 B
PHP

<?php
namespace JeroenED\Libpairtwo;
use JeroenED\LibPairtwo\Exceptions\LibpairtwoException;
use JeroenED\Libpairtwo\Interfaces\ReaderInterface;
use JeroenED\Libpairtwo\Readers\Pairtwo6;
abstract class IOFactory
{
private static $readers = [
'Pairtwo-6' => Readers\Pairtwo6::class,
'Pairtwo-5' => Readers\Pairtwo6::class // File structure identical
];
/**
* Creates a reader for $type
*
* @param string $type
* @return ReaderInterface
*/
public static function createReader(string $type): ReaderInterface
{
if (!isset(self::$readers[$type])) {
throw new LibpairtwoException("Cannot read type $type");
}
// create reader class
$readerClass = self::$readers[$type];
$reader = new $readerClass;
return $reader;
}
}