-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
160 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace holicz\PVGIS\Adapter; | ||
|
||
use holicz\PVGIS\Model\Request; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class UrlBuilder | ||
{ | ||
private Request $request; | ||
private string $url; | ||
|
||
public function __construct(Request $request) | ||
{ | ||
$this->request = $request; | ||
$this->url = 'https://re.jrc.ec.europa.eu/api/pvcalc?peakpower=1&pvtechchoice=crystSi&mountingplace=building&loss=10&outputformat=json'; | ||
} | ||
|
||
public function build(): string | ||
{ | ||
$this->buildGPSCoordinates(); | ||
$this->buildAngle(); | ||
$this->buildAzimuth(); | ||
|
||
return $this->url; | ||
} | ||
|
||
private function buildGPSCoordinates(): void | ||
{ | ||
$this->url .= sprintf('&lat=%s&lon=%s', $this->request->getLatitude(), $this->request->getLongitude()); | ||
} | ||
|
||
private function buildAngle(): void | ||
{ | ||
if ($this->request->getAngle() === null) { | ||
return; | ||
} | ||
|
||
$this->url .= sprintf('&angle=%d', $this->request->getAngle()); | ||
} | ||
|
||
private function buildAzimuth(): void | ||
{ | ||
if ($this->request->getAzimuth() === null) { | ||
return; | ||
} | ||
|
||
$this->url .= sprintf('&aspect=%d', $this->request->getAzimuth()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace holicz\PVGIS\Enum; | ||
|
||
final class CardinalDirection | ||
{ | ||
public const NORTH = 180; | ||
public const NORTHEAST = -135; | ||
public const EAST = -90; | ||
public const SOUTHEAST = -45; | ||
public const SOUTH = 0; | ||
public const SOUTHWEST = 45; | ||
public const WEST = 90; | ||
public const NORTHWEST = 135; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace holicz\PVGIS\Model; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class Request | ||
{ | ||
private string $latitude; | ||
private string $longitude; | ||
private ?int $angle; | ||
private ?int $azimuth; | ||
|
||
public function __construct( | ||
string $latitude, | ||
string $longitude, | ||
?int $angle = null, | ||
?int $azimuth = null | ||
) { | ||
$this->latitude = $latitude; | ||
$this->longitude = $longitude; | ||
$this->angle = $angle; | ||
$this->azimuth = $azimuth; | ||
} | ||
|
||
public function getLatitude(): string | ||
{ | ||
return $this->latitude; | ||
} | ||
|
||
public function getLongitude(): string | ||
{ | ||
return $this->longitude; | ||
} | ||
|
||
public function setAngle(?int $angle): void | ||
{ | ||
$this->angle = $angle; | ||
} | ||
|
||
public function getAngle(): ?int | ||
{ | ||
return $this->angle; | ||
} | ||
|
||
public function setAzimuth(?int $azimuth): void | ||
{ | ||
$this->azimuth = $azimuth; | ||
} | ||
|
||
public function getAzimuth(): ?int | ||
{ | ||
return $this->azimuth; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters