This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
drupalcampbristol/vendor/symfony/class-loader
2015-11-17 16:48:54 -08:00
..
.gitignore Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663 2015-10-08 15:13:01 -07:00
ApcClassLoader.php Update to Drupal 8.0-dev-2015-11-17. Commits through da81cd220, Tue Nov 17 15:53:49 2015 +0000, Issue #2617224 by Wim Leers: Move around/fix some documentation. 2015-11-17 16:48:54 -08:00
ApcUniversalClassLoader.php Update to Drupal 8.0-dev-2015-11-17. Commits through da81cd220, Tue Nov 17 15:53:49 2015 +0000, Issue #2617224 by Wim Leers: Move around/fix some documentation. 2015-11-17 16:48:54 -08:00
CHANGELOG.md Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663 2015-10-08 15:13:01 -07:00
ClassCollectionLoader.php Update to Drupal 8.0-dev-2015-11-17. Commits through da81cd220, Tue Nov 17 15:53:49 2015 +0000, Issue #2617224 by Wim Leers: Move around/fix some documentation. 2015-11-17 16:48:54 -08:00
ClassLoader.php Update to Drupal 8.0-dev-2015-11-17. Commits through da81cd220, Tue Nov 17 15:53:49 2015 +0000, Issue #2617224 by Wim Leers: Move around/fix some documentation. 2015-11-17 16:48:54 -08:00
ClassMapGenerator.php Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663 2015-10-08 15:13:01 -07:00
composer.json Update to Drupal 8.0-dev-2015-11-17. Commits through da81cd220, Tue Nov 17 15:53:49 2015 +0000, Issue #2617224 by Wim Leers: Move around/fix some documentation. 2015-11-17 16:48:54 -08:00
DebugClassLoader.php Update to Drupal 8.0-dev-2015-11-17. Commits through da81cd220, Tue Nov 17 15:53:49 2015 +0000, Issue #2617224 by Wim Leers: Move around/fix some documentation. 2015-11-17 16:48:54 -08:00
DebugUniversalClassLoader.php Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663 2015-10-08 15:13:01 -07:00
LICENSE Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663 2015-10-08 15:13:01 -07:00
MapClassLoader.php Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663 2015-10-08 15:13:01 -07:00
phpunit.xml.dist Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663 2015-10-08 15:13:01 -07:00
Psr4ClassLoader.php Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663 2015-10-08 15:13:01 -07:00
README.md Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663 2015-10-08 15:13:01 -07:00
UniversalClassLoader.php Update to Drupal 8.0-dev-2015-11-17. Commits through da81cd220, Tue Nov 17 15:53:49 2015 +0000, Issue #2617224 by Wim Leers: Move around/fix some documentation. 2015-11-17 16:48:54 -08:00
WinCacheClassLoader.php Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663 2015-10-08 15:13:01 -07:00
XcacheClassLoader.php Update to Drupal 8.0-dev-2015-11-17. Commits through da81cd220, Tue Nov 17 15:53:49 2015 +0000, Issue #2617224 by Wim Leers: Move around/fix some documentation. 2015-11-17 16:48:54 -08:00

ClassLoader Component

ClassLoader loads your project classes automatically if they follow some standard PHP conventions.

The ClassLoader object is able to autoload classes that implement the PSR-0 standard or the PEAR naming convention.

First, register the autoloader:

require_once __DIR__.'/src/Symfony/Component/ClassLoader/ClassLoader.php';

use Symfony\Component\ClassLoader\ClassLoader;

$loader = new ClassLoader();
$loader->register();

Then, register some namespaces with the addPrefix() method:

$loader->addPrefix('Symfony', __DIR__.'/src');
$loader->addPrefix('Monolog', __DIR__.'/vendor/monolog/src');

The addPrefix() method takes a namespace prefix and a path where to look for the classes as arguments.

You can also register a sub-namespaces:

$loader->addPrefix('Doctrine\\Common', __DIR__.'/vendor/doctrine-common/lib');

The order of registration is significant and the first registered namespace takes precedence over later registered one.

You can also register more than one path for a given namespace:

$loader->addPrefix('Symfony', array(__DIR__.'/src', __DIR__.'/symfony/src'));

Alternatively, you can use the addPrefixes() method to register more than one namespace at once:

$loader->addPrefixes(array(
    'Symfony' => array(__DIR__.'/src', __DIR__.'/symfony/src'),
    'Doctrine\\Common' => __DIR__.'/vendor/doctrine-common/lib',
    'Doctrine' => __DIR__.'/vendor/doctrine/lib',
    'Monolog' => __DIR__.'/vendor/monolog/src',
));

For better performance, you can use the APC class loader:

require_once __DIR__.'/src/Symfony/Component/ClassLoader/ClassLoader.php';
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ApcClassLoader.php';

use Symfony\Component\ClassLoader\ClassLoader;
use Symfony\Component\ClassLoader\ApcClassLoader;

$loader = new ClassLoader();
$loader->addPrefix('Symfony', __DIR__.'/src');

$loader = new ApcClassLoader('apc.prefix.', $loader);
$loader->register();

Furthermore, the component provides tools to aggregate classes into a single file, which is especially useful to improve performance on servers that do not provide byte caches.

Resources

You can run the unit tests with the following command:

$ cd path/to/Symfony/Component/ClassLoader/
$ composer install
$ phpunit