Skip to content

Commit

Permalink
feat: add method has to DataRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdarin committed Jun 18, 2024
1 parent 5c36e52 commit 4595d9e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/DataRepository/DataRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

interface DataRepositoryInterface
{
public function has(?string $indexName = null): bool;

/**
* @return list<TimezoneData>
*/
Expand Down
17 changes: 12 additions & 5 deletions src/DataRepository/JsonFileDataRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public function __construct(
private GeoJsonToTimezoneDataConverter $geoJsonConverter = new GeoJsonToTimezoneDataConverter(),
) {}

public function has(?string $indexName = null): bool
{
return file_exists($this->getIndexFilePath($indexName));
}

/**
* @return list<TimezoneData>
*/
Expand Down Expand Up @@ -51,11 +56,6 @@ public function write(array $data, ?string $indexName = null): void
}
}

private function getIndexFilePath(?string $indexName): string
{
return $indexName === null ? $this->baseGeoDataPath : $this->dataDirectory . $indexName . '.json';
}

public function remove(?string $indexName = null): void
{
if ($indexName === null) {
Expand All @@ -64,4 +64,11 @@ public function remove(?string $indexName = null): void

@unlink($this->getIndexFilePath($indexName));
}

private function getIndexFilePath(?string $indexName): string
{
$indexPath = rtrim($this->dataDirectory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'timezones' . DIRECTORY_SEPARATOR . $indexName . '.json';

return $indexName === null ? $this->baseGeoDataPath : $indexPath;
}
}
2 changes: 1 addition & 1 deletion src/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
readonly class Indexer
{
public const DEFAULT_INDEX_LEVEL = 6;

public function __construct(
private DataRepositoryInterface $dataRepository,
private QuadrantBuilder $quadrantBuilder = new QuadrantBuilder(),
Expand Down

0 comments on commit 4595d9e

Please sign in to comment.