4b53873d7a
* 2.5: fix typos [HttpKernel] add use statement for phpdoc fixed DateComparator if file does not exist Disabled the PHPUnit self-update on Travis fix mustRun() in sigchild environments [ClassLoader] simplified phpdoc [ClassLoader] Add a __call() method to XcacheClassLoader fix some minor typos in tests [Yaml] fixed mapping keys containing a quoted # Added fixture to test parsing of hash keys ending with a space and # [Validator] Pass strict argument into the strict email validator [Filesystem Component] mkdir race condition fix #11626 [Validator] reverted permissions change on translation files Fixed Factory services not within the ServiceReferenceGraph. [CssSelector] Fix URL to SimonSapin/cssselect repo [Validator] Fixed wrong translation keys/messages for Collection constraint. The error messages for a missing field and an unexpected field did not match the Contraint class Remove hard dependency of RequestContext in AssetsExtension added useful reminder about form.vars.errors into UPGRADE-2.5 notes [YAML] resolve variables in inlined YAML Disallow abstract definitions from doctrine event listener registration Conflicts: src/Symfony/Component/Yaml/Inline.php src/Symfony/Component/Yaml/Parser.php src/Symfony/Component/Yaml/Tests/InlineTest.php |
||
---|---|---|
.. | ||
Tests | ||
.gitignore | ||
ApcClassLoader.php | ||
ApcUniversalClassLoader.php | ||
CHANGELOG.md | ||
ClassCollectionLoader.php | ||
ClassLoader.php | ||
ClassMapGenerator.php | ||
composer.json | ||
DebugClassLoader.php | ||
DebugUniversalClassLoader.php | ||
LICENSE | ||
MapClassLoader.php | ||
phpunit.xml.dist | ||
Psr4ClassLoader.php | ||
README.md | ||
UniversalClassLoader.php | ||
WinCacheClassLoader.php | ||
XcacheClassLoader.php |
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:
$ cd path/to/Symfony/Component/ClassLoader/
$ composer.phar install
$ phpunit