Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  namespace enrol_lti\local\ltiadvantage\lib;
  18  
  19  use Packback\Lti1p3\Interfaces\IHttpResponse;
  20  
  21  /**
  22   * An implementation of IHTTPResponse, for use with the lib/lti1p3 library code.
  23   *
  24   * @package    enrol_lti
  25   * @copyright  2022 Jake Dallimore <jrhdallimore@gmail.com>
  26   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   */
  28  class http_response implements IHttpResponse {
  29  
  30      /** @var string HTTP response body */
  31      private $body;
  32  
  33      /** @var array HTTP response header lines */
  34      private $headers;
  35  
  36      /** @var int http status code */
  37      private $statuscode;
  38  
  39      /**
  40       * Constructor.
  41       *
  42       * @param array $payload the array containing the body and headers.
  43       * @param int $statuscode the HTTP status code.
  44       */
  45      public function __construct(array $payload, int $statuscode) {
  46          $this->parse_payload($payload);
  47          $this->statuscode = $statuscode;
  48      }
  49  
  50      /**
  51       * Parse the array containing headers and body into instance vars.
  52       *
  53       * @param array $payload
  54       */
  55      private function parse_payload(array $payload): void {
  56          $this->headers = $payload['headers'];
  57          $this->body = $payload['body'];
  58      }
  59  
  60      /**
  61       * Get the HTTP response body string.
  62       *
  63       * @return string the HTTP response body.
  64       */
  65      public function getBody() {
  66          return $this->body;
  67      }
  68  
  69      /**
  70       * Get the HTTP headers array.
  71       *
  72       * @return array the array containing the headers.
  73       */
  74      public function getHeaders(): array {
  75          return $this->headers;
  76      }
  77  
  78      /**
  79       * Get the HTTP response status code.
  80       *
  81       * @return int the HTTP response status code.
  82       */
  83      public function getStatusCode(): int {
  84          return $this->statuscode;
  85      }
  86  }