Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Calculation;
   4  
   5  use PhpOffice\PhpSpreadsheet\Settings;
   6  use Psr\Http\Client\ClientExceptionInterface;
   7  
   8  class Web
   9  {
  10      /**
  11       * WEBSERVICE.
  12       *
  13       * Returns data from a web service on the Internet or Intranet.
  14       *
  15       * Excel Function:
  16       *        Webservice(url)
  17       *
  18       * @return string the output resulting from a call to the webservice
  19       */
  20      public static function WEBSERVICE(string $url)
  21      {
  22          $url = trim($url);
  23          if (strlen($url) > 2048) {
  24              return Functions::VALUE(); // Invalid URL length
  25          }
  26  
  27          if (!preg_match('/^http[s]?:\/\//', $url)) {
  28              return Functions::VALUE(); // Invalid protocol
  29          }
  30  
  31          // Get results from the the webservice
  32          $client = Settings::getHttpClient();
  33          $requestFactory = Settings::getRequestFactory();
  34          $request = $requestFactory->createRequest('GET', $url);
  35  
  36          try {
  37              $response = $client->sendRequest($request);
  38          } catch (ClientExceptionInterface $e) {
  39              return Functions::VALUE(); // cURL error
  40          }
  41  
  42          if ($response->getStatusCode() != 200) {
  43              return Functions::VALUE(); // cURL error
  44          }
  45  
  46          $output = $response->getBody()->getContents();
  47          if (strlen($output) > 32767) {
  48              return Functions::VALUE(); // Output not a string or too long
  49          }
  50  
  51          return $output;
  52      }
  53  }