From 7442df191e2ca7aa88cccf43bf9503a3b204c604 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Tue, 28 May 2019 10:20:06 +0200 Subject: [PATCH] ENHANCEMENT: Compatibility with Pairtwo-5 Filestructure of pairtwo-5 files are identical to pairtwo-6 --- src/IOFactory.php | 4 +++- src/Readers/Pairtwo6.php | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/IOFactory.php b/src/IOFactory.php index d5f7526..9b55d9f 100644 --- a/src/IOFactory.php +++ b/src/IOFactory.php @@ -5,11 +5,13 @@ namespace JeroenED\Libpairtwo; use JeroenED\LibPairtwo\Exceptions\LibpairtwoException; use JeroenED\Libpairtwo\Interfaces\ReaderInterface; +use JeroenED\Libpairtwo\Readers\Pairtwo6; abstract class IOFactory { private static $readers = [ - 'Pairtwo-6' => Readers\Pairtwo6::class + 'Pairtwo-6' => Readers\Pairtwo6::class, + 'Pairtwo-5' => Readers\Pairtwo6::class // File structure identical ]; diff --git a/src/Readers/Pairtwo6.php b/src/Readers/Pairtwo6.php index 6117f36..5d19746 100644 --- a/src/Readers/Pairtwo6.php +++ b/src/Readers/Pairtwo6.php @@ -51,6 +51,7 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface private const PT_MONTHFACTOR = 16; private const PT_YEARFACTOR = 512; private const PT_PASTOFFSET = 117; + private const CompatibleVersions = ['6.', '5.']; /** * Reads out $swsfile and returns a Pairtwo6 class object @@ -71,8 +72,8 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface $this->setRelease($this->readData('String', substr($swscontents, $offset, $length))); $offset += $length; - if (substr($this->getRelease(), 0, 2) !== "6.") { - throw new IncompatibleReaderException("This file was not created with Pairtwo 6 or higher"); + if (array_search(substr($this->getRelease(), 0, 2), self::CompatibleVersions) === false) { + throw new IncompatibleReaderException("This file was not created with Pairtwo 5 or higher"); } $this->setTournament(new Tournament());