You are here

function LingotekOAuthRequest::__construct in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.7 lib/oauth-php/library/LingotekOAuthRequest.php \LingotekOAuthRequest::__construct()
  2. 7.5 lib/oauth-php/library/LingotekOAuthRequest.php \LingotekOAuthRequest::__construct()
  3. 7.6 lib/oauth-php/library/LingotekOAuthRequest.php \LingotekOAuthRequest::__construct()

* Construct from the current request. Useful for checking the signature of a request. * When not supplied with any parameters this will use the current request. * *

Parameters

string uri might include parameters: * @param string method GET, PUT, POST etc. * @param string parameters additional post parameters, urlencoded (RFC1738) * @param array headers headers for request * @param string body optional body of the OAuth request (POST or PUT)

2 calls to LingotekOAuthRequest::__construct()
LingotekOAuthRequestSigner::__construct in lib/oauth-php/library/LingotekOAuthRequestSigner.php
* Construct the request to be signed. Parses or appends the parameters in the params url. * When you supply an params array, then the params should not be urlencoded. * When you supply a string, then it is assumed it is of the type…
LingotekOAuthRequestVerifier::__construct in lib/oauth-php/library/LingotekOAuthRequestVerifier.php
* Construct the request to be verified * *
2 methods override LingotekOAuthRequest::__construct()
LingotekOAuthRequestSigner::__construct in lib/oauth-php/library/LingotekOAuthRequestSigner.php
* Construct the request to be signed. Parses or appends the parameters in the params url. * When you supply an params array, then the params should not be urlencoded. * When you supply a string, then it is assumed it is of the type…
LingotekOAuthRequestVerifier::__construct in lib/oauth-php/library/LingotekOAuthRequestVerifier.php
* Construct the request to be verified * *

File

lib/oauth-php/library/LingotekOAuthRequest.php, line 73

Class

LingotekOAuthRequest
Object to parse an incoming OAuth request or prepare an outgoing OAuth request

Code

function __construct($uri = null, $method = null, $parameters = '', $headers = array(), $body = null) {
  if (is_object($_SERVER)) {

    // Tainted arrays - the normal stuff in anyMeta
    if (!$method) {
      $method = $_SERVER->REQUEST_METHOD
        ->getRawUnsafe();
    }
    if (empty($uri)) {
      $uri = $_SERVER->REQUEST_URI
        ->getRawUnsafe();
    }
  }
  else {

    // non anyMeta systems
    if (!$method) {
      if (isset($_SERVER['REQUEST_METHOD'])) {
        $method = $_SERVER['REQUEST_METHOD'];
      }
      else {
        $method = 'GET';
      }
    }
    $proto = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
    if (empty($uri)) {
      if (strpos($_SERVER['REQUEST_URI'], "://") !== false) {
        $uri = $_SERVER['REQUEST_URI'];
      }
      else {
        $uri = sprintf('%s://%s%s', $proto, $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']);
      }
    }
  }
  $headers = LingotekOAuthRequestLogger::getAllHeaders();
  $this->method = strtoupper($method);

  // If this is a post then also check the posted variables
  if (strcasecmp($method, 'POST') == 0) {

    // TODO: what to do with 'multipart/form-data'?
    if ($this
      ->getRequestContentType() == 'multipart/form-data') {

      // Get the posted body (when available)
      if (!isset($headers['X-OAuth-Test'])) {
        $parameters .= $this
          ->getRequestBodyOfMultipart();
      }
    }
    if ($this
      ->getRequestContentType() == 'application/x-www-form-urlencoded') {

      // Get the posted body (when available)
      if (!isset($headers['X-OAuth-Test'])) {
        $parameters .= $this
          ->getRequestBody();
      }
    }
    else {
      $body = $this
        ->getRequestBody();
    }
  }
  else {
    if (strcasecmp($method, 'PUT') == 0) {
      $body = $this
        ->getRequestBody();
    }
  }
  $this->method = strtoupper($method);
  $this->headers = $headers;

  // Store the values, prepare for oauth
  $this->uri = $uri;
  $this->body = $body;
  $this
    ->parseUri($parameters);
  $this
    ->parseHeaders();
  $this
    ->transcodeParams();
}