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 311 and 401] [Versions 39 and 401]

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