?? encoding.php
字號:
* @access public */ function merge($query) { if (is_object($query)) { $this->_request = array_merge($this->_request, $query->getAll()); } elseif (is_array($query)) { 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 * multiple entries. * @access public */ function getValue($key) { $values = array(); foreach ($this->_request as $pair) { if ($pair->isKey($key)) { $values[] = $pair->getValue(); } } if (count($values) == 0) { return false; } elseif (count($values) == 1) { return $values[0]; } else { return $values; } } /** * Accessor for listing of pairs. * @return array All pair objects. * @access public */ function getAll() { return $this->_request; } /** * Renders the query string as a URL encoded * request part. * @return string Part of URL. * @access protected */ function _encode() { $statements = array(); foreach ($this->_request as $pair) { if ($statement = $pair->asRequest()) { $statements[] = $statement; } } return implode('&', $statements); } } /** * Bundle of GET parameters. Can include * repeated parameters. * @package SimpleTest * @subpackage WebTester */ class SimpleGetEncoding extends SimpleEncoding { /** * Starts empty. * @param array $query Hash of parameters. * Multiple values are * as lists on a single key. * @access public */ function SimpleGetEncoding($query = false) { $this->SimpleEncoding($query); } /** * HTTP request method. * @return string Always GET. * @access public */ function getMethod() { return 'GET'; } /** * Writes no extra headers. * @param SimpleSocket $socket Socket to write to. * @access public */ function writeHeadersTo(&$socket) { } /** * No data is sent to the socket as the data is encoded into * the URL. * @param SimpleSocket $socket Socket to write to. * @access public */ function writeTo(&$socket) { } /** * Renders the query string as a URL encoded * request part for attaching to a URL. * @return string Part of URL. * @access public */ function asUrlRequest() { return $this->_encode(); } } /** * Bundle of URL parameters for a HEAD request. * @package SimpleTest * @subpackage WebTester */ class SimpleHeadEncoding extends SimpleGetEncoding { /** * Starts empty. * @param array $query Hash of parameters. * Multiple values are * as lists on a single key. * @access public */ function SimpleHeadEncoding($query = false) { $this->SimpleGetEncoding($query); } /** * HTTP request method. * @return string Always HEAD. * @access public */ function getMethod() { return 'HEAD'; } } /** * Bundle of POST parameters. Can include * repeated parameters. * @package SimpleTest * @subpackage WebTester */ class SimplePostEncoding extends SimpleEncoding { /** * Starts empty. * @param array $query Hash of parameters. * Multiple values are * as lists on a single key. * @access public */ function SimplePostEncoding($query = false) { $this->SimpleEncoding($query); } /** * HTTP request method. * @return string Always POST. * @access public */ function getMethod() { return 'POST'; } /** * Dispatches the form headers down the socket. * @param SimpleSocket $socket Socket to write to. * @access public */ function writeHeadersTo(&$socket) { $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. * @access public */ function writeTo(&$socket) { $socket->write($this->_encode()); } /** * Renders the query string as a URL encoded * request part for attaching to a URL. * @return string Part of URL. * @access public */ function asUrlRequest() { return ''; } } /** * Bundle of POST parameters in the multipart * format. Can include file uploads. * @package SimpleTest * @subpackage WebTester */ class SimpleMultipartEncoding extends SimplePostEncoding { var $_boundary; /** * Starts empty. * @param array $query Hash of parameters. * Multiple values are * as lists on a single key. * @access public */ function SimpleMultipartEncoding($query = false, $boundary = false) { $this->SimplePostEncoding($query); $this->_boundary = ($boundary === false ? uniqid('st') : $boundary); } /** * Dispatches the form headers down the socket. * @param SimpleSocket $socket Socket to write to. * @access public */ function writeHeadersTo(&$socket) { $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. * @access public */ function writeTo(&$socket) { $socket->write($this->_encode()); } /** * Renders the query string as a URL encoded * request part. * @return string Part of URL. * @access public */ function _encode() { $stream = ''; foreach ($this->_request as $pair) { $stream .= "--" . $this->_boundary . "\r\n"; $stream .= $pair->asMime() . "\r\n"; } $stream .= "--" . $this->_boundary . "--\r\n"; return $stream; } }?>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -