identifier = $identifier; $this->options = $options; $this->version = $version??"0.0.0.0"; [$this->packageName, $this->datasetName] = explode("#", $identifier, 2); } /** * * @return string */ public function getIdentifier(): string { return $this->identifier; } /** * * @return string */ public function getPackageName(): string { return $this->packageName; } /** * * @return string */ public function getDatasetName(): string { return $this->datasetName; } /** * * @return string */ public function getVersion(): string { return $this->version; } /** * * @return string|null */ public function getComment(): ?string { return array_key_exists('comment', $this->options) ? $this->options['comment'] : null; } /** * * @return string|null */ public function getLicense(): ?string { return array_key_exists('license', $this->options) ? $this->options['license'] : null; } /** * * @return Iterator */ public function open(): Iterator { $filename = $this->options['filename']; $reader = $this->determineReaderForFile($filename); $inst = new $reader($filename, $this->options); return $inst; } /** * * @param string $filename * @return string */ private function determineReaderForFile(string $filename): string { if ($reader = $this->options['reader']??null) { 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"); } } }