Skip to content

Commit

Permalink
Fixed issue #9372: RemoteControl export_responses breaks with some XM…
Browse files Browse the repository at this point in the history
…L-RPC clients
  • Loading branch information
c-schmitz committed Nov 26, 2014
1 parent ad9163c commit 733d98f
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions application/libraries/BigData.php
@@ -1,13 +1,13 @@
<?php
<?php

/**
* Class containing helper functions for dealing with "big data".
* @author Sam Mousa <sam@befound.nl>
*/
class BigData {



/**
* This function combines json_encode and echo.
* If a stream is passed (or is part of the array) it's content will be
Expand All @@ -21,7 +21,7 @@ public static function json_echo($json, $options = 0)
{
// Scan array for any streams.
$hasStream = array_reduce($json, array('BigData', 'hasStream'), false);

// If there is no stream we are done.
if (!$hasStream)
{
Expand All @@ -31,9 +31,9 @@ public static function json_echo($json, $options = 0)
{
self::json_echo_data($json, ($options & JSON_FORCE_OBJECT) == JSON_FORCE_OBJECT);
}

}

protected static function hasStream(&$result, $item)
{
if ($result === true)
Expand All @@ -54,13 +54,13 @@ protected static function hasStream(&$result, $item)
return false;
}
}


protected static function isStream($item)
{
return is_object($item) && get_class($item) == 'BigFile';
}

protected static function isAssociative($array)
{
foreach ($array as $key => $value)
Expand All @@ -72,8 +72,8 @@ protected static function isAssociative($array)
}
return false;
}


protected static function json_echo_data($json)
{
if (self::isStream($json))
Expand Down Expand Up @@ -101,7 +101,7 @@ protected static function json_echo_data($json)
echo json_encode(null);
}
}

protected static function json_echo_array($json)
{
echo '[';
Expand All @@ -113,7 +113,7 @@ protected static function json_echo_array($json)
}
echo ']';
}

protected static function json_echo_number($json)
{
echo $json;
Expand All @@ -136,21 +136,21 @@ protected static function json_echo_object($json)
}
echo '}';
}

protected static function json_echo_string($json)
{
echo json_encode($json);
}

protected static function json_echo_stream(BigFile $data)
{
// Encode stream to base64.
echo '"';
$data->render();
echo '"';
}


protected static function tag($name, $data)
{
echo "<$name>$data</$name>\n";
Expand Down Expand Up @@ -180,9 +180,9 @@ public static function xmlrpc_echo($data)
{
self::xmlrpc_echo_string($data);
}

}

protected static function xmlrpc_echo_array($data)
{
echo '<array>';
Expand All @@ -196,7 +196,7 @@ protected static function xmlrpc_echo_array($data)
echo '</data>';
echo '</array>';
}

/**
* Prints XMLRPC numeric types.
* @param type $data
Expand All @@ -210,7 +210,7 @@ protected static function xmlrpc_echo_number($data)
self::tag('double', $data);
}
}

protected static function xmlrpc_echo_object($data)
{
echo '<struct>';
Expand All @@ -221,12 +221,12 @@ protected static function xmlrpc_echo_object($data)
echo '<value>';
self::xmlrpc_echo($value);
echo '</value>';

echo '</member>';
}
echo '</struct>';
}

protected static function xmlrpc_echo_stream($data)
{
$data->render();
Expand Down Expand Up @@ -267,13 +267,15 @@ public function render($type = null)
unlink($this->fileName);
}
}

protected function echo_base64()
{
echo '<string>'; // a Base64 tag would be more sensible here but it would break all current implementations
$fileHandle = fopen($this->fileName, 'r');
stream_filter_append($fileHandle, 'convert.base64-encode', STREAM_FILTER_READ);
fpassthru($fileHandle);
fclose($fileHandle);
echo '</string>';
}
}

Expand Down

0 comments on commit 733d98f

Please sign in to comment.