The autoloader code is available in t3lib/class.t3lib_autoloader.php.
- TYPO3 4.3
- TYPO3 4.6
- Creating an ext_autoload.php file
- Determine extension name from class name
- Load extension's ext_autoload.php file
- Load file for class as described in ext_autoload.php
Extension name calculation
In short: The lowercased second part of the class name needs to equal the extension name without "_".
Example: Class Tx_BlogExample_Controller_BlogController belongs to extension blog_example, because a lowercased BlogExample equals blog_example without underscores.
Note that the mapping only works for activated extensions.
The code that does this is in t3lib_extmgm::getExtensionKeyByPrefix() and t3lib_autoloader::attemptToLoadRegistryForGivenClassName()
This file defines a mapping of class names to file paths. Every single class needs to be listed in the mapping array; wildcards are not possible. Class names need to be lowercase.
<?php $extPath = t3lib_extMgm::extPath('nr_semantic_annotations'); $srcPath = $extPath . 'src/NR/SemanticAnnotations/'; $prefix = 'nr_semanticannotations_'; return array( $prefix . 'config' => $srcPath . 'Config.php', $prefix . 'config_tables' => $srcPath . 'Config/Tables.php', $prefix . 'exception' => $srcPath . 'Exception.php', $prefix . 'helper_typo' => $srcPath . 'Helper/Typo.php', ); ?>
Updating the file will have immediate effect, at least up to TYPO3 4.5.
The file does not need to be registered anywhere. TYPO3 just finds it by its name.
- Class mapping information gets cached
- ext_autoload.php for each active extension is loaded unconditionally on startup
- Files for extbase-style class names are loaded automatically without an explicit mapping in ext_autoload.php.
TYPO3 will not notice if you change ext_autoload.php, because it caches the class-to-filename mapping now.
Either clear the cache in the TYPO3 backend, or just do the following in your shell:
$ rm typo3temp/Cache/Code/cache_phpcode/*
Previously, an extension's ext_autoload.php file was only loaded if a class was requested that got mapped to the extension. With 4.6, each active's extension autoload file gets loaded automatically when the autoloader is initialized.
This means that now you can use arbitrary class names that have no connection to the extension name at all.
Extbase class loading
Quick reminder: A class Tx_BlogExample_Controller_DefaultController has its file in blog_example/Classes/Controller/DefaultController.php.
Creating an ext_autoload.php file
No autoload file
When you're on TYPO3 4.6 upwards and follow the extbase class naming conventions, you do not need an ext_autoload.php file. The autoloader's magic will find them.
If you have only a couple of classes, creating the autoload file manually is an option.
extbase extension utility
Somewhere in your code add the following lines. Use them only if you need them, not permanently.
<?php Tx_Extbase_Utility_Extension::createAutoloadRegistryForExtension( $extensionKey, t3lib_extMgm::extPath($extensionKey) ); ?>
Note that this works for all kinds of classes and filenames, not only extbase styled ones.
Extension Development Evaluator
It only registers classes whose name begins with tx_extensionname, Tx_extensionname or user_extensionname - all others are ignored.