Chapter 4. Module Programming

Table of Contents
Module Concepts
Common Variables

Module Concepts

Modules in PHP are based on the same basic principle as shared objects (.so or .dll) for C/C++. They are pieces of code which the main program can execute and draw information from, which do no have to be explicitly specified in the core of the program. phpwebtools implements this functionality by way of a superclass, PHP.module, and a listing and caching class, PHP.module_list.

Meta-Information

Modules have a great deal of information embedded in them, but drawing information from more than one module can be extremely processor-intensive, since all of the modules would have to be loaded to extract information.

The phpwebtools module_list (PHP.module_list) caches the modules' meta-information, so that it can be more easily retrieved. Due to the way that PHP.module stores its data, there are certain constants that a module stores in this cache by default. These are: PACKAGE_NAME, PACKAGE_VERSION, CATEGORY_NAME, CATEGORY_VERSION, MODULE_NAME, MODULE_VERSION, MODULE_AUTHOR, MODULE_VENDOR, MODULE_CLASS, MODULE_DESCRIPTION, MODULE_HIDDEN, PACKAGE_MINIMUM_VERSION, CATEGORY_MINIMUM_VERSION, DEPENDENCY, ICON, and META_INFORMATION.

META_INFORMATION is a catch-all which allows arbitrary information to be embedded in this cache. The module->SetMetaInformation(key, value) method allows this information to be set without having to manually manipulate META_INFORMATION.

Many of the variables, such as PACKAGE_NAME, PACKAGE_VERSION, CATEGORY_NAME, CATEGORY_VERSION, and MODULE_CLASS are set by the superclasses, and should not require setting by individual modules. Module constructors always call their parent class's constructor last, so as to properly create certain portions of the meta information and to properly run initialization routines.

Associations and Handlers

Associations are the ability to associate a module with another module, by its class name. This allows, for example, the Episode of Care module to have an unlimited amount of components, none of which have to be specified while programming the module which accesses them. (For example, if ProgressNotes and ScannedDocuments had been associated with EpisodeOfCare, EpisodeOfCare would not have to mention either of them in its code.)

Handlers are like associations, but are not tied to any specific module. Any portion of FreeMED can use handlers.

BaseModule, which all FreeMED modules are descended from, declares _GetAssociations () and _SetAssociation () to allow manipulation of associations. The FreeMED API has freemed::module_handler () to get the list of handlers, and BaseModule has _SetHandler() to allow adding of handlers.

For an example of associations, look at the Episode of Care module.

Hidden Modules

Setting MODULE_HIDDEN to true forces the module to not be listed or displayed anywhere, but allows it to still be executed. This is very useful when creating sub-functionality, or defining specific handlers.