Added IOFactory

This commit is contained in:
Jeroen De Meerleer 2019-05-27 13:01:37 +02:00
parent 8fee2c6746
commit 6ac07927af
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
1 changed files with 34 additions and 0 deletions

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;
}
}