libpairtwo/src/IOFactory.php

61 lines
1.4 KiB
PHP
Raw Normal View History

2019-05-27 13:01:37 +02:00
<?php
/**
* 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:01:37 +02:00
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
/**
* 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:01:37 +02:00
abstract class IOFactory
{
/**
* Compatible readers
*
* @var array
*/
2019-05-27 13:01:37 +02:00
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;
}
}