ClassLoader
Contents
ClassLoader
In Contrexx 3.0 there are three classloaders, since 3.1 there are just two. They are trying to load classes consecutively which are not explicitly included (e.g. with require_once()). And they are trying to load them in the following order:
\Cx\Core\ClassLoader\ClassLoader
Contrexx's main class loader. It loads classes using the namespaces according to the namespace concept. If the class/the interface exists in the customizing directory, this one will be loaded.
\Cx\Core\ClassLoader\LegacyClassLoader
The legacy class loader loads "old" Contrexx classes, which don't have a correct namespace. Third party classes (e.g. PEAR) will be loaded with this class loader as well. This ClassLoader will disappear fairly long-term.
To find classes it uses a rash of rules, which covers a big part of the classes to find (see #Ruleset). If the correct class cannot be found, the LegacyClassLoader searches in the complete Contrexx for a matching file. In each case it is trying to load the classes from the customizing directory first.
If a class could be found, it is saved into /tmp/legacyClassCache.tmp. So only the first request will be slow, all other will be faster due to this cache.
Format errors in /tmp/legacyClassCache.tmp will result in a white page. If you will find a white page in Contrexx 3 perhaps the file is the reason for it. Please only edit this file manually if you know what you are doing!! It is a serialized array.
Ruleset
The LegacyClassLoader works with this rash of rules. It checks whether the file exists. $className is the name of the class to load. $frontend is true if the request is a frontend request or false if the request is a backend request. $moduleName is the result of the formula: preg_replace('/mediadirectory/', 'mediadir', strtolower(preg_replace('/Library/', , $className))).
- ASCMS_CORE_PATH . '/' . $className . '.class.php'
- ASCMS_LIBRARY_PATH . '/' . $className . '.php'
- ASCMS_FRAMEWORK_PATH . '/User/' . $className . '.class.php'
- ASCMS_FRAMEWORK_PATH . '/' . preg_replace('/FW/', , $className) . '.class.php'
- ASCMS_LIBRARY_PATH . '/PEAR/' . preg_replace('/_/', '/', preg_replace('/PEAR\//', , $className . '/')) . end(preg_split('/_/', $className)) . '.php'
- ASCMS_MODEL_PATH . '/entities/Cx/Model/Base/' . $className . '.php'
- ASCMS_CORE_MODULE_PATH . '/' . strtolower($className) . ($frontend ? '/index.class.php' : '/admin.class.php')
- ASCMS_MODULE_PATH . '/' . strtolower($className) . ($frontend ? '/index.class.php' : '/admin.class.php')
- ASCMS_CORE_MODULE_PATH . '/' . $moduleName . '/lib/' . $moduleName . 'Lib.class.php'
- ASCMS_CORE_MODULE_PATH . '/' . $moduleName . '/lib/Lib.class.php'
- ASCMS_CORE_MODULE_PATH . '/' . $moduleName . '/lib/lib.class.php'
- ASCMS_CORE_MODULE_PATH . '/' . $moduleName . '/Lib.class.php'
- ASCMS_MODULE_PATH . '/' . $moduleName . '/lib/' . $moduleName . 'Lib.class.php'
- ASCMS_MODULE_PATH . '/' . $moduleName . '/lib/Lib.class.php'
- ASCMS_MODULE_PATH . '/' . $moduleName . '/lib/lib.class.php'
- ASCMS_MODULE_PATH . '/' . $moduleName . '/Lib.class.php'
- ASCMS_CORE_MODULE_PATH . '/' . current(preg_split('/[A-Z]/', lcfirst($className))) . '/lib/' . $className . '.class.php'
- ASCMS_CORE_MODULE_PATH . '/' . current(preg_split('/[A-Z]/', lcfirst($className))) . '/lib/' . substr($name, strlen(current(preg_split('/[A-Z]/', lcfirst($className)))) . '.class.php'
- ASCMS_CORE_MODULE_PATH . '/' . current(preg_split('/[A-Z]/', lcfirst($className))) . '/lib/' . strtolower(substr($name, strlen(current(preg_split('/[A-Z]/', lcfirst($className))))) . '.class.php'
- ASCMS_MODULE_PATH . '/' . current(preg_split('/[A-Z]/', lcfirst($className))) . '/lib/' . $className . '.class.php'
- ASCMS_MODULE_PATH . '/' . current(preg_split('/[A-Z]/', lcfirst($className))) . '/lib/' . substr($name, strlen(current(preg_split('/[A-Z]/', lcfirst($className)))) . '.class.php'
- ASCMS_MODULE_PATH . '/' . current(preg_split('/[A-Z]/', lcfirst($className))) . '/lib/' . strtolower(substr($name, strlen(current(preg_split('/[A-Z]/', lcfirst($className))))) . '.class.php'
- ASCMS_MODULE_PATH . '/' . current(preg_split('/[A-Z]/', lcfirst($className))) . '/' . $className . '.class.php' Data module
- ASCMS_MODULE_PATH . '/shop/lib/' . $className . '.class.php' Shop
- ASCMS_FRAMEWORK_PATH . '/File/' . $className . '.class.php' FileSystem
- ASCMS_FRAMEWORK_PATH . '/cxjs/' . $className . '.class.php' CxJs
- ASCMS_FRAMEWORK_PATH . '/cxjs/' . $className . '.interface.php' CxJs
- ASCMS_FRAMEWORK_PATH . '/cxjs/i18n/' . preg_replace('/JQueryUiI18nProvider/', 'jQueryUi', $className) . '.class.php' CxJs
Core files
Lib files
/lib/FRAMEWORK/User
/lib/FRAMEWORK
PEAR
Model
Module index files
Module main libraries
Module model (files in (core_)modules/{moduleName}/lib
EXCEPTIONS
If no rule matches, so fallbackLoad() will be called (glob()).
\Cx\ClassLoader
The third ClassLoader is a customized version of the Doctrine ClassLoader. It loads the unadjusted Doctrine and Gedmo classes (adjusted classes are in /model folder, they have a correct namespace and will be loaded by \Cx\Core\ClassLoader\ClassLoader. Because it is using a similar process like \Cx\Core\ClassLoader\ClassLoader, it has been removed for Contrexx 3.1.
Customizings
See the customizing article for detailed information.
Because the class loaders \Cx\Core\ClassLoader\ClassLoader and \Cx\Core\ClassLoader\LegacyClassLoader are searching in the customizing directory first, the developer can copy files with consideration of the normal folder structure to the customizing directory. These classes will replace the normal classes automatically.
Overview
The following drawing shows an overview over the functionality of both ClassLoaders: