abstract class AbstractMessageParser

Implements shared message parsing functionality

Hierarchy

Expanded class hierarchy of AbstractMessageParser

File

drupal/core/vendor/guzzle/parser/Guzzle/Parser/Message/AbstractMessageParser.php, line 8

Namespace

Guzzle\Parser\Message
View source
abstract class AbstractMessageParser implements MessageParserInterface {

  /**
   * Create URL parts from HTTP message parts
   *
   * @param string $requestUrl Associated URL
   * @param array  $parts      HTTP message parts
   *
   * @return array
   */
  protected function getUrlPartsFromMessage($requestUrl, array $parts) {

    // Parse the URL information from the message
    $urlParts = array(
      'path' => $requestUrl,
      'scheme' => 'http',
    );

    // Check for the Host header
    if (isset($parts['headers']['Host'])) {
      $urlParts['host'] = $parts['headers']['Host'];
    }
    elseif (isset($parts['headers']['host'])) {
      $urlParts['host'] = $parts['headers']['host'];
    }
    else {
      $urlParts['host'] = '';
    }
    if (false === strpos($urlParts['host'], ':')) {
      $urlParts['port'] = '';
    }
    else {
      $hostParts = explode(':', $urlParts['host']);
      $urlParts['host'] = trim($hostParts[0]);
      $urlParts['port'] = (int) trim($hostParts[1]);
      if ($urlParts['port'] == 443) {
        $urlParts['scheme'] = 'https';
      }
    }

    // Check if a query is present
    $path = $urlParts['path'];
    $qpos = strpos($path, '?');
    if ($qpos) {
      $urlParts['query'] = substr($path, $qpos + 1);
      $urlParts['path'] = substr($path, 0, $qpos);
    }
    else {
      $urlParts['query'] = '';
    }
    return $urlParts;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractMessageParser::getUrlPartsFromMessage protected function Create URL parts from HTTP message parts
MessageParserInterface::parseRequest public function Parse an HTTP request message into an associative array of parts. 2
MessageParserInterface::parseResponse public function Parse an HTTP response message into an associative array of parts. 2