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\Record;
   6  
   7  abstract class AbstractPlaceRecord extends AbstractRecord
   8  {
   9      private $locales;
  10  
  11      /**
  12       * @ignore
  13       */
  14      public function __construct(?array $record, array $locales = ['en'])
  15      {
  16          $this->locales = $locales;
  17          parent::__construct($record);
  18      }
  19  
  20      /**
  21       * @ignore
  22       */
  23      public function __get(string $attr)
  24      {
  25          if ($attr === 'name') {
  26              return $this->name();
  27          }
  28  
  29          return parent::__get($attr);
  30      }
  31  
  32      /**
  33       * @ignore
  34       */
  35      public function __isset(string $attr): bool
  36      {
  37          if ($attr === 'name') {
  38              return $this->firstSetNameLocale() !== null;
  39          }
  40  
  41          return parent::__isset($attr);
  42      }
  43  
  44      private function name(): ?string
  45      {
  46          $locale = $this->firstSetNameLocale();
  47  
  48          return $locale === null ? null : $this->names[$locale];
  49      }
  50  
  51      private function firstSetNameLocale(): ?string
  52      {
  53          foreach ($this->locales as $locale) {
  54              if (isset($this->names[$locale])) {
  55                  return $locale;
  56              }
  57          }
  58  
  59          return null;
  60      }
  61  }