/** * Sends the headers. * @param SimpleSocket $socket Open socket. * @param string $method HTTP request method, * usually GET. * @param SimpleFormEncoding $encoding Content to send with request. * @access private */ function _dispatchRequest(&$socket, $encoding) { foreach ($this->_headers as $header_line) { $socket->write($header_line . "\r\n"); } if (count($this->_cookies) > 0) { $socket->write("Cookie: " . implode(";", $this->_cookies) . "\r\n"); } $encoding->writeHeadersTo($socket); $socket->write("\r\n"); $encoding->writeTo($socket); }
/** * Breaks the request down into an object. * @param string $raw Raw request. * @return SimpleFormEncoding Parsed data. * @access private */ function _parseRequest($raw) { $request = new SimpleFormEncoding(); foreach (split("&", $raw) as $pair) { if (preg_match('/(.*?)=(.*)/', $pair, $matches)) { $request->add($matches[1], urldecode($matches[2])); } elseif ($pair) { $request->add($pair, ''); } } return $request; }
function testMergeInObjectWithCordinates() { $incoming = new SimpleFormEncoding(array('a' => 'A2')); $incoming->setCoordinates(25, 24); $encoding =& new SimpleFormEncoding(array('a' => 'A1')); $encoding->setCoordinates(1, 2); $encoding->merge($incoming); $this->assertIdentical($encoding->getValue('a'), array('A1', 'A2')); $this->assertIdentical($encoding->getX(), 25); $this->assertIdentical($encoding->getY(), 24); $this->assertIdentical($encoding->asString(), 'a=A1&a=A2?25,24'); }
/** * Calculates the length of the encoded content. * @param SimpleFormEncoding $encoding Content to send with * request or false. */ function _getContentLength($encoding) { if (!$encoding) { return 0; } return (int) strlen($encoding->asString()); }
/** * Creates the encoding for the current values in the * form. * @return SimpleFormEncoding Request to submit. * @access private */ function _getEncoding() { $encoding = new SimpleFormEncoding(); for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { $encoding->add($this->_widgets[$i]->getName(), $this->_widgets[$i]->getValue()); } return $encoding; }
/** * Sends the headers. * * @param SimpleSocket $socket Open socket. * @param string $method HTTP request method, usually GET. * @param SimpleFormEncoding $encoding Content to send with request. */ protected function dispatchRequest($socket, $encoding) { foreach ($this->headers as $header_line) { $socket->write($header_line . "\r\n"); } if (count($this->cookies) > 0) { $socket->write('Cookie: ' . implode(';', $this->cookies) . "\r\n"); } $encoding->writeHeadersTo($socket); $socket->write("\r\n"); $encoding->writeTo($socket); }