Dev:Class loader
From ZenMagick Wiki
What is the class loader
The class loader ZMLoader is the central piece of code responsible for locating and loading classes and other PHP resources like functions, settings, etc. In terms of the loader, all PHP code that is not a class is referred to as static code.
Static code is loaded right away, assuming that the files contain either functions (which can't be resolved at runtime) or constants, defines or other initial code.
Loader conventions
The most important task, however, is to load and instantiate classes. In order to to so, several conventions exist. ZenMagick, like many other applications, organizes PHP classes in separate files. In order for the loader to find the appropriate class, filenames have to match (case sensitive) the class name they contain.
One exception to this rule is the use of .class. in the filename as often done. Example: AProduct.class.php.
The second important convention is that class names do always start with upper case while static code starts with a lower case. For a more details please check the Dev:Naming_Convention.
Instantiating classes
There are several ways to create class instances in ZenMagick:
- PHP new
Using the new operator will work as expected. The loader is registered as SPL autoload handler and will be called automatically to resolve any unknown class name. - ZMLoader::make()
Similar to using new, with one important difference. Omitting the usual ZM prefix will allow the loader to look for custom implementations first and use the class with ZM prefix only as fallback. This is how core classes are overloaded.
Example: ZMLoader::make('Products'); First the loader will try to located a class named 'Products'. If that is not found, it wil look for a class named 'ZMProducts'. Since all core classes do have the 'ZM' prefix, this means if a custom 'Products' class exists, it will be used instead of the default implementation. Pretty much all instantiation within core code is done using this method to allow to replace almost all core classes by just providing alternative classes without the 'ZM' prefix.
- ZMBeanUtils::getBean(bean definition)
Bean definitions are strings describing objects. In some respects it is similar to serialized objects, however with the advantage of a simpler syntax. For more details please refer to the Dev::Beans documentation.

