Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403]

   1  <?php
   2  
   3  namespace IMSGlobal\LTI\ToolProvider;
   4  
   5  /**
   6   * Class to represent a tool consumer nonce
   7   *
   8   * @author  Stephen P Vickers <svickers@imsglobal.org>
   9   * @copyright  IMS Global Learning Consortium Inc
  10   * @date  2016
  11   * @version 3.0.2
  12   * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  13   */
  14  #[\AllowDynamicProperties]
  15  class ConsumerNonce
  16  {
  17  
  18  /**
  19   * Maximum age nonce values will be retained for (in minutes).
  20   */
  21      const MAX_NONCE_AGE = 30;  // in minutes
  22  
  23  /**
  24   * Date/time when the nonce value expires.
  25   *
  26   * @var int $expires
  27   */
  28      public $expires = null;
  29  
  30  /**
  31   * Tool Consumer to which this nonce applies.
  32   *
  33   * @var ToolConsumer $consumer
  34   */
  35      private $consumer = null;
  36  /**
  37   * Nonce value.
  38   *
  39   * @var string $value
  40   */
  41      private $value = null;
  42  
  43  /**
  44   * Class constructor.
  45   *
  46   * @param ToolConsumer      $consumer Consumer object
  47   * @param string            $value    Nonce value (optional, default is null)
  48   */
  49      public function __construct($consumer, $value = null)
  50      {
  51  
  52          $this->consumer = $consumer;
  53          $this->value = $value;
  54          $this->expires = time() + (self::MAX_NONCE_AGE * 60);
  55  
  56      }
  57  
  58  /**
  59   * Load a nonce value from the database.
  60   *
  61   * @return boolean True if the nonce value was successfully loaded
  62   */
  63      public function load()
  64      {
  65  
  66          return $this->consumer->getDataConnector()->loadConsumerNonce($this);
  67  
  68      }
  69  
  70  /**
  71   * Save a nonce value in the database.
  72   *
  73   * @return boolean True if the nonce value was successfully saved
  74   */
  75      public function save()
  76      {
  77  
  78          return $this->consumer->getDataConnector()->saveConsumerNonce($this);
  79  
  80      }
  81  
  82  /**
  83   * Get tool consumer.
  84   *
  85   * @return ToolConsumer Consumer for this nonce
  86   */
  87      public function getConsumer()
  88      {
  89  
  90          return $this->consumer;
  91  
  92      }
  93  
  94  /**
  95   * Get outcome value.
  96   *
  97   * @return string Outcome value
  98   */
  99      public function getValue()
 100      {
 101  
 102          return $this->value;
 103  
 104      }
 105  
 106  }