ClassLoader

From Cloudrexx Development Wiki
Jump to: navigation, search

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))).

    Core files

  1. ASCMS_CORE_PATH . '/' . $className . '.class.php'
  2. Lib files

  3. ASCMS_LIBRARY_PATH . '/' . $className . '.php'
  4. /lib/FRAMEWORK/User

  5. ASCMS_FRAMEWORK_PATH . '/User/' . $className . '.class.php'
  6. /lib/FRAMEWORK

  7. ASCMS_FRAMEWORK_PATH . '/' . preg_replace('/FW/', , $className) . '.class.php'
  8. PEAR

  9. ASCMS_LIBRARY_PATH . '/PEAR/' . preg_replace('/_/', '/', preg_replace('/PEAR\//', , $className . '/')) . end(preg_split('/_/', $className)) . '.php'
  10. Model

  11. ASCMS_MODEL_PATH . '/entities/Cx/Model/Base/' . $className . '.php'
  12. Module index files

  13. ASCMS_CORE_MODULE_PATH . '/' . strtolower($className) . ($frontend ? '/index.class.php' : '/admin.class.php')
  14. ASCMS_MODULE_PATH . '/' . strtolower($className) . ($frontend ? '/index.class.php' : '/admin.class.php')
  15. Module main libraries

  16. ASCMS_CORE_MODULE_PATH . '/' . $moduleName . '/lib/' . $moduleName . 'Lib.class.php'
  17. ASCMS_CORE_MODULE_PATH . '/' . $moduleName . '/lib/Lib.class.php'
  18. ASCMS_CORE_MODULE_PATH . '/' . $moduleName . '/lib/lib.class.php'
  19. ASCMS_CORE_MODULE_PATH . '/' . $moduleName . '/Lib.class.php'
  20. ASCMS_MODULE_PATH . '/' . $moduleName . '/lib/' . $moduleName . 'Lib.class.php'
  21. ASCMS_MODULE_PATH . '/' . $moduleName . '/lib/Lib.class.php'
  22. ASCMS_MODULE_PATH . '/' . $moduleName . '/lib/lib.class.php'
  23. ASCMS_MODULE_PATH . '/' . $moduleName . '/Lib.class.php'
  24. Module model (files in (core_)modules/{moduleName}/lib

  25. ASCMS_CORE_MODULE_PATH . '/' . current(preg_split('/[A-Z]/', lcfirst($className))) . '/lib/' . $className . '.class.php'
  26. ASCMS_CORE_MODULE_PATH . '/' . current(preg_split('/[A-Z]/', lcfirst($className))) . '/lib/' . substr($name, strlen(current(preg_split('/[A-Z]/', lcfirst($className)))) . '.class.php'
  27. 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'
  28. ASCMS_MODULE_PATH . '/' . current(preg_split('/[A-Z]/', lcfirst($className))) . '/lib/' . $className . '.class.php'
  29. ASCMS_MODULE_PATH . '/' . current(preg_split('/[A-Z]/', lcfirst($className))) . '/lib/' . substr($name, strlen(current(preg_split('/[A-Z]/', lcfirst($className)))) . '.class.php'
  30. ASCMS_MODULE_PATH . '/' . current(preg_split('/[A-Z]/', lcfirst($className))) . '/lib/' . strtolower(substr($name, strlen(current(preg_split('/[A-Z]/', lcfirst($className))))) . '.class.php'
  31. EXCEPTIONS

  32. ASCMS_MODULE_PATH . '/' . current(preg_split('/[A-Z]/', lcfirst($className))) . '/' . $className . '.class.php' Data module
  33. ASCMS_MODULE_PATH . '/shop/lib/' . $className . '.class.php' Shop
  34. ASCMS_FRAMEWORK_PATH . '/File/' . $className . '.class.php' FileSystem
  35. ASCMS_FRAMEWORK_PATH . '/cxjs/' . $className . '.class.php' CxJs
  36. ASCMS_FRAMEWORK_PATH . '/cxjs/' . $className . '.interface.php' CxJs
  37. ASCMS_FRAMEWORK_PATH . '/cxjs/i18n/' . preg_replace('/JQueryUiI18nProvider/', 'jQueryUi', $className) . '.class.php' CxJs

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:

Contrexx 3 ClassLoader (incl. LegacyClassLoader)