?? encoding.php
字號:
<?php /** * base include file for SimpleTest * @package SimpleTest * @subpackage WebTester * @version $Id: encoding.php 163 2008-01-14 04:40:16Z matt $ */ /**#@+ * include other SimpleTest class files */ require_once(dirname(__FILE__) . '/socket.php'); /**#@-*/ /** * Single post parameter. * @package SimpleTest * @subpackage WebTester */ class SimpleEncodedPair { var $_key; var $_value; /** * Stashes the data for rendering later. * @param string $key Form element name. * @param string $value Data to send. */ function SimpleEncodedPair($key, $value) { $this->_key = $key; $this->_value = $value; } /** * The pair as a single string. * @return string Encoded pair. * @access public */ function asRequest() { return urlencode($this->_key) . '=' . urlencode($this->_value); } /** * The MIME part as a string. * @return string MIME part encoding. * @access public */ function asMime() { $part = 'Content-Disposition: form-data; '; $part .= "name=\"" . $this->_key . "\"\r\n"; $part .= "\r\n" . $this->_value; return $part; } /** * Is this the value we are looking for? * @param string $key Identifier. * @return boolean True if matched. * @access public */ function isKey($key) { return $key == $this->_key; } /** * Is this the value we are looking for? * @return string Identifier. * @access public */ function getKey() { return $this->_key; } /** * Is this the value we are looking for? * @return string Content. * @access public */ function getValue() { return $this->_value; } } /** * Single post parameter. * @package SimpleTest * @subpackage WebTester */ class SimpleAttachment { var $_key; var $_content; var $_filename; /** * Stashes the data for rendering later. * @param string $key Key to add value to. * @param string $content Raw data. * @param hash $filename Original filename. */ function SimpleAttachment($key, $content, $filename) { $this->_key = $key; $this->_content = $content; $this->_filename = $filename; } /** * The pair as a single string. * @return string Encoded pair. * @access public */ function asRequest() { return ''; } /** * The MIME part as a string. * @return string MIME part encoding. * @access public */ function asMime() { $part = 'Content-Disposition: form-data; '; $part .= 'name="' . $this->_key . '"; '; $part .= 'filename="' . $this->_filename . '"'; $part .= "\r\nContent-Type: " . $this->_deduceMimeType(); $part .= "\r\n\r\n" . $this->_content; return $part; } /** * Attempts to figure out the MIME type from the * file extension and the content. * @return string MIME type. * @access private */ function _deduceMimeType() { if ($this->_isOnlyAscii($this->_content)) { return 'text/plain'; } return 'application/octet-stream'; } /** * Tests each character is in the range 0-127. * @param string $ascii String to test. * @access private */ function _isOnlyAscii($ascii) { for ($i = 0, $length = strlen($ascii); $i < $length; $i++) { if (ord($ascii[$i]) > 127) { return false; } } return true; } /** * Is this the value we are looking for? * @param string $key Identifier. * @return boolean True if matched. * @access public */ function isKey($key) { return $key == $this->_key; } /** * Is this the value we are looking for? * @return string Identifier. * @access public */ function getKey() { return $this->_key; } /** * Is this the value we are looking for? * @return string Content. * @access public */ function getValue() { return $this->_filename; } } /** * Bundle of GET/POST parameters. Can include * repeated parameters. * @package SimpleTest * @subpackage WebTester */ class SimpleEncoding { var $_request; /** * Starts empty. * @param array $query Hash of parameters. * Multiple values are * as lists on a single key. * @access public */ function SimpleEncoding($query = false) { if (! $query) { $query = array(); } $this->clear(); $this->merge($query); } /** * Empties the request of parameters. * @access public */ function clear() { $this->_request = array(); } /** * Adds a parameter to the query. * @param string $key Key to add value to. * @param string/array $value New data. * @access public */ function add($key, $value) { if ($value === false) { return; } if (is_array($value)) { foreach ($value as $item) { $this->_addPair($key, $item); } } else { $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. * @access private */ function _addPair($key, $value) { $this->_request[] = new SimpleEncodedPair($key, $value); } /** * Adds a MIME part to the query. Does nothing for a * form encoded packet. * @param string $key Key to add value to. * @param string $content Raw data. * @param hash $filename Original filename. * @access public */ function attach($key, $content, $filename) { $this->_request[] = new SimpleAttachment($key, $content, $filename); } /** * Adds a set of parameters to this query. * @param array/SimpleQueryString $query Multiple values are * as lists on a single key.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -