libpairtwo/src/IOFactory.php

37 lines
845 B
PHP
Raw Normal View History

2019-05-27 13:01:37 +02:00
<?php
namespace JeroenED\Libpairtwo;
use JeroenED\LibPairtwo\Exceptions\LibpairtwoException;
use JeroenED\Libpairtwo\Interfaces\ReaderInterface;
2019-05-28 10:16:34 +02:00
use JeroenED\Libpairtwo\Readers\Pairtwo6;
2019-05-27 13:01:37 +02:00
abstract class IOFactory
{
private static $readers = [
2019-05-28 10:16:34 +02:00
'Pairtwo-6' => Readers\Pairtwo6::class,
'Pairtwo-5' => Readers\Pairtwo6::class // File structure identical
2019-05-27 13:01:37 +02:00
];
/**
* 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;
}
}