Source for file encoding.php
Documentation is available at encoding.php
* base include file for SimpleTest
* @version $Id: encoding.php 1723 2008-04-08 00:34:10Z lastcraft $
* include other SimpleTest class files
require_once(dirname(__FILE__
) .
'/socket.php');
* Stashes the data for rendering later.
* @param string $key Form element name.
* @param string $value Data to send.
* The pair as a single string.
* @return string Encoded pair.
* The MIME part as a string.
* @return string MIME part encoding.
$part =
'Content-Disposition: form-data; ';
$part .=
"name=\"" .
$this->_key .
"\"\r\n";
$part .=
"\r\n" .
$this->_value;
* Is this the value we are looking for?
* @param string $key Identifier.
* @return boolean True if matched.
return $key ==
$this->_key;
* Is this the value we are looking for?
* @return string Identifier.
* Is this the value we are looking for?
* @return string Content.
* Stashes the data for rendering later.
* @param string $key Key to add value to.
* @param string $content Raw data.
* @param hash $filename Original filename.
* The pair as a single string.
* @return string Encoded pair.
* The MIME part as a string.
* @return string MIME part encoding.
$part =
'Content-Disposition: form-data; ';
$part .=
'name="' .
$this->_key .
'"; ';
$part .=
'filename="' .
$this->_filename .
'"';
$part .=
"\r\nContent-Type: " .
$this->_deduceMimeType();
* Attempts to figure out the MIME type from the
* file extension and the content.
* @return string MIME type.
function _deduceMimeType() {
if ($this->_isOnlyAscii($this->_content)) {
return 'application/octet-stream';
* Tests each character is in the range 0-127.
* @param string $ascii String to test.
function _isOnlyAscii($ascii) {
for ($i =
0, $length =
strlen($ascii); $i <
$length; $i++
) {
if (ord($ascii[$i]) >
127) {
* Is this the value we are looking for?
* @param string $key Identifier.
* @return boolean True if matched.
return $key ==
$this->_key;
* Is this the value we are looking for?
* @return string Identifier.
* Is this the value we are looking for?
* @return string Content.
* Bundle of GET/POST parameters. Can include
* @param array $query Hash of parameters.
* as lists on a single key.
* Empties the request of parameters.
* Adds a parameter to the query.
* @param string $key Key to add value to.
* @param string/array $value New data.
function add($key, $value) {
foreach ($value as $item) {
$this->_addPair($key, $item);
$this->_addPair($key, $value);
* Adds a new value into the request.
* @param string $key Key to add value to.
* @param string/array $value New data.
function _addPair($key, $value) {
* Adds a MIME part to the query. Does nothing for a
* @param string $key Key to add value to.
* @param string $content Raw data.
* @param hash $filename Original filename.
function attach($key, $content, $filename) {
* Adds a set of parameters to this query.
* @param array/SimpleQueryString $query Multiple values are
* as lists on a single key.
foreach ($query as $key =>
$value) {
$this->add($key, $value);
* Accessor for single value.
* @return string/array False if missing, string
* if present and array if
if ($pair->isKey($key)) {
$values[] =
$pair->getValue();
if (count($values) ==
0) {
} elseif (count($values) ==
1) {
* Accessor for listing of pairs.
* @return array All pair objects.
* Renders the query string as a URL encoded
* @return string Part of URL.
if ($statement =
$pair->asRequest()) {
$statements[] =
$statement;
* Bundle of GET parameters. Can include
* @param array $query Hash of parameters.
* as lists on a single key.
* @return string Always GET.
* Writes no extra headers.
* @param SimpleSocket $socket Socket to write to.
* No data is sent to the socket as the data is encoded into
* @param SimpleSocket $socket Socket to write to.
* Renders the query string as a URL encoded
* request part for attaching to a URL.
* @return string Part of URL.
* Bundle of URL parameters for a HEAD request.
* @param array $query Hash of parameters.
* as lists on a single key.
* @return string Always HEAD.
* Bundle of POST parameters. Can include
* @param array $query Hash of parameters.
* as lists on a single key.
foreach ($query as $key =>
$value) {
foreach ($query as $key =>
$value) {
foreach ($value as $sub_key =>
$sub_value) {
$query_[$key.
"[".
$sub_key.
"]"] =
$sub_value;
* @return string Always POST.
* Dispatches the form headers down the socket.
* @param SimpleSocket $socket Socket to write to.
$socket->write("Content-Length: " . (integer)
strlen($this->_encode()) .
"\r\n");
$socket->write("Content-Type: application/x-www-form-urlencoded\r\n");
* Dispatches the form data down the socket.
* @param SimpleSocket $socket Socket to write to.
* Renders the query string as a URL encoded
* request part for attaching to a URL.
* @return string Part of URL.
* Bundle of POST parameters in the multipart
* format. Can include file uploads.
* @param array $query Hash of parameters.
* as lists on a single key.
* Dispatches the form headers down the socket.
* @param SimpleSocket $socket Socket to write to.
$socket->write("Content-Length: " . (integer)
strlen($this->_encode()) .
"\r\n");
$socket->write("Content-Type: multipart/form-data, boundary=" .
$this->_boundary .
"\r\n");
* Dispatches the form data down the socket.
* @param SimpleSocket $socket Socket to write to.
* Renders the query string as a URL encoded
* @return string Part of URL.
$stream .=
$pair->asMime() .
"\r\n";
$stream .=
"--" .
$this->_boundary .
"--\r\n";
Documentation generated on Sun, 04 May 2008 09:21:31 -0500 by phpDocumentor 1.3.0