You are here

function xautoload_ClassLoader::register in X Autoload 7.2

Registers this instance as an autoloader.

Parameters

boolean $prepend: If TRUE, the loader will be prepended. Otherwise, it will be appended.

File

lib/ClassLoader.php, line 25

Class

xautoload_ClassLoader
Behaves like the Symfony ClassLoader classes.

Code

function register($prepend = false) {

  // http://www.php.net/manual/de/function.spl-autoload-register.php#107362
  // "when specifying the third parameter (prepend), the function will fail badly in PHP 5.2"
  if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
    spl_autoload_register(array(
      $this,
      'loadClass',
    ), TRUE, $prepend);
  }
  elseif ($prepend) {
    $loaders = spl_autoload_functions();
    spl_autoload_register(array(
      $this,
      'loadClass',
    ));
    foreach ($loaders as $loader) {
      spl_autoload_unregister($loader);
      spl_autoload_register($loader);
    }
  }
  else {
    spl_autoload_register(array(
      $this,
      'loadClass',
    ));
  }
}