You are here

class Socket in reCAPTCHA 8.2

Same name and namespace in other branches
  1. 6.2 recaptcha-php/src/ReCaptcha/RequestMethod/Socket.php \ReCaptcha\RequestMethod\Socket
  2. 7.2 recaptcha-php/src/ReCaptcha/RequestMethod/Socket.php \ReCaptcha\RequestMethod\Socket

Convenience wrapper around native socket and file functions to allow for mocking.

Hierarchy

  • class \ReCaptcha\RequestMethod\Socket

Expanded class hierarchy of Socket

File

recaptcha-php/src/ReCaptcha/RequestMethod/Socket.php, line 33

Namespace

ReCaptcha\RequestMethod
View source
class Socket {
  private $handle = null;

  /**
   * fsockopen
   *
   * @see http://php.net/fsockopen
   * @param string $hostname
   * @param int $port
   * @param int $errno
   * @param string $errstr
   * @param float $timeout
   * @return resource
   */
  public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null) {
    $this->handle = fsockopen($hostname, $port, $errno, $errstr, is_null($timeout) ? ini_get("default_socket_timeout") : $timeout);
    if ($this->handle != false && $errno === 0 && $errstr === '') {
      return $this->handle;
    }
    return false;
  }

  /**
   * fwrite
   *
   * @see http://php.net/fwrite
   * @param string $string
   * @param int $length
   * @return int | bool
   */
  public function fwrite($string, $length = null) {
    return fwrite($this->handle, $string, is_null($length) ? strlen($string) : $length);
  }

  /**
   * fgets
   *
   * @see http://php.net/fgets
   * @param int $length
   * @return string
   */
  public function fgets($length = null) {
    return fgets($this->handle, $length);
  }

  /**
   * feof
   *
   * @see http://php.net/feof
   * @return bool
   */
  public function feof() {
    return feof($this->handle);
  }

  /**
   * fclose
   *
   * @see http://php.net/fclose
   * @return bool
   */
  public function fclose() {
    return fclose($this->handle);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Socket::$handle private property
Socket::fclose public function fclose
Socket::feof public function feof
Socket::fgets public function fgets
Socket::fsockopen public function fsockopen
Socket::fwrite public function fwrite