Skip to content

Commit

Permalink
Resolve issue about hardcoded endpoint (#3)
Browse files Browse the repository at this point in the history
* Resolve issue about hardcoded endpoint

* Formatting + exception for short URLs

Co-authored-by: Gabriele Cavigiolo <gabriele.cavigiolo@synesthesia.it>
Co-authored-by: Ian Webster <ianw_github@ianww.com>
  • Loading branch information
3 people authored Jun 3, 2021
1 parent 0c303f4 commit ebcea99
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions QuickChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ function getUrl() {
}

function getShortUrl() {
$ch = curl_init('https://quickchart.io/chart/create');
if ($this->host != 'quickchart.io') {
throw new Exception('Short URLs must use quickchart.io host');
}
$ch = curl_init($this->getRootEndpoint() . '/chart/create');
$postData = array(
'backgroundColor' => $this->backgroundColor,
'width' => $this->width,
Expand All @@ -105,7 +108,7 @@ function getShortUrl() {
}

function toBinary() {
$ch = curl_init('https://quickchart.io/chart');
$ch = curl_init($this->getRootEndpoint() . '/chart');
$postData = array(
'backgroundColor' => $this->backgroundColor,
'width' => $this->width,
Expand All @@ -128,6 +131,10 @@ function toFile($path) {
$data = $this->toBinary();
file_put_contents($path, $data);
}

protected function getRootEndpoint() {
return $this->protocol . '://' . $this->host . ':' . $this->port;
}
}

?>

0 comments on commit ebcea99

Please sign in to comment.