webCOMAND

io_comand\loader

The COMAND API auto-loader automatically loads API classes as they are referenced in PHP code.  It can be customized to look in custom folders, and also provides methods to load and modify configuration files, and other custom file types.

File Types

The loader will look for the following types of files by default.

  • API & Package Classes (auto) - API classes and other package classes are loaded from:
    • comand/packages/
  • Configurations (config) - Configuration files are loaded from:
    • comand/config/
  • Extensions (extension) - Extension classes are loaded from:
    • comand/extensions/

Folder Customization

The loader can be customized to look in different folders for each file type listed above.  The following types of folders dictate where the loader looks.

Folders

Folders are simple file system paths where the loader will look for files of a specific type.

Base Folders

A base folder serves as the parent folder for subfolders.  Specific subfolders will be checked under each base folder depending on the type of file that should be loaded.  For example, the loader will look in the config subfolder for config files by default.

Subfolders

A subfolder specifies where to check under each base folder, as described above.

Path Formats

If a path starts with a slash, it will be rooted at the top of the file system. If it does not start with a slash, it will be rooted in the top-level folder where comand.php is located.

Example

The following example customizes the loader to look in a different folder for API Classes.

require_once( 'packages/io_comand/loader.php' );

// look for auto-loading API and package classes in /classes folder
\io_comand\loader::add_folder( 'auto', '/classes/' );

// look for config files in cfg folder, under comand folder
\io_comand\loader::add_folder( 'config', 'cfg/' );

// look in subfolders of comand_app folder, at same level as comand.php
\io_comand\loader::add_base_path( '../comand_app/' );

// look for auto-loading API and package classes in classes subfolder
// of all base folders (ie. comand_app and parent folder of comand.php)
\io_comand\loader::add_subfolder( 'auto', 'classes/' );