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\Record;
   6  
   7  use GeoIp2\Util;
   8  
   9  /**
  10   * Contains data for the traits record associated with an IP address.
  11   *
  12   * This record is returned by all location services and databases.
  13   *
  14   * @property-read int|null $autonomousSystemNumber The autonomous system number
  15   * associated with the IP address. See
  16   * https://en.wikipedia.org/wiki/Autonomous_system_(Internet%29. This attribute
  17   * is only available from the City and Insights web service and the GeoIP2
  18   * Enterprise database.
  19   * @property-read string|null $autonomousSystemOrganization The organization
  20   * associated with the registered autonomous system number for the IP address.
  21   * See https://en.wikipedia.org/wiki/Autonomous_system_(Internet%29. This
  22   * attribute is only available from the City and Insights web service and the
  23   * GeoIP2 Enterprise database.
  24   * @property-read string|null $connectionType The connection type may take the
  25   * following  values: "Dialup", "Cable/DSL", "Corporate", "Cellular".
  26   * Additional values may be added in the future. This attribute is only
  27   * available in the GeoIP2 Enterprise database.
  28   * @property-read string|null $domain The second level domain associated with the
  29   * IP address. This will be something like "example.com" or "example.co.uk",
  30   * not "foo.example.com". This attribute is only available from the
  31   * City and Insights web service and the GeoIP2 Enterprise
  32   * database.
  33   * @property-read string $ipAddress The IP address that the data in the model
  34   * is for. If you performed a "me" lookup against the web service, this
  35   * will be the externally routable IP address for the system the code is
  36   * running on. If the system is behind a NAT, this may differ from the IP
  37   * address locally assigned to it. This attribute is returned by all end
  38   * points.
  39   * @property-read bool $isAnonymous This is true if the IP address belongs to
  40   * any sort of anonymous network. This property is only available from GeoIP2
  41   * Precision Insights.
  42   * @property-read bool $isAnonymousProxy *Deprecated.* Please see our GeoIP2
  43   * Anonymous IP database
  44   * (https://www.maxmind.com/en/geoip2-anonymous-ip-database) to determine
  45   * whether the IP address is used by an anonymizing service.
  46   * @property-read bool $isAnonymousVpn This is true if the IP address is
  47   * registered to an anonymous VPN provider. If a VPN provider does not register
  48   * subnets under names associated with them, we will likely only flag their IP
  49   * ranges using the isHostingProvider property. This property is only available
  50   * from GeoIP2 Precision Insights.
  51   * @property-read bool $isHostingProvider This is true if the IP address belongs
  52   * to a hosting or VPN provider (see description of isAnonymousVpn property).
  53   * This property is only available from GeoIP2 Precision Insights.
  54   * @property-read bool $isLegitimateProxy This attribute is true if MaxMind
  55   * believes this IP address to be a legitimate proxy, such as an internal
  56   * VPN used by a corporation. This attribute is only available in the GeoIP2
  57   * Enterprise database.
  58   * @property-read bool $isPublicProxy This is true if the IP address belongs to
  59   * a public proxy. This property is only available from GeoIP2 Precision
  60   * Insights.
  61   * @property-read bool $isResidentialProxy This is true if the IP address is
  62   * on a suspected anonymizing network and belongs to a residential ISP. This
  63   * property is only available from GeoIP2 Precision Insights.
  64   * @property-read bool $isSatelliteProvider *Deprecated.* Due to the
  65   * increased coverage by mobile carriers, very few satellite providers now
  66   * serve multiple countries. As a result, the output does not provide
  67   * sufficiently relevant data for us to maintain it.
  68   * @property-read bool $isTorExitNode This is true if the IP address is a Tor
  69   * exit node. This property is only available from GeoIP2 Precision Insights.
  70   * @property-read string|null $isp The name of the ISP associated with the IP
  71   * address. This attribute is only available from the City and Insights web
  72   * services and the GeoIP2 Enterprise database.
  73   * @property-read string $network The network in CIDR notation associated with
  74   * the record. In particular, this is the largest network where all of the
  75   * fields besides $ipAddress have the same value.
  76   * @property-read string|null $organization The name of the organization associated
  77   * with the IP address. This attribute is only available from the City and
  78   * Insights web services and the GeoIP2 Enterprise database.
  79   * @property-read float|null $staticIPScore An indicator of how static or
  80   * dynamic an IP address is. This property is only available from GeoIP2
  81   * Precision Insights.
  82   * @property-read int|null $userCount The estimated number of users sharing
  83   * the IP/network during the past 24 hours. For IPv4, the count is for the
  84   * individual IP. For IPv6, the count is for the /64 network. This property is
  85   * only available from GeoIP2 Precision Insights.
  86   * @property-read string|null $userType <p>The user type associated with the IP
  87   *  address. This can be one of the following values:</p>
  88   *  <ul>
  89   *    <li>business
  90   *    <li>cafe
  91   *    <li>cellular
  92   *    <li>college
  93   *    <li>content_delivery_network
  94   *    <li>dialup
  95   *    <li>government
  96   *    <li>hosting
  97   *    <li>library
  98   *    <li>military
  99   *    <li>residential
 100   *    <li>router
 101   *    <li>school
 102   *    <li>search_engine_spider
 103   *    <li>traveler
 104   * </ul>
 105   * <p>
 106   *   This attribute is only available from the Insights web service and the
 107   *   GeoIP2 Enterprise database.
 108   * </p>
 109   */
 110  class Traits extends AbstractRecord
 111  {
 112      /**
 113       * @ignore
 114       */
 115      protected $validAttributes = [
 116          'autonomousSystemNumber',
 117          'autonomousSystemOrganization',
 118          'connectionType',
 119          'domain',
 120          'ipAddress',
 121          'isAnonymous',
 122          'isAnonymousProxy',
 123          'isAnonymousVpn',
 124          'isHostingProvider',
 125          'isLegitimateProxy',
 126          'isp',
 127          'isPublicProxy',
 128          'isResidentialProxy',
 129          'isSatelliteProvider',
 130          'isTorExitNode',
 131          'network',
 132          'organization',
 133          'staticIpScore',
 134          'userCount',
 135          'userType',
 136      ];
 137  
 138      public function __construct(?array $record)
 139      {
 140          if (!isset($record['network']) && isset($record['ip_address']) && isset($record['prefix_len'])) {
 141              $record['network'] = Util::cidr($record['ip_address'], $record['prefix_len']);
 142          }
 143  
 144          parent::__construct($record);
 145      }
 146  }