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.
   1  <?php
   2  
   3  namespace Matrix;
   4  
   5  /**
   6   *
   7   * Autoloader for Matrix classes
   8   *
   9   * @package Matrix
  10   * @copyright  Copyright (c) 2014 Mark Baker (https://github.com/MarkBaker/PHPMatrix)
  11   * @license    https://opensource.org/licenses/MIT          MIT
  12   */
  13  class Autoloader
  14  {
  15      /**
  16       * Register the Autoloader with SPL
  17       *
  18       */
  19      public static function Register()
  20      {
  21          if (function_exists('__autoload')) {
  22              //    Register any existing autoloader function with SPL, so we don't get any clashes
  23              spl_autoload_register('__autoload');
  24          }
  25          //    Register ourselves with SPL
  26          return spl_autoload_register(['Matrix\\Autoloader', 'Load']);
  27      }
  28  
  29  
  30      /**
  31       * Autoload a class identified by name
  32       *
  33       * @param    string    $pClassName    Name of the object to load
  34       */
  35      public static function Load($pClassName)
  36      {
  37          if ((class_exists($pClassName, false)) || (strpos($pClassName, 'Matrix\\') !== 0)) {
  38              // Either already loaded, or not a Matrix class request
  39              return false;
  40          }
  41  
  42          $pClassFilePath = __DIR__ . DIRECTORY_SEPARATOR .
  43                            'src' . DIRECTORY_SEPARATOR .
  44                            str_replace(['Matrix\\', '\\'], ['', '/'], $pClassName) .
  45                            '.php';
  46  
  47          if ((file_exists($pClassFilePath) === false) || (is_readable($pClassFilePath) === false)) {
  48              // Can't load
  49              return false;
  50          }
  51          require($pClassFilePath);
  52      }
  53  }