mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-06-26 12:23:12 +02:00
This is a first step in generalisation of the project. Please review https://github.com/JeroenED/libpairtwo/wiki/Converting-your-code-to-the-generalized-format for more info on your code changes
35 lines
727 B
PHP
35 lines
727 B
PHP
<?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;
|
|
}
|
|
}
|