Skip to content

Commit 29fc074

Browse files
committed
Rename 'node' to 'tag' in most cases, change some method names
1 parent 505d71a commit 29fc074

18 files changed

+165
-165
lines changed

src/PhpArrayToXml.php

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ class PhpArrayToXml
1515
protected $_encoding = 'UTF-8';
1616
protected $_default_root_name = 'root';
1717
protected $_custom_root_name = null;
18-
protected $_default_node_name = 'node';
19-
protected $_custom_node_name = null;
18+
protected $_default_tag_name = 'node';
19+
protected $_custom_tag_name = null;
2020
protected $_separator = '_';
21-
protected $_transform_key_names = null;
21+
protected $_transform_tags = null;
2222
protected $_format_output = false;
23-
protected $_numeric_node_suffix = null;
23+
protected $_numeric_tag_suffix = null;
2424

2525
/**
2626
* Set the version of the XML (Default = '1.0')
@@ -112,7 +112,7 @@ public function getFormatOutput()
112112
*/
113113
public function setCustomRootName($value)
114114
{
115-
if (!$this->isValidNodeName($value)) {
115+
if (!$this->isValidXmlTag($value)) {
116116
throw new \Exception('Not a valid root name: ' . $value);
117117
}
118118

@@ -142,45 +142,45 @@ public function getDefaultRootName()
142142
}
143143

144144
/**
145-
* Set the custom node name of the XML (only used for inner arrays)
145+
* Set the custom tag name of the XML (only used for inner arrays)
146146
*
147147
* @param $value
148148
* @return PhpArrayToXml
149149
* @throws \Exception
150150
*/
151-
public function setCustomNodeName($value)
151+
public function setCustomTagName($value)
152152
{
153-
if (!$this->isValidNodeName($value)) {
154-
throw new \Exception('Not a valid node name: ' . $value);
153+
if (!$this->isValidXmlTag($value)) {
154+
throw new \Exception('Not a valid tag name: ' . $value);
155155
}
156156

157-
$this->_custom_node_name = $value;
157+
$this->_custom_tag_name = $value;
158158

159159
return $this;
160160
}
161161

162162
/**
163-
* Get the custom node name of the XML (only used for inner arrays)
163+
* Get the custom tag name of the XML (only used for inner arrays)
164164
*
165165
* @return string
166166
*/
167-
public function getCustomNodeName()
167+
public function getCustomTagName()
168168
{
169-
return $this->_custom_node_name;
169+
return $this->_custom_tag_name;
170170
}
171171

172172
/**
173-
* Get the default node name of the XML (only used for inner arrays)
173+
* Get the default tag name of the XML (only used for inner arrays)
174174
*
175175
* @return string
176176
*/
177-
public function getDefaultNodeName()
177+
public function getDefaultTagName()
178178
{
179-
return $this->_default_node_name;
179+
return $this->_default_tag_name;
180180
}
181181

182182
/**
183-
* Set the value for the separator that will be used to replace special characters in node/tag names
183+
* Set the value for the separator that will be used to replace special characters in tag names
184184
*
185185
* @param $value
186186
* @return PhpArrayToXml
@@ -193,7 +193,7 @@ public function setSeparator($value)
193193
}
194194

195195
/**
196-
* Get the value for the separator that will be used to replace special characters in node/tag names
196+
* Get the value for the separator that will be used to replace special characters in tag names
197197
*
198198
* @return string
199199
*/
@@ -203,7 +203,7 @@ public function getSeparator()
203203
}
204204

205205
/**
206-
* Set the method for transforming keys
206+
* Set the transformation method for tag names
207207
* Possible values:
208208
* - null
209209
* - 'uppercase'
@@ -212,17 +212,17 @@ public function getSeparator()
212212
* @param $value
213213
* @return PhpArrayToXml
214214
*/
215-
public function setMethodTransformKeys($value = null)
215+
public function setTransformTags($value = null)
216216
{
217217
switch($value) {
218218
case self::LOWERCASE:
219219
case self::UPPERCASE: {
220-
$this->_transform_key_names = $value;
220+
$this->_transform_tags = $value;
221221
break;
222222
}
223223
default: {
224224
if($value === null) {
225-
$this->_transform_key_names = null;
225+
$this->_transform_tags = null;
226226
}
227227
}
228228
}
@@ -231,82 +231,82 @@ public function setMethodTransformKeys($value = null)
231231
}
232232

233233
/**
234-
* Get the method for transforming keys
234+
* Get the transformation method for tag names
235235
*
236236
* @return string
237237
*/
238-
public function getMethodTransformKeys()
238+
public function getTransformTags()
239239
{
240-
return $this->_transform_key_names;
240+
return $this->_transform_tags;
241241
}
242242

243243
/**
244-
* Set the numeric node suffix
244+
* Set the numeric tag suffix
245245
*
246246
* @param null $value
247247
* @return PhpArrayToXml
248248
*/
249-
public function setNumericNodeSuffix($value = null)
249+
public function setNumericTagSuffix($value = null)
250250
{
251-
$this->_numeric_node_suffix = $value;
251+
$this->_numeric_tag_suffix = $value;
252252

253253
if($value === true || $value === false) {
254-
$this->_numeric_node_suffix = '';
254+
$this->_numeric_tag_suffix = '';
255255
}
256256
return $this;
257257
}
258258

259259
/**
260-
* Get the numeric node suffix
260+
* Get the numeric tag suffix
261261
*
262262
* @return null
263263
*/
264-
public function getNumericNodeSuffix()
264+
public function getNumericTagSuffix()
265265
{
266-
return $this->_numeric_node_suffix;
266+
return $this->_numeric_tag_suffix;
267267
}
268268

269269
/**
270-
* Validate if a given value has a proper node/tag starting character to be used in XML
270+
* Validate if a given value has a proper tag starting character to be used in XML
271271
*
272272
* @param null $value
273273
* @return bool
274274
*/
275-
public static function hasValidNodeStart($value = null)
275+
public static function hasValidXmlTagStartingChar($value = null)
276276
{
277-
if(preg_match(self::getValidXmlNodeStartPattern(), $value) === 1) {
277+
if(preg_match(self::getValidXmlTagStartPattern(), $value) === 1) {
278278
return true;
279279
}
280280
return false;
281281
}
282282

283283
/**
284-
* Validate if a given value is a valid node/tag character
284+
* Validate if a given value is a valid tag character
285285
*
286286
* @param null $value
287287
* @return bool
288288
*/
289-
public static function isValidNodeNameChar($value = null)
289+
public static function isValidXmlTagChar($value = null)
290290
{
291-
if(preg_match(self::getValidXmlNodeNameChar(), $value) === 1) {
291+
if(preg_match(self::getValidXmlTagNameChar(), $value) === 1) {
292292
return true;
293293
}
294294
return false;
295295
}
296296

297297
/**
298-
* Validate if a given value is a proper node/tag name to be used in XML
298+
* Validate if a given value is a proper tag name to be used in XML
299299
*
300300
* @param null $value
301301
* @return bool
302302
*/
303-
public static function isValidNodeName($value = null)
303+
public static function isValidXmlTag($value = null)
304304
{
305305
if(empty($value) || is_int($value)) {
306306
return false;
307307
}
308308

309-
if(preg_match(self::getValidXmlNodeNamePattern(), $value) === 1) {
309+
if(preg_match(self::getValidXmlTagNamePattern(), $value) === 1) {
310310
return true;
311311
}
312312
return false;
@@ -333,11 +333,11 @@ public function toXmlString($array = [])
333333
}
334334

335335
/**
336-
* Get a regex pattern for valid node names
336+
* Get a regex pattern for valid tag names
337337
*
338338
* @return string
339339
*/
340-
protected static function getValidXmlNodeNamePattern()
340+
protected static function getValidXmlTagNamePattern()
341341
{
342342
return '~
343343
# XML 1.0 Name symbol PHP PCRE regex <http://www.w3.org/TR/REC-xml/#NT-Name>
@@ -351,11 +351,11 @@ protected static function getValidXmlNodeNamePattern()
351351
}
352352

353353
/**
354-
* Get a regex pattern for valid node chars
354+
* Get a regex pattern for valid tag chars
355355
*
356356
* @return string
357357
*/
358-
protected static function getValidXmlNodeNameChar()
358+
protected static function getValidXmlTagNameChar()
359359
{
360360
return '~
361361
(?(DEFINE)
@@ -367,11 +367,11 @@ protected static function getValidXmlNodeNameChar()
367367
}
368368

369369
/**
370-
* Get a regex pattern for valid node starting characters
370+
* Get a regex pattern for valid tag starting characters
371371
*
372372
* @return string
373373
*/
374-
protected static function getValidXmlNodeStartPattern()
374+
protected static function getValidXmlTagStartPattern()
375375
{
376376
return '~^([:A-Z_a-z\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\x{2FF}\\x{370}-\\x{37D}\\x{37F}-\\x{1FFF}\\x{200C}-\\x{200D}\\x{2070}-\\x{218F}\\x{2C00}-\\x{2FEF}\\x{3001}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFFD}\\x{10000}-\\x{EFFFF}])~ux';
377377
}
@@ -451,7 +451,7 @@ protected function isNumericKey($value)
451451
*/
452452
protected function createElement($name, $value = null, $cdata = false, $attributes = [])
453453
{
454-
$name = $this->createValidNodeName($name);
454+
$name = $this->createValidTagName($name);
455455

456456
if($cdata === true) {
457457
$element = $this->_doc->createElement($name);
@@ -474,60 +474,60 @@ protected function createElement($name, $value = null, $cdata = false, $attribut
474474
}
475475

476476
/**
477-
* Creates a valid node name
477+
* Creates a valid tag name
478478
*
479479
* @param null $name
480480
* @return string
481481
*/
482-
protected function createValidNodeName($name = null)
482+
protected function createValidTagName($name = null)
483483
{
484484
if(empty($name) || $this->isNumericKey($name)) {
485485
$key = $name;
486486

487-
if ($this->isValidNodeName($this->getCustomNodeName())) {
488-
$name = $this->getCustomNodeName();
487+
if ($this->isValidXmlTag($this->getCustomTagName())) {
488+
$name = $this->getCustomTagName();
489489
} else {
490-
$name = $this->transformNodeName($this->getDefaultNodeName());
490+
$name = $this->transformTagName($this->getDefaultTagName());
491491
}
492492

493-
if($this->getNumericNodeSuffix() !== null) {
494-
$name = $name . (string)$this->getNumericNodeSuffix() . $key;
493+
if($this->getNumericTagSuffix() !== null) {
494+
$name = $name . (string)$this->getNumericTagSuffix() . $key;
495495
}
496496
return $name;
497497
}
498498

499-
if(!$this->isValidNodeName($name)) {
500-
$name = $this->replaceInvalidNodeChars($name);
499+
if(!$this->isValidXmlTag($name)) {
500+
$name = $this->replaceInvalidTagChars($name);
501501

502-
if(!self::hasValidNodeStart($name)) {
503-
$name = $this->prefixInvalidNodeStartingChar($name);
502+
if(!self::hasValidXmlTagStartingChar($name)) {
503+
$name = $this->prefixInvalidTagStartingChar($name);
504504
}
505505
}
506-
return $this->transformNodeName($name);
506+
return $this->transformTagName($name);
507507
}
508508

509509
/**
510-
* If a node has an invalid starting character, use an underscore as prefix
510+
* If a tag has an invalid starting character, use an underscore as prefix
511511
*
512512
* @param $value
513513
* @return string
514514
*/
515-
protected function prefixInvalidNodeStartingChar($value)
515+
protected function prefixInvalidTagStartingChar($value)
516516
{
517517
return '_' . substr($value, 1);
518518
}
519519

520520
/**
521-
* Replace invalid node characters
521+
* Replace invalid tag characters
522522
*
523523
* @param $value
524524
* @return null|string|string[]
525525
*/
526-
protected function replaceInvalidNodeChars($value)
526+
protected function replaceInvalidTagChars($value)
527527
{
528528
$pattern = '';
529529
for($i=0; $i < strlen($value); $i++) {
530-
if(!self::isValidNodeNameChar($value[$i])) {
530+
if(!self::isValidXmlTagChar($value[$i])) {
531531
$pattern .= "\\$value[$i]";
532532
}
533533
}
@@ -549,21 +549,21 @@ protected function createValidRootName($name = null)
549549
if (is_string($name)) {
550550
$name = preg_replace("/[^_a-zA-Z0-9]/", $this->getSeparator(), $name);
551551
}
552-
if ($this->isValidNodeName($name)) {
552+
if ($this->isValidXmlTag($name)) {
553553
return $name;
554554
}
555-
return $this->transformNodeName($this->getDefaultRootName());
555+
return $this->transformTagName($this->getDefaultRootName());
556556
}
557557

558558
/**
559-
* Transforms a node name (only when specified)
559+
* Transforms a tag name (only when specified)
560560
*
561561
* @param null $name
562562
* @return null|string
563563
*/
564-
protected function transformNodeName($name = null)
564+
protected function transformTagName($name = null)
565565
{
566-
switch($this->getMethodTransformKeys()) {
566+
switch($this->getTransformTags()) {
567567
case self::LOWERCASE: {
568568
return strtolower($name);
569569
break;

0 commit comments

Comments
 (0)