Skip to content

Commit

Permalink
Added check to see if paths exist before parsing, added property and …
Browse files Browse the repository at this point in the history
…parameter maps, changed method name to invertLightness
  • Loading branch information
mattsparks committed Jul 7, 2017
1 parent 7b24cd3 commit 055b8d0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
40 changes: 39 additions & 1 deletion src/Builders/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ abstract class Builder implements BuilderInterface
* @var string
*/
protected $baseUri;
/**
* @var array
*/
protected $parameterMap = [];
/**
* @var array
*/
protected $propertyMap = [];
/**
* @var StaticMap
*/
Expand Down Expand Up @@ -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;
}

/**
Expand Down
13 changes: 12 additions & 1 deletion src/Builders/GoogleStaticMapBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Components/Styleable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Styleable
/**
* @var string
*/
public $invert_lightness = null;
public $invertLightness = null;
/**
* @var string
*/
Expand Down Expand Up @@ -101,7 +101,7 @@ public function invert()
*/
public function invertLightness($invertLightness)
{
$this->invert_lightness = $invertLightness;
$this->invertLightness = $invertLightness;

return $this;
}
Expand Down

0 comments on commit 055b8d0

Please sign in to comment.