mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-24 23:37:41 +01:00
Added IOFactory
This commit is contained in:
parent
8fee2c6746
commit
6ac07927af
34
src/IOFactory.php
Normal file
34
src/IOFactory.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user