Exemplo n.º 1
0
 /**
  *    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);
 }
Exemplo n.º 2
0
 /**
  *    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;
 }
Exemplo n.º 3
0
 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');
 }
Exemplo n.º 4
0
 /**
  *    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());
 }
Exemplo n.º 5
0
 /**
  *    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;
 }
Exemplo n.º 6
0
 /**
  * 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);
 }