cvs: pecl /sdo/DAS Json.php
| From: | Simon Laws | Date: | Mon, 23 Oct 2006 21:50:34 +0000 |
| Subject: | cvs: pecl /sdo/DAS Json.php | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-6536@lists.php.net to get a copy of this message | ||
slaws Mon Oct 23 21:50:34 2006 UTC
Modified files:
/pecl/sdo/DAS Json.php
Log:
Temporary fix array end element detection logic
http://cvs.php.net/viewvc.cgi/pecl/sdo/DAS/Json.php?r1=1.3&r2=1.4&diff_format=u
Index: pecl/sdo/DAS/Json.php
diff -u pecl/sdo/DAS/Json.php:1.3 pecl/sdo/DAS/Json.php:1.4
--- pecl/sdo/DAS/Json.php:1.3 Mon Oct 23 16:53:08 2006
+++ pecl/sdo/DAS/Json.php Mon Oct 23 21:50:34 2006
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
| Author: SL |
+----------------------------------------------------------------------+
-$Id: Json.php,v 1.3 2006/10/23 16:53:08 slaws Exp $
+$Id: Json.php,v 1.4 2006/10/23 21:50:34 slaws Exp $
*/
@@ -180,8 +180,8 @@
$reflection = new SDO_Model_ReflectionDataObject($sdo);
$sdo_type = $reflection->getType();
- $last = end($sdo);
- reset($sdo);
+ $sdo_size = $this->_count($sdo);
+ $i = 0;
foreach ( $sdo as $property_name => $property_value ) {
$json_string .= "\"" . $property_name . "\":";
@@ -244,8 +244,9 @@
// it's a primitive type
$this->_encodePrimitiveFromSDO($property_value, $json_string,
$sdo_property_type_name);
}
-
- if ( $property_value != $last ) {
+
+ $i++;
+ if ( $i < $sdo_size ) {
$json_string .= ",";
}
}
@@ -255,26 +256,27 @@
private function _encodeArrayFromSDO ( $sdo, &$json_string, $sdo_type )
{
- $json_string .= "[";
+ $json_string .= "[";
+
+ $sdo_size = $this->_count($sdo);
+ $i = 0;
if ( $sdo_type->isDataType() == true )
{
// it's an array of primitives
- $last = end($sdo);
- reset($sdo);
foreach ( $sdo as $property_name => $property_value ) {
$this->_encodePrimitiveFromSDO($property_value, $json_string, $sdo_type);
- if ( $property_value != $last ) {
+ $i++;
+ if ( $i < $sdo_size ) {
$json_string .= ",";
}
}
} else {
// it's an array of objects
- $last = end($sdo);
- reset($sdo);
foreach ( $sdo as $property_name => $property_value ) {
$this->_encodeObjectFromSDO($property_value, $json_string);
- if ( $property_value != $last ) {
+ $i++;
+ if ( $i < $sdo_size ) {
$json_string .= ",";
}
}
@@ -295,7 +297,7 @@
if ( $sdo == true ) {
$json_string .= "true";
} else {
- $json_string .= "true";
+ $json_string .= "false";
}
break;
case "Byte":
@@ -324,7 +326,23 @@
// TODO - what to do about nulls
}
- }
+ }
+
+ /**
+ * Temporary count function because using the real count on an
+ * SDO returns the number of properties in the model rather than
+ * in the data object
+ */
+ private function _count ( $array )
+ {
+ $i = 0;
+
+ foreach ( $array as $item ) {
+ $i++;
+ }
+
+ return $i;
+ }
public function __destruct()
{