mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-10-31 20:56:08 +01:00
Added IOFactory
This commit is contained in:
parent
190767d3af
commit
5d5d0b3cb7
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