2019-05-27 13:15:28 +02:00
|
|
|
<?php
|
2019-06-19 21:54:19 +02:00
|
|
|
/**
|
|
|
|
* Class IOFactory
|
|
|
|
*
|
|
|
|
* Class for creating readers for pairing files
|
|
|
|
*
|
|
|
|
* @author Jeroen De Meerleer <schaak@jeroened.be>
|
|
|
|
* @category Main
|
|
|
|
* @package Libpairtwo
|
|
|
|
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
|
|
|
|
*/
|
2019-05-27 13:15:28 +02:00
|
|
|
|
|
|
|
namespace JeroenED\Libpairtwo;
|
|
|
|
|
|
|
|
use JeroenED\LibPairtwo\Exceptions\LibpairtwoException;
|
|
|
|
use JeroenED\Libpairtwo\Interfaces\ReaderInterface;
|
2019-05-28 10:20:06 +02:00
|
|
|
use JeroenED\Libpairtwo\Readers\Pairtwo6;
|
2019-05-27 13:15:28 +02:00
|
|
|
|
2019-06-19 21:54:19 +02:00
|
|
|
/**
|
|
|
|
* Class IOFactory
|
|
|
|
*
|
|
|
|
* Class for creating readers for pairing files
|
|
|
|
*
|
|
|
|
* @author Jeroen De Meerleer <schaak@jeroened.be>
|
|
|
|
* @category Main
|
|
|
|
* @package Libpairtwo
|
|
|
|
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
|
|
|
|
*/
|
2019-05-27 13:15:28 +02:00
|
|
|
abstract class IOFactory
|
|
|
|
{
|
2019-06-19 21:54:19 +02:00
|
|
|
/**
|
|
|
|
* Compatible readers
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2019-05-27 13:15:28 +02:00
|
|
|
private static $readers = [
|
2019-09-25 18:46:33 +02:00
|
|
|
'Swar-4' => Readers\Swar4::class,
|
2019-05-28 10:20:06 +02:00
|
|
|
'Pairtwo-6' => Readers\Pairtwo6::class,
|
|
|
|
'Pairtwo-5' => Readers\Pairtwo6::class // File structure identical
|
2019-05-27 13:15:28 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a reader for $type
|
|
|
|
*
|
2019-09-25 18:46:33 +02:00
|
|
|
* Compatible types are Swar-4, Pairtwo-5, Pairtwo-6
|
2019-06-20 15:32:26 +02:00
|
|
|
*
|
2019-05-27 13:15:28 +02:00
|
|
|
* @param string $type
|
|
|
|
* @return ReaderInterface
|
2019-06-20 15:32:26 +02:00
|
|
|
* @throws LibpairtwoException
|
2019-05-27 13:15:28 +02:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|