Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 39 and 400] [Versions 400 and 402] [Versions 400 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  }