Initial unit tests, code cleanup
This commit is contained in:
@ -22,16 +22,46 @@ class DatasetManager
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the available datasets
|
||||
*
|
||||
* @return Array<Dataset> The available datasets
|
||||
*/
|
||||
public function getAvailableDatasets(): array
|
||||
{
|
||||
return self::$datasets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly return a reader for a specific dataset.
|
||||
*
|
||||
* @param string $identifier The dataset identifier
|
||||
* @return ReaderInterface A reader for the data
|
||||
* @throws InvalidDatasetException if the dataset can not be opened
|
||||
* @throws UnknownDatasetException if the dataset does not exist
|
||||
*/
|
||||
public function openDataset(string $identifier): ReaderInterface
|
||||
{
|
||||
return $this->getDataset($identifier)->open();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a Dataset object containing metadata and methods to retrieve
|
||||
* a reader for the data in the set.
|
||||
*
|
||||
* @param string $identifier The dataset identifier
|
||||
* @throws UnknownDatasetException if the dataset does not exist
|
||||
*/
|
||||
public function getDataset(string $identifier): Dataset
|
||||
{
|
||||
if (!array_key_exists($identifier, self::$datasets)) {
|
||||
throw UnknownDatasetException::DatasetNotFound();
|
||||
}
|
||||
|
||||
return self::$datasets[$identifier];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the vendor directory and try to locate all bundled datasets
|
||||
*
|
||||
@ -67,8 +97,8 @@ class DatasetManager
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param string The package name (org/package)
|
||||
* @param string The full path to the package (..../vendor/org/package)
|
||||
* @param string $package The package name (org/package)
|
||||
* @param string $path The full path to the package (..../vendor/org/package)
|
||||
*/
|
||||
private function scanPackageDatasets(string $package, string $path)
|
||||
{
|
||||
@ -84,10 +114,15 @@ class DatasetManager
|
||||
}
|
||||
|
||||
$this->loadDatasets($json['datasets'], null, $package, $path);
|
||||
//printf("found %d sets in %s\n", count($json['datasets']), $package);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
private function loadDatasets(array $datasets, ?string $prefix, string $package, string $path)
|
||||
{
|
||||
foreach ($datasets as $name=>$options) {
|
||||
@ -103,14 +138,21 @@ class DatasetManager
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
private function determineVendorPath(): ?string
|
||||
{
|
||||
if (defined("COMPOSER_VENDOR_PATH")) {
|
||||
return COMPOSER_VENDOR_PATH;
|
||||
$d = defined("NOCCYLABS_DATASET_TEST") ? (dirname(__DIR__)."/tests") : __DIR__;
|
||||
while ($d != dirname($d)) {
|
||||
if (file_exists($d."/autoload.php")) break;
|
||||
$d = dirname($d);
|
||||
}
|
||||
if (file_exists(__DIR__."/../../../autoload.php")) {
|
||||
// we are installed as a composer package
|
||||
return dirname(__DIR__, 3);
|
||||
|
||||
if (file_exists($d."/autoload.php")) {
|
||||
return $d;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -127,17 +169,4 @@ class DatasetManager
|
||||
self::$datasets[$id] = $dataset;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @throws InvalidDatasetException if the dataset can not be opened
|
||||
* @throws UnknownDatasetExcception if the dataset does not exist
|
||||
*/
|
||||
public function getDataset(string $identifier): Dataset
|
||||
{
|
||||
|
||||
return self::$datasets[$identifier];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user