[Pull Request 3134] Improved code based on comments
This commit is contained in:
parent
90abc0f454
commit
7f3464386b
@ -304,21 +304,18 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
||||
return $appendNode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a value contains any characters which would require CDATA padding.
|
||||
* Checks if a value contains any characters which would require CDATA wrapping.
|
||||
*
|
||||
* @param string $val
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
private function needsCdataPadding($val)
|
||||
private function needsCdataWrapping($val)
|
||||
{
|
||||
return preg_match('/[<>&]/', $val);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tests the value being passed and decide what sort of element to create
|
||||
*
|
||||
@ -340,7 +337,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
||||
return $this->buildXml($node, $this->serializer->normalize($val, $this->format));
|
||||
} elseif (is_numeric($val)) {
|
||||
return $this->appendText($node, (string) $val);
|
||||
} elseif (is_string($val) && $this->needsCdataPadding($val)) {
|
||||
} elseif (is_string($val) && $this->needsCdataWrapping($val)) {
|
||||
return $this->appendCData($node, $val);
|
||||
} elseif (is_string($val)) {
|
||||
return $this->appendText($node, $val);
|
||||
|
Reference in New Issue
Block a user