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 310 and 311] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  namespace GeoIp2\Model;
   6  
   7  /**
   8   * @ignore
   9   */
  10  abstract class AbstractModel implements \JsonSerializable
  11  {
  12      protected $raw;
  13  
  14      /**
  15       * @ignore
  16       */
  17      public function __construct(array $raw)
  18      {
  19          $this->raw = $raw;
  20      }
  21  
  22      /**
  23       * @ignore
  24       */
  25      protected function get(string $field)
  26      {
  27          if (isset($this->raw[$field])) {
  28              return $this->raw[$field];
  29          }
  30          if (preg_match('/^is_/', $field)) {
  31              return false;
  32          }
  33  
  34          return null;
  35      }
  36  
  37      /**
  38       * @ignore
  39       */
  40      public function __get(string $attr)
  41      {
  42          if ($attr !== 'instance' && property_exists($this, $attr)) {
  43              return $this->$attr;
  44          }
  45  
  46          throw new \RuntimeException("Unknown attribute: $attr");
  47      }
  48  
  49      /**
  50       * @ignore
  51       */
  52      public function __isset(string $attr): bool
  53      {
  54          return $attr !== 'instance' && isset($this->$attr);
  55      }
  56  
  57      public function jsonSerialize(): array
  58      {
  59          return $this->raw;
  60      }
  61  }