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.
   1  <?php
   2  
   3  /**
   4   * Autoloader Class
   5   *
   6   *  PHP Version 7
   7   *
   8   * @file      CAS/Autoload.php
   9   * @category  Authentication
  10   * @package   SimpleCAS
  11   * @author    Brett Bieber <brett.bieber@gmail.com>
  12   * @copyright 2008 Regents of the University of Nebraska
  13   * @license   http://www1.unl.edu/wdn/wiki/Software_License BSD License
  14   * @link      http://code.google.com/p/simplecas/
  15   **/
  16  
  17  /**
  18   * Autoload a class
  19   *
  20   * @param string $class Classname to load
  21   *
  22   * @return bool
  23   */
  24  function CAS_autoload($class)
  25  {
  26      // Static to hold the Include Path to CAS
  27      static $include_path;
  28      // Check only for CAS classes
  29      if (substr($class, 0, 4) !== 'CAS_' && substr($class, 0, 7) !== 'PhpCas\\') {
  30          return false;
  31      }
  32  
  33      // Setup the include path if it's not already set from a previous call
  34      if (empty($include_path)) {
  35          $include_path = array(dirname(__DIR__));
  36      }
  37  
  38      // Declare local variable to store the expected full path to the file
  39      foreach ($include_path as $path) {
  40          $class_path = str_replace('_', DIRECTORY_SEPARATOR, $class);
  41          // PhpCas namespace mapping
  42          if (substr($class_path, 0, 7) === 'PhpCas\\') {
  43              $class_path = 'CAS' . DIRECTORY_SEPARATOR . substr($class_path, 7);
  44          }
  45  
  46          $file_path = $path . DIRECTORY_SEPARATOR . $class_path . '.php';
  47          $fp = @fopen($file_path, 'r', true);
  48          if ($fp) {
  49              fclose($fp);
  50              include $file_path;
  51              if (!class_exists($class, false) && !interface_exists($class, false)) {
  52                  die(
  53                      new Exception(
  54                          'Class ' . $class . ' was not present in ' .
  55                          $file_path .
  56                          ' [CAS_autoload]'
  57                      )
  58                  );
  59              }
  60              return true;
  61          }
  62      }
  63  
  64      $e = new Exception(
  65          'Class ' . $class . ' could not be loaded from ' .
  66          $file_path . ', file does not exist (Path="'
  67          . implode(':', $include_path) .'") [CAS_autoload]'
  68      );
  69      $trace = $e->getTrace();
  70      if (isset($trace[2]) && isset($trace[2]['function'])
  71          && in_array($trace[2]['function'], array('class_exists', 'interface_exists', 'trait_exists'))
  72      ) {
  73          return false;
  74      }
  75      if (isset($trace[1]) && isset($trace[1]['function'])
  76          && in_array($trace[1]['function'], array('class_exists', 'interface_exists', 'trait_exists'))
  77      ) {
  78          return false;
  79      }
  80      die ((string) $e);
  81  }
  82  
  83  // Set up autoload if not already configured by composer.
  84  if (!class_exists('CAS_Client'))
  85  {
  86      trigger_error('phpCAS autoloader is deprecated. Install phpCAS using composer instead.', E_USER_DEPRECATED);
  87      spl_autoload_register('CAS_autoload');
  88      if (function_exists('__autoload')
  89          && !in_array('__autoload', spl_autoload_functions())
  90      ) {
  91          // __autoload() was being used, but now would be ignored, add
  92          // it to the autoload stack
  93          spl_autoload_register('__autoload');
  94      }
  95  }