libpairtwo/src/IOFactory.php
Jeroen De Meerleer e979b7e556 MAJOR ENHANCEMENT: Generalisation
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
2019-05-27 13:15:49 +02:00

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;
}
}