XmlEncoder
in package
implements
EncoderInterface, DecoderInterface, NormalizationAwareInterface, SerializerAwareInterface
Uses
SerializerAwareTrait
Tags
Table of Contents
Interfaces
- EncoderInterface
- DecoderInterface
- NormalizationAwareInterface
- Defines the interface of encoders that will normalize data themselves.
- SerializerAwareInterface
Constants
- AS_COLLECTION = 'as_collection'
- DECODER_IGNORED_NODE_TYPES = 'decoder_ignored_node_types'
- An array of ignored XML node types while decoding, each one of the DOM Predefined XML_* constants.
- ENCODER_IGNORED_NODE_TYPES = 'encoder_ignored_node_types'
- An array of ignored XML node types while encoding, each one of the DOM Predefined XML_* constants.
- ENCODING = 'xml_encoding'
- FORMAT = 'xml'
- FORMAT_OUTPUT = 'xml_format_output'
- LOAD_OPTIONS = 'load_options'
- A bit field of LIBXML_* constants.
- REMOVE_EMPTY_TAGS = 'remove_empty_tags'
- ROOT_NODE_NAME = 'xml_root_node_name'
- STANDALONE = 'xml_standalone'
- TYPE_CAST_ATTRIBUTES = 'xml_type_cast_attributes'
- VERSION = 'xml_version'
Properties
- $serializer : SerializerInterface
- $defaultContext : mixed
Methods
- __construct() : mixed
- decode() : mixed
- Decodes a string into PHP data.
- encode() : string
- Encodes data into the given format.
- setSerializer() : mixed
- supportsDecoding() : bool
- Checks whether the deserializer can decode from given format.
- supportsEncoding() : bool
- Checks whether the serializer can encode to given format.
- appendCData() : bool
- appendComment() : bool
- appendDocumentFragment() : bool
- appendText() : bool
- appendXMLString() : bool
- isElementNameValid() : bool
- Checks the name is a valid xml element name.
- appendNode() : bool
- Selects the type of node to create and appends it to the parent.
- buildXml() : bool
- Parse the data and convert it to DOMElements.
- createDomDocument() : DOMDocument
- Create a DOM document, taking serializer options into account.
- needsCdataWrapping() : bool
- Checks if a value contains any characters which would require CDATA wrapping.
- parseXml() : array<string|int, mixed>|string
- Parse the input DOMNode into an array or a string.
- parseXmlAttributes() : array<string|int, mixed>
- Parse the input DOMNode attributes into an array.
- parseXmlValue() : array<string|int, mixed>|string
- Parse the input DOMNode value (content and children) into an array or a string.
- selectNodeType() : bool
- Tests the value being passed and decide what sort of element to create.
Constants
AS_COLLECTION
public
mixed
AS_COLLECTION
= 'as_collection'
DECODER_IGNORED_NODE_TYPES
An array of ignored XML node types while decoding, each one of the DOM Predefined XML_* constants.
public
mixed
DECODER_IGNORED_NODE_TYPES
= 'decoder_ignored_node_types'
ENCODER_IGNORED_NODE_TYPES
An array of ignored XML node types while encoding, each one of the DOM Predefined XML_* constants.
public
mixed
ENCODER_IGNORED_NODE_TYPES
= 'encoder_ignored_node_types'
ENCODING
public
mixed
ENCODING
= 'xml_encoding'
FORMAT
public
mixed
FORMAT
= 'xml'
FORMAT_OUTPUT
public
mixed
FORMAT_OUTPUT
= 'xml_format_output'
LOAD_OPTIONS
A bit field of LIBXML_* constants.
public
mixed
LOAD_OPTIONS
= 'load_options'
REMOVE_EMPTY_TAGS
public
mixed
REMOVE_EMPTY_TAGS
= 'remove_empty_tags'
ROOT_NODE_NAME
public
mixed
ROOT_NODE_NAME
= 'xml_root_node_name'
STANDALONE
public
mixed
STANDALONE
= 'xml_standalone'
TYPE_CAST_ATTRIBUTES
public
mixed
TYPE_CAST_ATTRIBUTES
= 'xml_type_cast_attributes'
VERSION
public
mixed
VERSION
= 'xml_version'
Properties
$serializer
protected
SerializerInterface
$serializer
$defaultContext
private
mixed
$defaultContext
= [self::AS_COLLECTION => false, self::DECODER_IGNORED_NODE_TYPES => [\XML_PI_NODE, \XML_COMMENT_NODE], self::ENCODER_IGNORED_NODE_TYPES => [], self::LOAD_OPTIONS => \LIBXML_NONET | \LIBXML_NOBLANKS, self::REMOVE_EMPTY_TAGS => false, self::ROOT_NODE_NAME => 'response', self::TYPE_CAST_ATTRIBUTES => true]
Methods
__construct()
public
__construct([array<string|int, mixed> $defaultContext = [] ]) : mixed
Parameters
- $defaultContext : array<string|int, mixed> = []
decode()
Decodes a string into PHP data.
public
decode(string $data, string $format[, array<string|int, mixed> $context = [] ]) : mixed
Parameters
- $data : string
-
Data to decode
- $format : string
-
Format name
- $context : array<string|int, mixed> = []
-
Options that decoders have access to
The format parameter specifies which format the data is in; valid values depend on the specific implementation. Authors implementing this interface are encouraged to document which formats they support in a non-inherited phpdoc comment.
encode()
Encodes data into the given format.
public
encode(mixed $data, string $format[, array<string|int, mixed> $context = [] ]) : string
Parameters
- $data : mixed
-
Data to encode
- $format : string
-
Format name
- $context : array<string|int, mixed> = []
-
Options that normalizers/encoders have access to
Return values
stringsetSerializer()
public
setSerializer(SerializerInterface $serializer) : mixed
Parameters
- $serializer : SerializerInterface
supportsDecoding()
Checks whether the deserializer can decode from given format.
public
supportsDecoding(string $format) : bool
Parameters
- $format : string
-
Format name
Return values
boolsupportsEncoding()
Checks whether the serializer can encode to given format.
public
supportsEncoding(string $format) : bool
Parameters
- $format : string
-
Format name
Return values
boolappendCData()
protected
final appendCData(DOMNode $node, string $val) : bool
Parameters
- $node : DOMNode
- $val : string
Return values
boolappendComment()
protected
final appendComment(DOMNode $node, string $data) : bool
Parameters
- $node : DOMNode
- $data : string
Return values
boolappendDocumentFragment()
protected
final appendDocumentFragment(DOMNode $node, DOMDocumentFragment $fragment) : bool
Parameters
- $node : DOMNode
- $fragment : DOMDocumentFragment
Return values
boolappendText()
protected
final appendText(DOMNode $node, string $val) : bool
Parameters
- $node : DOMNode
- $val : string
Return values
boolappendXMLString()
protected
final appendXMLString(DOMNode $node, string $val) : bool
Parameters
- $node : DOMNode
- $val : string
Return values
boolisElementNameValid()
Checks the name is a valid xml element name.
protected
final isElementNameValid(string $name) : bool
Parameters
- $name : string
Return values
boolappendNode()
Selects the type of node to create and appends it to the parent.
private
appendNode(DOMNode $parentNode, mixed $data, string $format, array<string|int, mixed> $context, string $nodeName[, string $key = null ]) : bool
Parameters
- $parentNode : DOMNode
- $data : mixed
- $format : string
- $context : array<string|int, mixed>
- $nodeName : string
- $key : string = null
Return values
boolbuildXml()
Parse the data and convert it to DOMElements.
private
buildXml(DOMNode $parentNode, mixed $data, string $format, array<string|int, mixed> $context[, string $xmlRootNodeName = null ]) : bool
Parameters
- $parentNode : DOMNode
- $data : mixed
- $format : string
- $context : array<string|int, mixed>
- $xmlRootNodeName : string = null
Tags
Return values
boolcreateDomDocument()
Create a DOM document, taking serializer options into account.
private
createDomDocument(array<string|int, mixed> $context) : DOMDocument
Parameters
- $context : array<string|int, mixed>
Return values
DOMDocumentneedsCdataWrapping()
Checks if a value contains any characters which would require CDATA wrapping.
private
needsCdataWrapping(string $val) : bool
Parameters
- $val : string
Return values
boolparseXml()
Parse the input DOMNode into an array or a string.
private
parseXml(DOMNode $node[, array<string|int, mixed> $context = [] ]) : array<string|int, mixed>|string
Parameters
- $node : DOMNode
- $context : array<string|int, mixed> = []
Return values
array<string|int, mixed>|stringparseXmlAttributes()
Parse the input DOMNode attributes into an array.
private
parseXmlAttributes(DOMNode $node[, array<string|int, mixed> $context = [] ]) : array<string|int, mixed>
Parameters
- $node : DOMNode
- $context : array<string|int, mixed> = []
Return values
array<string|int, mixed>parseXmlValue()
Parse the input DOMNode value (content and children) into an array or a string.
private
parseXmlValue(DOMNode $node[, array<string|int, mixed> $context = [] ]) : array<string|int, mixed>|string
Parameters
- $node : DOMNode
- $context : array<string|int, mixed> = []
Return values
array<string|int, mixed>|stringselectNodeType()
Tests the value being passed and decide what sort of element to create.
private
selectNodeType(DOMNode $node, mixed $val, string $format, array<string|int, mixed> $context) : bool
Parameters
- $node : DOMNode
- $val : mixed
- $format : string
- $context : array<string|int, mixed>