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.

Differences Between: [Versions 310 and 401] [Versions 39 and 401] [Versions 401 and 402] [Versions 401 and 403]

   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  }