Added IOFactory

This commit is contained in:
Jeroen De Meerleer 2019-05-27 13:01:37 +02:00
parent 190767d3af
commit 5d5d0b3cb7

34
src/IOFactory.php Normal file
View File

@ -0,0 +1,34 @@
<?php
namespace JeroenED\Libpairtwo;
use JeroenED\LibPairtwo\Exceptions\LibpairtwoException;
use JeroenED\Libpairtwo\Interfaces\ReaderInterface;
abstract class IOFactory
{
private static $readers = [
'Pairtwo-6' => Readers\Pairtwo6::class
];
/**
* 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;
}
}