[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Captcha/Google/ -> HttpBridgePostRequestMethod.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Captcha\Google;
  11  
  12  use Joomla\CMS\Http\HttpFactory;
  13  use Joomla\Http\Exception\InvalidResponseCodeException;
  14  use Joomla\Http\Http;
  15  use ReCaptcha\RequestMethod;
  16  use ReCaptcha\RequestParameters;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('JPATH_PLATFORM') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * Bridges the Joomla! HTTP API to the Google Recaptcha RequestMethod interface for a POST request.
  24   *
  25   * @since  3.9.0
  26   */
  27  final class HttpBridgePostRequestMethod implements RequestMethod
  28  {
  29      /**
  30       * URL to which requests are sent.
  31       *
  32       * @var    string
  33       * @since  3.9.0
  34       */
  35      public const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';
  36  
  37      /**
  38       * The HTTP adapter
  39       *
  40       * @var    Http
  41       * @since  3.9.0
  42       */
  43      private $http;
  44  
  45      /**
  46       * Class constructor.
  47       *
  48       * @param   Http|null  $http  The HTTP adapter
  49       *
  50       * @since   3.9.0
  51       */
  52      public function __construct(Http $http = null)
  53      {
  54          $this->http = $http ?: HttpFactory::getHttp();
  55      }
  56  
  57      /**
  58       * Submit the request with the specified parameters.
  59       *
  60       * @param   RequestParameters  $params  Request parameters
  61       *
  62       * @return  string  Body of the reCAPTCHA response
  63       *
  64       * @since   3.9.0
  65       */
  66      public function submit(RequestParameters $params)
  67      {
  68          try {
  69              $response = $this->http->post(self::SITE_VERIFY_URL, $params->toArray());
  70  
  71              return (string) $response->getBody();
  72          } catch (InvalidResponseCodeException $exception) {
  73              return '';
  74          }
  75      }
  76  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer