Skip to content
dongbeta edited this page Jul 21, 2011 · 2 revisions

Autoloader

What is autoloader

Autoloading is a mechanism that eliminates the need to manually require dependencies within your PHP code. Using autoloading, you do not need to worry about where a class exists in your project. With well-defined autoloaders, you do not need to worry about where a class file is relative to the current class file; you simply use the class, and the autoloader will perform the file lookup. By extending Zend Framework Autoloader, Xoops Engine provides a customized autoloader.

How autoloader works

Once an autoloader has been defined, it "is automatically called in case you are trying to use a class or an interface which hasn't been defined yet."

Autoloaders in Xoops Engine

The autoloaders in Xoops Engine are:

  • Kernel\Loader\ClassMapAutoloader::autoload()
  • Kernel\Loader\StandardAutoloader::autoload()
  • Kernel\Loader\Autoloader::dispatch()
  • smartyAutoload()

They will be called in turns.

ClassMapAutoloader

ClassMapAutoloader is the first autoloader class be called. It can loads these classes:

  • Kernel\EngineInterface
  • Kernel\HostInterface
  • Kernel\Persist
  • Kernel\Service
  • Debug

StandardAutoloader

StandardAutoloader can load classes with one of these prefixs or namespaces:

  • Kernel
  • Engine
  • Xoops
  • App
  • Module
  • Applet

If the prefix is not in the above, the StandardAutoloader will call it use fallback auloader. For example, the class name Zend_Acl_Role will be transformed as filename XoopsEngin/lib/Zend/Acl/Role.php.

Kernel Autoloader

Kernel\Loader\Autoloader is actually not a autoloader, it just setup and configurate ClassMapAutoloader and StandardAutoloader in Xoops Engine. The fallbackAutoloaderFlag of StandardAutoloader is be opened in Kernel\Loader\Autoloader.

smartyAutoload

smartyAutoload is a function. It is used for the smarty library in Xoops Engine.