drupal/core/vendor/Symfony/Component/ClassLoader
Dries 34ef955ae5 - Patch #1542710 by BTMash, Crell: update to latest Symfony 2.1 code. 2012-04-28 18:07:40 -04:00
..
Tests - Patch #1542710 by BTMash, Crell: update to latest Symfony 2.1 code. 2012-04-28 18:07:40 -04:00
ApcClassLoader.php - Patch #1542710 by BTMash, Crell: update to latest Symfony 2.1 code. 2012-04-28 18:07:40 -04:00
ApcUniversalClassLoader.php - Patch #1343160 by msonnabaum: update Symfony2 components to latest release. 2012-02-23 09:24:11 -05:00
ClassCollectionLoader.php - Patch #1542710 by BTMash, Crell: update to latest Symfony 2.1 code. 2012-04-28 18:07:40 -04:00
ClassLoader.php - Patch #1542710 by BTMash, Crell: update to latest Symfony 2.1 code. 2012-04-28 18:07:40 -04:00
ClassMapGenerator.php - Patch #1497182 by Crell, BTMash: Update to latest Symfony 2.1 code. This is commit c4dfe931f1ce8827f8c02975bc0ab405bdc8d27c out of Symfony. 2012-03-28 15:08:43 -04:00
DebugClassLoader.php - Patch #1542710 by BTMash, Crell: update to latest Symfony 2.1 code. 2012-04-28 18:07:40 -04:00
DebugUniversalClassLoader.php - Patch #1497182 by Crell, BTMash: Update to latest Symfony 2.1 code. This is commit c4dfe931f1ce8827f8c02975bc0ab405bdc8d27c out of Symfony. 2012-03-28 15:05:43 -04:00
LICENSE - Patch #1497182 by Crell, BTMash: Update to latest Symfony 2.1 code. This is commit c4dfe931f1ce8827f8c02975bc0ab405bdc8d27c out of Symfony. 2012-03-28 15:05:43 -04:00
MapClassLoader.php
README.md - Patch #1542710 by BTMash, Crell: update to latest Symfony 2.1 code. 2012-04-28 18:07:40 -04:00
UniversalClassLoader.php - Patch #1497182 by Crell, BTMash: Update to latest Symfony 2.1 code. This is commit c4dfe931f1ce8827f8c02975bc0ab405bdc8d27c out of Symfony. 2012-03-28 15:05:43 -04:00
XcacheClassLoader.php - Patch #1542710 by BTMash, Crell: update to latest Symfony 2.1 code. 2012-04-28 18:07:40 -04:00
composer.json - Patch #1497182 by Crell, BTMash: Update to latest Symfony 2.1 code. This is commit c4dfe931f1ce8827f8c02975bc0ab405bdc8d27c out of Symfony. 2012-03-28 15:05:43 -04:00
phpunit.xml.dist - Patch #1542710 by BTMash, Crell: update to latest Symfony 2.1 code. 2012-04-28 18:07:40 -04:00

README.md

ClassLoader Component

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

The Universal ClassLoader 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/UniversalClassLoader.php';

use Symfony\Component\ClassLoader\UniversalClassLoader;

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

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

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

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

You can also register a sub-namespaces:

$loader->registerNamespace('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->registerNamespace('Symfony', array(__DIR__.'/src', __DIR__.'/symfony/src'));

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

$loader->registerNamespaces(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 based version of the universal class loader:

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

use Symfony\Component\ClassLoader\ApcUniversalClassLoader;

$loader = new ApcUniversalClassLoader('apc.prefix.');

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:

phpunit -c src/Symfony/Component/ClassLoader/

If you also want to run the unit tests that depend on other Symfony Components, declare the following environment variables before running PHPUnit:

export SYMFONY_FINDER=../path/to/Finder