Composer provides an autoload.php file which registers its class loader and all required namespaces. If you are manually bootstrapping Drupal, ensure this file is included beforehand so that the classes are available:
require_once 'drupal/core/vendor/autoload.php'; require_once 'drupal/core/includes/bootstrap.inc';
Interacting with the Class Loader
In most cases, class namespaces are already registered for you and you should not have to worry about registering the class namespaces yourself. There might be times, however, where you need direct access to the class loader object itself. The class loader instance is available by calling the
drupal_classloader() function. By calling this function, you have access to register additional namespaces, interact with its class map, etc. This is a Composer\Autoload\ClassLoader object.
$loader = drupal_classloader(); $loader->add('MyNamespace', __DIR__);