27
27
*/
28
28
class Services_OpenStreetMap_Changeset extends Services_OpenStreetMap_Object
29
29
{
30
+ /**
31
+ * Array of tags in key/value format
32
+ *
33
+ * @var array
34
+ */
35
+ protected $ tags = [];
36
+
30
37
/**
31
38
* What type object this is.
32
39
*
@@ -125,6 +132,52 @@ public function __construct($settings = [])
125
132
}
126
133
}
127
134
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
+
128
181
/**
129
182
* Begin changeset transaction.
130
183
*
@@ -147,10 +200,14 @@ public function begin(string $message): void
147
200
$ userAgent = $ configObj ->getValue ('User-Agent ' );
148
201
$ doc = "<?xml version='1.0' encoding= \"UTF-8 \"?> \n" .
149
202
'<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
+ }
154
211
$ doc .= '</changeset></osm> ' ;
155
212
$ url = $ configObj ->getValue ('server ' )
156
213
. 'api/ '
@@ -750,20 +807,6 @@ public function getUpdateMap(): array
750
807
return $ this ->updateMap ;
751
808
}
752
809
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
-
767
810
/**
768
811
* Validate credentials for using the API backend.
769
812
*
0 commit comments