From 055b8d058bb8647a238462f116fee181445117e4 Mon Sep 17 00:00:00 2001 From: themattsparks Date: Thu, 6 Jul 2017 21:47:35 -0400 Subject: [PATCH] Added check to see if paths exist before parsing, added property and parameter maps, changed method name to invertLightness --- src/Builders/Builder.php | 40 ++++++++++++++++++++++++- src/Builders/GoogleStaticMapBuilder.php | 13 +++++++- src/Components/Styleable.php | 4 +-- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/Builders/Builder.php b/src/Builders/Builder.php index 924f54b..2aa0624 100644 --- a/src/Builders/Builder.php +++ b/src/Builders/Builder.php @@ -10,6 +10,14 @@ abstract class Builder implements BuilderInterface * @var string */ protected $baseUri; + /** + * @var array + */ + protected $parameterMap = []; + /** + * @var array + */ + protected $propertyMap = []; /** * @var StaticMap */ @@ -38,7 +46,37 @@ public function __construct(StaticMap $staticMap) */ public function addParameter($parameter, $value) { - $this->uri .= $parameter . '=' . urlencode($value) . '&'; + $this->uri .= $this->mapParameter($parameter) . '=' . urlencode($value) . '&'; + } + + /** + * Map Parameter + * + * @param $parameter + * @return mixed + */ + public function mapParameter($parameter) + { + if (array_key_exists($parameter, $this->parameterMap)) { + return $this->parameterMap[$parameter]; + } + + return $parameter; + } + + /** + * Map Property + * + * @param $property + * @return mixed + */ + public function mapProperty($property) + { + if (array_key_exists($property, $this->propertyMap)) { + return $this->propertyMap[$property]; + } + + return $property; } /** diff --git a/src/Builders/GoogleStaticMapBuilder.php b/src/Builders/GoogleStaticMapBuilder.php index 0343eeb..0304869 100644 --- a/src/Builders/GoogleStaticMapBuilder.php +++ b/src/Builders/GoogleStaticMapBuilder.php @@ -14,6 +14,13 @@ class GoogleStaticMapBuilder extends Builder implements BuilderInterface const STYLE_FORMAT = 'feature:%s|%s'; const MULTI_STYLE_FORMAT = 'feature:%s|%s|%s'; + /** + * @var array + */ + protected $propertyMap = [ + 'invertLightness' => 'invert_lightness' + ]; + /** * @var string */ @@ -50,6 +57,10 @@ public function addKey() */ public function addPath() { + if(!$this->staticMap->path) { + return; + } + $properties = get_object_vars($this->staticMap->path); $points = $this->staticMap->path->points; @@ -151,7 +162,7 @@ public function format(array $params, $format) foreach ($params as $property => $value) { if ($value) { - $temp .= sprintf($format, $property, $value); + $temp .= sprintf($format, $this->mapProperty($property), $value); } } diff --git a/src/Components/Styleable.php b/src/Components/Styleable.php index 803b6e9..528e1f8 100644 --- a/src/Components/Styleable.php +++ b/src/Components/Styleable.php @@ -20,7 +20,7 @@ class Styleable /** * @var string */ - public $invert_lightness = null; + public $invertLightness = null; /** * @var string */ @@ -101,7 +101,7 @@ public function invert() */ public function invertLightness($invertLightness) { - $this->invert_lightness = $invertLightness; + $this->invertLightness = $invertLightness; return $this; }