systemAutoload

Handles class autoloading and location. This class can be registered with either __autoload or spl_autoload_register. It is preferable to use the spl function.

The autoload system works by de-constructing the classname and attempting to match it to an autoload file in the /libraries/autoload folder. This autoload file is simply an associative array of classname => location relative to /libraries. If the class location is already in the internal array of locations it will be immediately included without any further lookups required.

The autoload file is located by breaking apart the class name using either the camel case breaks e.g. dbManager would first be checked on dbmanager and then just db; or PEAR / ZF style and splitting on the underscore (_) e.g. Db_Manager dbmanager / db. Note that all autoload cache files are lowercase.

If the class cannot be found in any of the cache files in any of the registered paths, the autoloader will fall back to trying to map the class components to a file structure. e.g. dbManager would attempt to be loaded from first:

%path%/db/Manager.(class.)php and then %path%/db/manage.(class.)php

Db_Manager would be loaded from: %path%/Db/Manager.(class.)php

Both .class.php and .php are used as extensions.

The autoload files should be based on the class name and split into groups. The adopted standard is similar to ez Components e.g.: all system classes can be loaded from system_autoload.php.

The autoload cache file should return an array of all classes and locations that it contains:

// example cache file
return array(
    'myClass' => 'my/class.class.php',
    'myOtherClass' => 'my/other.class.php',
);

The autoloader is automatically registered by including system.inc. Otherwise you can implement your own autoloader based on this.

Further paths can be added to the autoloader by calling systemAutoload::addPath() and giving the location of the class folder. This should be a full path to the folder and the folder should contain a sub-folder called "autoload". The autoload sub-folder is where the autoload cache files will be read from.

systemAutoload will cache the resolved class paths as they are loaded and used. This removes the need to have to cycle through the assigned paths looking for classes and can improve performance.


Methods

private __construct()

Returns instance of systemAutoload

public static getInstance()

Returns the single instance of systemAutoload

public static autoload($inClassname)

Static autoload method

public static getClassPaths()

Returns the array of paths to search for classes in

public static addPath($inPath)

Add a path to search for classes in

public static setClassPaths([$inClassPaths = array()])

Set $_ClassPaths to $inClassPaths

public static removePath($inPath)

Removes the path from the set of class locations

public static convertCapitalizedString($inString, [$inSeparator = ' '])

Returns a string from "SomethingLikeThis" into "Something Like This"

public static cleanPath($inPath)

Cleans the tailing slash off the path

public static cleanDirSlashes($inPath)

Replaces directory slashes with the system set directory separator

public loadClass($inClassname)

Attempts to autoload the class named $inClassname

protected _fallback($inClassname, $inClassPath)

Attempts to load the specified class without using an autoload cache file

protected _includeFile($inClassname, $inClassPath, [$isAutoloadFile = false])

File include wrapper, returns true on success, else throws exceptions

protected _includeOnce($inFile)

Includes the file $inFile

protected _getBasePath($inClassname, $inClassPath)

Returns the full path to the specified file, or throws an exception if it cannot be found

public load()

Loads the previously cached autoload map

public save()

Saves the autoload cache to the filesystem

public delete()

Deletes the cache record

private getCacheFile()

Returns the full path to the autoload cache file

public isModified()

Returns true if object has been modified

public setModified([$status = true])

Set the status of the object if it has been changed

public getClasses()

Returns the entire autoload array

public countClasses()

Returns total number of classes in autoload system

public getClassFile($inClassname)

Returns the file path for $inClassname

public setClassFile($inClassname, $inClasspath)

Sets the class path for $inClassname

public getResolvedClasses()

Returns $_ResolvedClasses

public addResolvedClass($inClassname, $inClassPath)

Add fully resolved class path

public setResolvedClasses($inResolvedClasses)

Set $_ResolvedClasses to $inResolvedClasses

<  1  >