From 4b9e6f4c29b6c4840ebaf9455d59b874fb91cca2 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Mon, 31 Oct 2022 12:51:24 +0100 Subject: [PATCH] Restored some PHP 7.4 support --- src/Dataset.php | 12 +++++++++++- src/FilteringReaderIterator.php | 6 +++++- src/Readers/JsonReader.php | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Dataset.php b/src/Dataset.php index d32c3ef..93f7bd5 100644 --- a/src/Dataset.php +++ b/src/Dataset.php @@ -116,11 +116,21 @@ class Dataset return $reader; } $ext = pathinfo($filename, PATHINFO_EXTENSION); + + /* return match ($ext) { 'json' => JsonReader::class, 'csv' => CsvReader::class, default => throw new \RuntimeException("Unable to determine reader for dataset file") }; + */ + + // PHP7.4 compat: use switch instead of match + switch ($ext) { + case 'json': return JsonReader::class; + case 'csv': return CsvReader::class; + default: throw new \RuntimeException("Unable to determine reader for dataset file"); + } } -} \ No newline at end of file +} diff --git a/src/FilteringReaderIterator.php b/src/FilteringReaderIterator.php index 0a89de9..fd81a1f 100644 --- a/src/FilteringReaderIterator.php +++ b/src/FilteringReaderIterator.php @@ -10,7 +10,11 @@ class FilteringReaderIterator implements Iterator private $condition; - public function __construct(Iterator $reader, array|callable $condition) + /** + * + * @note Removed support for callable in cond (php7.4 compat) + */ + public function __construct(Iterator $reader, array $condition) { $this->reader = $reader; $this->condition = $condition; diff --git a/src/Readers/JsonReader.php b/src/Readers/JsonReader.php index 176b830..8aebdca 100644 --- a/src/Readers/JsonReader.php +++ b/src/Readers/JsonReader.php @@ -38,7 +38,7 @@ class JsonReader implements ReaderInterface $flags = ($this->options['bigintAsString']??false)?JSON_BIGINT_AS_STRING:0; $file = $this->files[$this->currentFile]; - $json = @json_decode(@file_get_contents($file), true, flags:$flags); + $json = @json_decode(@file_get_contents($file), true, 512, $flags); $this->loadData($json); $this->loadedFile = $this->currentFile;