cvs: pear /XML_Serializer Serializer.php Unserializer.php /XML_Serializer/examples serializeArrayWithObjects.php serializeObject.php
| From: | Stephan Schmidt | Date: | Fri, 26 Nov 2004 17:22:46 +0000 |
| Subject: | cvs: pear /XML_Serializer Serializer.php Unserializer.php /XML_Serializer/examples serializeArrayWithObjects.php serializeObject.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-26526@lists.php.net to get a copy of this message | ||
schst Fri Nov 26 12:22:46 2004 EDT
Modified files:
/pear/XML_Serializer Serializer.php Unserializer.php
/pear/XML_Serializer/examples serializeArrayWithObjects.php
serializeObject.php
Log:
fixed error handling (courtesy of Lukas)
removed some left-over tabs and replaced them with spaces
http://cvs.php.net/diff.php/pear/XML_Serializer/Serializer.php?r1=1.26&r2=1.27&ty=u
Index: pear/XML_Serializer/Serializer.php
diff -u pear/XML_Serializer/Serializer.php:1.26 pear/XML_Serializer/Serializer.php:1.27
--- pear/XML_Serializer/Serializer.php:1.26 Sat Nov 6 10:49:52 2004
+++ pear/XML_Serializer/Serializer.php Fri Nov 26 12:22:45 2004
@@ -16,7 +16,7 @@
// | Authors: Stephan Schmidt <schst@php-tools.net> |
// +----------------------------------------------------------------------+
//
-// $Id: Serializer.php,v 1.26 2004/11/06 15:49:52 schst Exp $
+// $Id: Serializer.php,v 1.27 2004/11/26 17:22:45 schst Exp $
/**
* uses PEAR error management
@@ -127,7 +127,7 @@
'rootAttributes' => array(), // attributes
of the root tag
'attributesArray' => null, // all values
in this key will be treated as attributes
'contentName' => null, // this value
will be used directly as content, instead of creating a new tag, may only be used in conjuction with
attributesArray
- 'tagMap' => array()
+ 'tagMap' => array()
);
/**
@@ -174,7 +174,7 @@
*/
function apiVersion()
{
- return '0.13';
+ return '0.13';
}
/**
@@ -287,10 +287,10 @@
}
- if ($optionsBak !== null) {
- $this->options = $optionsBak;
- }
-
+ if ($optionsBak !== null) {
+ $this->options = $optionsBak;
+ }
+
return true;
}
@@ -388,7 +388,7 @@
$string .= $this->_serializeValue( $val, $tagName, $attributes);
$string .= $this->options['linebreak'];
- // do indentation
+ // do indentation
if ($this->options['indent']!==null &&
$this->_tagDepth>0) {
$string .= str_repeat($this->options['indent'],
$this->_tagDepth);
}
@@ -397,14 +397,14 @@
}
}
- if ($this->options['scalarAsAttributes'] === true) {
- foreach ($array as $key => $value) {
- if (is_scalar($value) && (XML_Util::isValidName($key) === true)) {
- unset($array[$key]);
- $attributes[$this->options['prependAttributes'].$key] = $value;
- }
- }
- }
+ if ($this->options['scalarAsAttributes'] === true) {
+ foreach ($array as $key => $value) {
+ if (is_scalar($value) && (XML_Util::isValidName($key) === true)) {
+ unset($array[$key]);
+ $attributes[$this->options['prependAttributes'].$key] = $value;
+ }
+ }
+ }
// check for empty array => create empty tag
if (empty($array)) {
@@ -418,35 +418,37 @@
$this->_tagDepth++;
$tmp = $this->options['linebreak'];
foreach ($array as $key => $value) {
- // do indentation
+ // do indentation
if ($this->options['indent']!==null &&
$this->_tagDepth>0) {
$tmp .= str_repeat($this->options['indent'], $this->_tagDepth);
}
if (isset($this->options['tagMap'][$key])) {
- $key = $this->options['tagMap'][$key];
+ $key = $this->options['tagMap'][$key];
}
- // copy key
- $origKey = $key;
- // key cannot be used as tagname => use default tag
+ // copy key
+ $origKey = $key;
+ $this->expectError('*');
+ // key cannot be used as tagname => use default tag
$valid = XML_Util::isValidName($key);
- if (PEAR::isError($valid)) {
- if ($this->options['classAsTagName'] && is_object($value)) {
- $key = get_class($value);
- } else {
- $key = $this->options['defaultTagName'];
- }
- }
+ $this->popExpect();
+ if (PEAR::isError($valid)) {
+ if ($this->options['classAsTagName'] && is_object($value))
{
+ $key = get_class($value);
+ } else {
+ $key = $this->options['defaultTagName'];
+ }
+ }
$atts = array();
if ($this->options['typeHints'] === true) {
$atts[$this->options['typeAttribute']] = gettype($value);
- if ($key !== $origKey) {
- $atts[$this->options['keyAttribute']] = (string)$origKey;
- }
+ if ($key !== $origKey) {
+ $atts[$this->options['keyAttribute']] = (string)$origKey;
+ }
}
-
+
$tmp .= $this->_createXMLTag(array(
'qname' => $key,
'attributes' => $atts,
@@ -460,10 +462,10 @@
$tmp .= str_repeat($this->options['indent'], $this->_tagDepth);
}
- if (trim($tmp) === '') {
- $tmp = null;
- }
-
+ if (trim($tmp) === '') {
+ $tmp = null;
+ }
+
$tag = array(
'qname' => $tagName,
'content' => $tmp,
http://cvs.php.net/diff.php/pear/XML_Serializer/Unserializer.php?r1=1.23&r2=1.24&ty=u
Index: pear/XML_Serializer/Unserializer.php
diff -u pear/XML_Serializer/Unserializer.php:1.23 pear/XML_Serializer/Unserializer.php:1.24
--- pear/XML_Serializer/Unserializer.php:1.23 Sat Nov 6 10:49:52 2004
+++ pear/XML_Serializer/Unserializer.php Fri Nov 26 12:22:45 2004
@@ -16,7 +16,7 @@
// | Authors: Stephan Schmidt <schst@php-tools.net> |
// +----------------------------------------------------------------------+
//
-// $Id: Unserializer.php,v 1.23 2004/11/06 15:49:52 schst Exp $
+// $Id: Unserializer.php,v 1.24 2004/11/26 17:22:45 schst Exp $
/**
* uses PEAR error managemt
@@ -527,4 +527,4 @@
$this->_dataStack[$this->_depth] .= $cdata;
}
}
-?>
+?>
\ No newline at end of file
http://cvs.php.net/diff.php/pear/XML_Serializer/examples/serializeArrayWithObjects.php?r1=1.1&r2=1.2&ty=u
Index: pear/XML_Serializer/examples/serializeArrayWithObjects.php
diff -u pear/XML_Serializer/examples/serializeArrayWithObjects.php:1.1
pear/XML_Serializer/examples/serializeArrayWithObjects.php:1.2
--- pear/XML_Serializer/examples/serializeArrayWithObjects.php:1.1 Tue Aug 24 09:28:39 2004
+++ pear/XML_Serializer/examples/serializeArrayWithObjects.php Fri Nov 26 12:22:46 2004
@@ -21,6 +21,7 @@
$serializer = new XML_Serializer($options);
+ $serializer->setErrorHandling(PEAR_ERROR_DIE);
$array = array(
new stdClass(),
http://cvs.php.net/diff.php/pear/XML_Serializer/examples/serializeObject.php?r1=1.5&r2=1.6&ty=u
Index: pear/XML_Serializer/examples/serializeObject.php
diff -u pear/XML_Serializer/examples/serializeObject.php:1.5
pear/XML_Serializer/examples/serializeObject.php:1.6
--- pear/XML_Serializer/examples/serializeObject.php:1.5 Mon May 24 15:32:35 2004
+++ pear/XML_Serializer/examples/serializeObject.php Fri Nov 26 12:22:46 2004
@@ -29,7 +29,7 @@
$foo->arr = array();
$foo->zero = 0;
- $serializer = new XML_Serializer($options);
+ $serializer = &new XML_Serializer($options);
$result = $serializer->serialize($foo);