Skip to content

Commit

Permalink
Another patch from mike
Browse files Browse the repository at this point in the history
git-svn-id: http://sabreamf.googlecode.com/svn/trunk@244 4d1502ab-f33c-0410-ba90-8f7d5a69d0d2
  • Loading branch information
evert committed Sep 17, 2009
1 parent 071d803 commit 57c6a70
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions SabreAMF/AMF3/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,44 +226,50 @@ public function writeString($str) {
}

/**
* writeArray
*
* @param array $arr
* @return void
* Checks wether the provided array has string keys and if it's not sparse.
*
* @param array $arr
* @return bool
*/
public function writeArray(array $arr) {

end($arr);

// We need to split up strings an numeric array keys
$num = array();
$string = array();
protected function isPureArray(array $array ) {
$i=0;
foreach($arr as $k=>$v) {
if (!is_numeric($k) || $k != $i || intval($k) != $k) {
$string[$k] = $v;
} else {
$num[] = $v;
foreach($array as $k=>$v) {
if ( $k !== $i && (int)$k !== $k ) {
return false;
}
$i++;
}

unset($arr);

// Writing the length for the numeric keys in the array
$arrLen = count($num);
$arrId = ($arrLen << 1) | 0x01;
return true;
}

$this->writeInt($arrId);
/**
* writeArray
*
* @param array $arr
* @return void
*/
public function writeArray(array $arr) {

foreach($string as $key=>$v) {
$this->writeString($key);
$this->writeAMFData($v);
}
$this->writeString("");

foreach($num as $v) {
$this->writeAMFData($v);
//Check if this is an associative array or not.
if ( !$this->isPureArray( $arr ) ) {
$this->writeInt(1);
foreach($arr as $key=>$value) {
$this->writeString($key);
$this->writeAMFData($value);
}
$this->writeString('');
} else {
// Writing the length for the numeric keys in the array
$arrLen = count($arr);
$arrId = ($arrLen << 1) | 0x01;

$this->writeInt($arrId);
$this->writeString('');

foreach($arr as $v) {
$this->writeAMFData($v);
}
}

}
Expand All @@ -283,5 +289,3 @@ public function writeDate(DateTime $data) {
}

}


0 comments on commit 57c6a70

Please sign in to comment.