You are here

class RequestParameters in reCAPTCHA 7.2

Same name and namespace in other branches
  1. 8.2 recaptcha-php/src/ReCaptcha/RequestParameters.php \ReCaptcha\RequestParameters
  2. 6.2 recaptcha-php/src/ReCaptcha/RequestParameters.php \ReCaptcha\RequestParameters

Stores and formats the parameters for the request to the reCAPTCHA service.

Hierarchy

Expanded class hierarchy of RequestParameters

7 files declare their use of RequestParameters
CurlPost.php in recaptcha-php/src/ReCaptcha/RequestMethod/CurlPost.php
CurlPostTest.php in recaptcha-php/tests/ReCaptcha/RequestMethod/CurlPostTest.php
Drupal7Post.php in src/ReCaptcha/RequestMethod/Drupal7Post.php
Custom Drupal 7 RequestMehod class for Google reCAPTCHA library.
Post.php in recaptcha-php/src/ReCaptcha/RequestMethod/Post.php
PostTest.php in recaptcha-php/tests/ReCaptcha/RequestMethod/PostTest.php

... See full list

File

recaptcha-php/src/ReCaptcha/RequestParameters.php, line 32

Namespace

ReCaptcha
View source
class RequestParameters {

  /**
   * The shared key between your site and reCAPTCHA.
   * @var string
   */
  private $secret;

  /**
   * The user response token provided by reCAPTCHA, verifying the user on your site.
   * @var string
   */
  private $response;

  /**
   * Remote user's IP address.
   * @var string
   */
  private $remoteIp;

  /**
   * Client version.
   * @var string
   */
  private $version;

  /**
   * Initialise parameters.
   *
   * @param string $secret Site secret.
   * @param string $response Value from g-captcha-response form field.
   * @param string $remoteIp User's IP address.
   * @param string $version Version of this client library.
   */
  public function __construct($secret, $response, $remoteIp = null, $version = null) {
    $this->secret = $secret;
    $this->response = $response;
    $this->remoteIp = $remoteIp;
    $this->version = $version;
  }

  /**
   * Array representation.
   *
   * @return array Array formatted parameters.
   */
  public function toArray() {
    $params = array(
      'secret' => $this->secret,
      'response' => $this->response,
    );
    if (!is_null($this->remoteIp)) {
      $params['remoteip'] = $this->remoteIp;
    }
    if (!is_null($this->version)) {
      $params['version'] = $this->version;
    }
    return $params;
  }

  /**
   * Query string representation for HTTP request.
   *
   * @return string Query string formatted parameters.
   */
  public function toQueryString() {
    return http_build_query($this
      ->toArray(), '', '&');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RequestParameters::$remoteIp private property Remote user's IP address.
RequestParameters::$response private property The user response token provided by reCAPTCHA, verifying the user on your site.
RequestParameters::$secret private property The shared key between your site and reCAPTCHA.
RequestParameters::$version private property Client version.
RequestParameters::toArray public function Array representation.
RequestParameters::toQueryString public function Query string representation for HTTP request.
RequestParameters::__construct public function Initialise parameters.