本文整理汇总了PHP中XML_Util::getDoctypeDeclaration方法的典型用法代码示例。如果您正苦于以下问题:PHP XML_Util::getDoctypeDeclaration方法的具体用法?PHP XML_Util::getDoctypeDeclaration怎么用?PHP XML_Util::getDoctypeDeclaration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XML_Util
的用法示例。
在下文中一共展示了XML_Util::getDoctypeDeclaration方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: serialize
/**
* serialize data
*
* @param mixed $data data to serialize
* @param array $options options array
*
* @return boolean true on success, pear error on failure
* @access public
* @uses XML_Util::getDoctypeDeclaration()
* @uses XML_Util::getXMLDeclaration()
* @internal uses error suppression "@settype()"
*/
function serialize($data, $options = null)
{
// if options have been specified, use them instead
// of the previously defined ones
if (is_array($options)) {
$optionsBak = $this->options;
if (isset($options['overrideOptions']) && $options['overrideOptions'] == true) {
$this->options = array_merge($this->_defaultOptions, $options);
} else {
$this->options = array_merge($this->options, $options);
}
} else {
$optionsBak = null;
}
// start depth is zero
$this->_tagDepth = 0;
$rootAttributes = $this->options[XML_SERIALIZER_OPTION_ROOT_ATTRIBS];
if (isset($this->options[XML_SERIALIZER_OPTION_NAMESPACE]) && is_array($this->options[XML_SERIALIZER_OPTION_NAMESPACE])) {
$rootAttributes['xmlns:' . $this->options[XML_SERIALIZER_OPTION_NAMESPACE][0]] = $this->options[XML_SERIALIZER_OPTION_NAMESPACE][1];
}
$this->_serializedData = '';
// serialize an array
if (is_array($data)) {
if (isset($this->options[XML_SERIALIZER_OPTION_ROOT_NAME])) {
$tagName = $this->options[XML_SERIALIZER_OPTION_ROOT_NAME];
} else {
$tagName = 'array';
}
$this->_serializedData .= $this->_serializeArray($data, $tagName, $rootAttributes);
} elseif (is_object($data)) {
// serialize an object
if (isset($this->options[XML_SERIALIZER_OPTION_ROOT_NAME])) {
$tagName = $this->options[XML_SERIALIZER_OPTION_ROOT_NAME];
} else {
$tagName = get_class($data);
}
$this->_serializedData .= $this->_serializeObject($data, $tagName, $rootAttributes);
} else {
$tag = array();
if (isset($this->options[XML_SERIALIZER_OPTION_ROOT_NAME])) {
$tag['qname'] = $this->options[XML_SERIALIZER_OPTION_ROOT_NAME];
} else {
$tag['qname'] = gettype($data);
}
$tagName = $tag['qname'];
if ($this->options[XML_SERIALIZER_OPTION_TYPEHINTS] === true) {
$rootAttributes[$this->options[XML_SERIALIZER_OPTION_ATTRIBUTE_TYPE]] = gettype($data);
}
if (!is_bool($data)) {
$tag['content'] = $data;
} elseif ($data === false) {
if ($this->options[XML_SERIALIZER_OPTION_FALSE_AS_STRING] === true) {
$tag['content'] = '0';
} else {
$tag['content'] = '';
}
} else {
$tag['content'] = $data;
}
@settype($data, 'string');
$tag['attributes'] = $rootAttributes;
$this->_serializedData = $this->_createXMLTag($tag);
}
// add doctype declaration
if ($this->options[XML_SERIALIZER_OPTION_DOCTYPE_ENABLED] === true) {
$this->_serializedData = XML_Util::getDoctypeDeclaration($tagName, $this->options[XML_SERIALIZER_OPTION_DOCTYPE]) . $this->options[XML_SERIALIZER_OPTION_LINEBREAKS] . $this->_serializedData;
}
// build xml declaration
if ($this->options[XML_SERIALIZER_OPTION_XML_DECL_ENABLED]) {
$atts = array();
$this->_serializedData = XML_Util::getXMLDeclaration('1.0', $this->options[XML_SERIALIZER_OPTION_XML_ENCODING]) . $this->options[XML_SERIALIZER_OPTION_LINEBREAKS] . $this->_serializedData;
}
if ($this->options[XML_SERIALIZER_OPTION_RETURN_RESULT] === true) {
$result = $this->_serializedData;
} else {
$result = true;
}
if ($optionsBak !== null) {
$this->options = $optionsBak;
}
return $result;
}
示例2: serialize
/**
* serialize data
*
* @access public
* @param mixed $data data to serialize
* @return boolean true on success, pear error on failure
*/
function serialize($data, $options = null)
{
// if options have been specified, use them instead
// of the previously defined ones
if (is_array($options)) {
$optionsBak = $this->options;
if (isset($options['overrideOptions']) && $options['overrideOptions'] == true) {
$this->options = array_merge($this->_defaultOptions, $options);
} else {
$this->options = array_merge($this->options, $options);
}
} else {
$optionsBak = null;
}
// start depth is zero
$this->_tagDepth = 0;
$this->_serializedData = '';
// serialize an array
if (is_array($data)) {
if (isset($this->options['rootName'])) {
$tagName = $this->options['rootName'];
} else {
$tagName = 'array';
}
$this->_serializedData .= $this->_serializeArray($data, $tagName, $this->options['rootAttributes']);
}
// add doctype declaration
if ($this->options['addDoctype'] === true) {
$this->_serializedData = XML_Util::getDoctypeDeclaration($tagName, $this->options['doctype']) . $this->options['linebreak'] . $this->_serializedData;
}
// build xml declaration
if ($this->options['addDecl']) {
$atts = array();
if (isset($this->options['encoding'])) {
$encoding = $this->options['encoding'];
} else {
$encoding = null;
}
$this->_serializedData = XML_Util::getXMLDeclaration('1.0', $encoding) . $this->options['linebreak'] . $this->_serializedData;
}
if ($optionsBak !== null) {
$this->options = $optionsBak;
}
return true;
}
示例3: serialize
/**
* serialize data
*
* @access public
* @param mixed $data data to serialize
* @return boolean true on success, pear error on failure
*/
function serialize($data, $options = null)
{
// if options have been specified, use them instead
// of the previously defined ones
if (is_array($options)) {
$optionsBak = $this->options;
if (isset($options["overrideOptions"]) && $options["overrideOptions"] == true) {
$this->options = array_merge($this->_defaultOptions, $options);
} else {
$this->options = array_merge($this->options, $options);
}
} else {
$optionsBak = null;
}
// maintain BC
if (isset($this->options["tagName"])) {
$this->options["rootName"] = $this->options["tagName"];
}
// start depth is zero
$this->_tagDepth = 0;
$this->_serializedData = "";
// serialize an array
if (is_array($data)) {
if (isset($this->options["rootName"])) {
$tagName = $this->options["rootName"];
} else {
$tagName = "array";
}
$this->_serializedData .= $this->_serializeArray($data, $tagName, $this->options["rootAttributes"]);
} elseif (is_object($data)) {
if (isset($this->options["rootName"])) {
$tagName = $this->options["rootName"];
} else {
$tagName = get_class($data);
}
$this->_serializedData .= $this->_serializeObject($data, $tagName, $this->options["rootAttributes"]);
}
// add doctype declaration
if ($this->options["addDoctype"] === true) {
$this->_serializedData = XML_Util::getDoctypeDeclaration($tagName, $this->options["doctype"]) . $this->options["linebreak"] . $this->_serializedData;
}
// build xml declaration
if ($this->options["addDecl"]) {
$atts = array();
if (isset($this->options["encoding"])) {
$encoding = $this->options["encoding"];
} else {
$encoding = null;
}
$this->_serializedData = XML_Util::getXMLDeclaration("1.0", $encoding) . $this->options["linebreak"] . $this->_serializedData;
}
if ($optionsBak !== null) {
$this->options = $optionsBak;
}
return true;
}