Skip to content

Commit ebcea99

Browse files
MrGabriCavigabricavisyntyppo
authored
Resolve issue about hardcoded endpoint (#3)
* Resolve issue about hardcoded endpoint * Formatting + exception for short URLs Co-authored-by: Gabriele Cavigiolo <[email protected]> Co-authored-by: Ian Webster <[email protected]>
1 parent 0c303f4 commit ebcea99

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

QuickChart.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ function getUrl() {
7878
}
7979

8080
function getShortUrl() {
81-
$ch = curl_init('https://quickchart.io/chart/create');
81+
if ($this->host != 'quickchart.io') {
82+
throw new Exception('Short URLs must use quickchart.io host');
83+
}
84+
$ch = curl_init($this->getRootEndpoint() . '/chart/create');
8285
$postData = array(
8386
'backgroundColor' => $this->backgroundColor,
8487
'width' => $this->width,
@@ -105,7 +108,7 @@ function getShortUrl() {
105108
}
106109

107110
function toBinary() {
108-
$ch = curl_init('https://quickchart.io/chart');
111+
$ch = curl_init($this->getRootEndpoint() . '/chart');
109112
$postData = array(
110113
'backgroundColor' => $this->backgroundColor,
111114
'width' => $this->width,
@@ -128,6 +131,10 @@ function toFile($path) {
128131
$data = $this->toBinary();
129132
file_put_contents($path, $data);
130133
}
134+
135+
protected function getRootEndpoint() {
136+
return $this->protocol . '://' . $this->host . ':' . $this->port;
137+
}
131138
}
132139

133-
?>
140+

0 commit comments

Comments
 (0)