From 3520ec946b9a0c6154798fd3e4fe4eca7bae19e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=CC=81s=CC=8C=20Holeczy?= Date: Mon, 21 Mar 2022 18:40:43 +0100 Subject: [PATCH] Add support for selecting radiation database --- README.md | 4 +++- src/Adapter/UrlBuilder.php | 10 ++++++++++ src/Enum/Database.php | 15 +++++++++++++++ src/Model/Request.php | 15 ++++++++++++++- src/PVGIS.php | 5 +++-- 5 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 src/Enum/Database.php diff --git a/README.md b/README.md index d42ebc4..e2f081c 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ composer require holicz/pvgis use holicz\PVGIS\PVGIS; use holicz\PVGIS\Adapter\PvgisAdapter; +use holicz\PVGIS\Enum\Database; $latitude = '50.0898689'; $longitude = '14.4000936'; @@ -23,7 +24,8 @@ $electricityProduction = $pvgis->getElectricityProduction( $latitude, $longitude, 35, // Solar panels angle (not required) - CardinalDirection::SOUTH // Solar panels azimuth (not required) + CardinalDirection::SOUTH, // Solar panels azimuth (not required) + Database::SARAH // Name of the radiation database (not required) ); // Yearly sum of production diff --git a/src/Adapter/UrlBuilder.php b/src/Adapter/UrlBuilder.php index 2227a67..fd81e69 100644 --- a/src/Adapter/UrlBuilder.php +++ b/src/Adapter/UrlBuilder.php @@ -25,6 +25,7 @@ public function build(): string $this->buildGPSCoordinates(); $this->buildAngle(); $this->buildAzimuth(); + $this->buildDatabase(); return $this->url; } @@ -51,4 +52,13 @@ private function buildAzimuth(): void $this->url .= sprintf('&aspect=%d', $this->request->getAzimuth()); } + + private function buildDatabase(): void + { + if ($this->request->getDatabase() === null) { + return; + } + + $this->url .= sprintf('&raddatabase=%s', $this->request->getDatabase()); + } } diff --git a/src/Enum/Database.php b/src/Enum/Database.php new file mode 100644 index 0000000..f2f6768 --- /dev/null +++ b/src/Enum/Database.php @@ -0,0 +1,15 @@ +latitude = $latitude; $this->longitude = $longitude; $this->angle = $angle; $this->azimuth = $azimuth; + $this->database = $database; } public function getLatitude(): string @@ -55,4 +58,14 @@ public function getAzimuth(): ?int { return $this->azimuth; } + + public function setDatabase(?string $database): void + { + $this->database = $database; + } + + public function getDatabase(): ?string + { + return $this->database; + } } diff --git a/src/PVGIS.php b/src/PVGIS.php index ad33281..c3d5ce1 100644 --- a/src/PVGIS.php +++ b/src/PVGIS.php @@ -25,9 +25,10 @@ public function getElectricityProduction( string $latitude, string $longitude, ?int $angle = null, - ?int $azimuth = null + ?int $azimuth = null, + ?string $database = null ): ElectricityProduction { - $request = new Request($latitude, $longitude, $angle, $azimuth); + $request = new Request($latitude, $longitude, $angle, $azimuth, $database); return $this->pvgisAdapter->getPvgisData($request); }