Skip to content

Commit 54a8b91

Browse files
authored
Merge pull request #9 from davetha/master
Add support for curl options and fail curl on error in the TileLayer.
2 parents 5808877 + e037af6 commit 54a8b91

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
],
2424
"require": {
2525
"php": ">=7.0",
26-
"dantsu/php-image-editor": "^1.2"
26+
"dantsu/php-image-editor": "^1.3"
2727
},
2828
"autoload": {
2929
"psr-4": {

src/TileLayer.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,31 @@ public static function defaultTileLayer(): TileLayer
4444
*/
4545
protected $opacity = 1;
4646

47+
/**
48+
* @array $curlOptions Array of curl options
49+
*/
50+
protected $curlOptions = [];
51+
52+
/**
53+
* @bool $failCurlOnError If true, curl will throw an exception on error.
54+
*/
55+
protected $failCurlOnError = false;
56+
4757
/**
4858
* TileLayer constructor
4959
* @param string $url tile server url with placeholders (`x`, `y`, `z`, `r`, `s`)
5060
* @param string $attributionText tile server attribution text
5161
* @param string $subdomains tile server subdomains
62+
* @param array $curlOptions Array of curl options
63+
* @param bool $failCurlOnError If true, curl will throw an exception on error.
5264
*/
53-
public function __construct(string $url, string $attributionText, string $subdomains = 'abc')
65+
public function __construct(string $url, string $attributionText, string $subdomains = 'abc', array $curlOptions = [], bool $failCurlOnError = false)
5466
{
5567
$this->url = $url;
5668
$this->attributionText = $attributionText;
5769
$this->subdomains = \str_split($subdomains);
70+
$this->curlOptions = $curlOptions;
71+
$this->failCurlOnError = $failCurlOnError;
5872
}
5973

6074
/**
@@ -115,7 +129,7 @@ public function getTile(float $x, float $y, int $z): Image
115129
return Image::newCanvas(256, 256);
116130
}
117131

118-
$tile = Image::fromCurl($this->getTileUrl($x, $y, $z));
132+
$tile = Image::fromCurl($this->getTileUrl($x, $y, $z),$this->curlOptions, $this->failCurlOnError);
119133

120134
if($this->opacity > 0 && $this->opacity < 1) {
121135
$tile->setOpacity($this->opacity);

0 commit comments

Comments
 (0)