You are here

function AbstractClassLoader::register in X Autoload 7.5

Same name and namespace in other branches
  1. 7.4 lib/ClassLoader/AbstractClassLoader.php \Drupal\xautoload\ClassLoader\AbstractClassLoader::register()

Registers this instance as an autoloader.

Parameters

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

Overrides ClassLoaderInterface::register

File

src/ClassLoader/AbstractClassLoader.php, line 16

Class

AbstractClassLoader
Behaves mostly like the Symfony ClassLoader classes.

Namespace

Drupal\xautoload\ClassLoader

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',
    ));
  }
}