Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

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