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  /**
   4   * PSR-4 autoloader implementation for the MaxMind\DB namespace.
   5   * First we define the 'mmdb_autoload' function, and then we register
   6   * it with 'spl_autoload_register' so that PHP knows to use it.
   7   *
   8   * @param mixed $class
   9   */
  10  
  11  /**
  12   * Automatically include the file that defines <code>class</code>.
  13   *
  14   * @param string $class
  15   *                      the name of the class to load
  16   */
  17  function mmdb_autoload($class)
  18  {
  19      /*
  20      * A project-specific mapping between the namespaces and where
  21      * they're located. By convention, we include the trailing
  22      * slashes. The one-element array here simply makes things easy
  23      * to extend in the future if (for example) the test classes
  24      * begin to use one another.
  25      */
  26      $namespace_map = ['MaxMind\\Db\\' => __DIR__ . '/src/MaxMind/Db/'];
  27  
  28      foreach ($namespace_map as $prefix => $dir) {
  29          /* First swap out the namespace prefix with a directory... */
  30          $path = str_replace($prefix, $dir, $class);
  31  
  32          /* replace the namespace separator with a directory separator... */
  33          $path = str_replace('\\', '/', $path);
  34  
  35          /* and finally, add the PHP file extension to the result. */
  36          $path = $path . '.php';
  37  
  38          /* $path should now contain the path to a PHP file defining $class */
  39          if (file_exists($path)) {
  40              include $path;
  41          }
  42      }
  43  }
  44  
  45  spl_autoload_register('mmdb_autoload');