Skip to content

Commit aeab900

Browse files
authored
Merge pull request #214 from sascha-hendel/master
Update Changeset.php
2 parents 3c0e27a + 035f2b6 commit aeab900

File tree

1 file changed

+61
-18
lines changed

1 file changed

+61
-18
lines changed

Services/OpenStreetMap/Changeset.php

+61-18
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
*/
2828
class Services_OpenStreetMap_Changeset extends Services_OpenStreetMap_Object
2929
{
30+
/**
31+
* Array of tags in key/value format
32+
*
33+
* @var array
34+
*/
35+
protected $tags = [];
36+
3037
/**
3138
* What type object this is.
3239
*
@@ -125,6 +132,52 @@ public function __construct($settings = [])
125132
}
126133
}
127134

135+
/**
136+
* Set tag to [new] key/value pair.
137+
*
138+
* The object is returned, supporting Fluent coding style.
139+
*
140+
* <code>
141+
* $changeset->setTag('key', 'value')->setTag(...);
142+
* </code>
143+
*
144+
* @param mixed $key key
145+
* @param mixed $value value
146+
*
147+
* @return Services_OpenStreetMap_Changeset
148+
*/
149+
public function setTag($key, $value): Services_OpenStreetMap_Changeset
150+
{
151+
$this->tags[$key] = $value;
152+
return $this;
153+
}
154+
/**
155+
* Return the tags set for this changeset in question.
156+
*
157+
* @return array tags
158+
*/
159+
public function getTags(): array
160+
{
161+
return $this->tags;
162+
}
163+
164+
/**
165+
* Return value of specified tag as set against this changeset.
166+
* If tag isn't set, return null.
167+
*
168+
* @param string $key Key value, For example, 'created_by', 'automatic' etc
169+
*
170+
* @return string|null
171+
*/
172+
public function getTag(string $key): ?string
173+
{
174+
if (isset($this->tags[$key])) {
175+
return $this->tags[$key];
176+
} else {
177+
return null;
178+
}
179+
}
180+
128181
/**
129182
* Begin changeset transaction.
130183
*
@@ -147,10 +200,14 @@ public function begin(string $message): void
147200
$userAgent = $configObj->getValue('User-Agent');
148201
$doc = "<?xml version='1.0' encoding=\"UTF-8\"?>\n" .
149202
'<osm version="0.6" generator="' . $userAgent . '">'
150-
. "<changeset id='0' open='false'>"
151-
. '<tag k="comment" v="' . $message . '"/>'
152-
. '<tag k="created_by" v="' . $userAgent . '/0.1"/>';
153-
$doc .= $this->generateReviewRequestedTag();
203+
. "<changeset id='0' open='false'>";
204+
$this->setTag('comment' , $message);
205+
$this->setTag('created_by' , $userAgent . '/0.1');
206+
$this->setTag('review_requested' , ($this->reviewRequested ? 'yes' : 'no'));
207+
$tags = $this->getTags();
208+
foreach ($tags as $key => $value) {
209+
$doc .= '<tag k="' . $key . '" v="' . $value . '"/>';
210+
}
154211
$doc .= '</changeset></osm>';
155212
$url = $configObj->getValue('server')
156213
. 'api/'
@@ -750,20 +807,6 @@ public function getUpdateMap(): array
750807
return $this->updateMap;
751808
}
752809

753-
/**
754-
* Generate the changeset tag to indicate if a review is requested
755-
*
756-
* @return string
757-
*/
758-
private function generateReviewRequestedTag(): string
759-
{
760-
$tag = '<tag k="review_requested" v="no"/>';
761-
if ($this->reviewRequested) {
762-
$tag = '<tag k="review_requested" v="yes"/>';
763-
}
764-
return $tag;
765-
}
766-
767810
/**
768811
* Validate credentials for using the API backend.
769812
*

0 commit comments

Comments
 (0)