ZenMagick 0.9.6


org.zenmagick.ZMLoader

Class ZMLoader

ZMLoader

public class ZMLoader

ZenMagick code/class loader.

Loader might be chained to allow delegation of theme loading. All loader implement a parent first strategy.

Classes in ZenMagick have to adhere to the following conventions:

Note: This is not as scalable as Java code and does not handle more than on level of inheritance.

Static methods operate all on the root loader.

Author:
DerManoMann
Version:
$Id: ZMLoader.php 2172 2009-04-22 00:19:36Z dermanomann $

Constructor Summary

ZMLoader()

Create a new loader.

Method Summary
void

addGlobal(string filename)

Add a file to be loaded in global context.

void

addPath(string path, boolean recursive)

Add a given path to the loaders path.

static array

findIncludes(string dir, string ext, boolean recursive, mixed level)

Scan (recursively) for .php files.

protected string

getClassFile(string name)

Get the class file for the given class name.

array

getClassPath(boolean includeParent)

Get the class path.

void

getGlobal(array List)

Get files to be loaded in global context.

array

getStatic()

Returns a list of all the static code in this loaders path.

void

getStats(mixed all, all Optional)

Get loader stats.

static ZMLoader

instance()

Get the root loader.

void

loadStatic()

Load all available static code.

static mixed

make(mixed args, string name, var arg)

Shortcut for creating new class instances.

protected mixed

makeClass(string name, var arg)

Resolve, load and instantiate a new instance of the given class.

static string

makeClassname(string filename)

Normalize class names based on the filename This is pretty much following Java conventions.

void

registerClass(string clazz, string filename)

Manually register a class.

static string

resolve(string name, mixed isAutoLoad, boolean isAutoload)

Shortcut version of ZMLoader::instance()->resolveClass($name).

string

resolveClass(string name, mixed isAutoLoad, boolean isAutoload)

Resolve and load the class code for the given class name.

private string

resolveFromClassPath(string name, mixed isAutoLoad, boolean isAutoload)

Resolve and load the class given.

protected array

scan(string path, boolean recursive)

Scan the given path for PHP files.

void

setParent(mixed parent)

Set the parent loader.

Constructor Detail

ZMLoader

public ZMLoader()

Create a new loader. /


Method Detail

addGlobal

public void addGlobal(string filename)

Add a file to be loaded in global context.

Parameters:
filename - The file to load.

addPath

public void addPath(string path, boolean recursive)

Add a given path to the loaders path.

Parameters:
path - The path to add.
recursive - Flag to indicate if the path should be scanned recursively.

findIncludes

public static array findIncludes(string dir, string ext, boolean recursive, mixed level)

Scan (recursively) for .php files.

It is worth mentioning that directories will always be processed only after all plain files in a directory are done.

Parameters:
dir - The name of the root directory to scan.
ext - Optional file suffix/extension; default is .php.
recursive - If true, scan recursively.
Returns:
List of full filenames of .php files.

getClassFile

protected string getClassFile(string name)

Get the class file for the given class name.

Parameters:
name - The class name without the ZM prefix.
Returns:
The class filename that or null.

getClassPath

public array getClassPath(boolean includeParent)

Get the class path.

Parameters:
includeParent - If true include the parent loader path: default is true.
Returns:
Class path array.

getGlobal

public void getGlobal(array List)

Get files to be loaded in global context.

Parameters:
List - of filenames.

getStatic

public array getStatic()

Returns a list of all the static code in this loaders path. Code is identified by a filename starting with a lower case character.

Note: This is an instance specific method. There is no delegation to a parent loader.

Returns:
Static files with local.php being the first (if it exists).

getStats

public void getStats(mixed all, all Optional)

Get loader stats.

Parameters:
Optional - parameter to indicate that stats of all loaders should be returned.

instance

public static ZMLoader instance()

Get the root loader.

Returns:
The root loader.

loadStatic

public void loadStatic()

Load all available static code.

Note: Using this is intended to load functions, defines, etc. As this is loaded inside a method, variables inside static files will not be real globals.

/


make

public static mixed make(mixed args, string name, var arg)

Shortcut for creating new class instances.

Please note that is it also possible to pass just a single parameter (array) that contains the class name (first element) and optionally constructor arguments (second, third,..).

Parameters:
name - The class name (without the ZM prefix).
arg - Optional constructor arguments.
Returns:
A new instance of the given class.

makeClass

protected mixed makeClass(string name, var arg)

Resolve, load and instantiate a new instance of the given class.

Parameters:
name - The class name (without the ZM prefix).
arg - Optional constructor arguments.
Returns:
A new instance of the given class.

makeClassname

public static string makeClassname(string filename)

Normalize class names based on the filename

This is pretty much following Java conventions.

Parameters:
filename - The filename.
Returns:
A corresponding class name.

registerClass

public void registerClass(string clazz, string filename)

Manually register a class.

Parameters:
clazz - The class name.
filename - The filename.

resolve

public static string resolve(string name, mixed isAutoLoad, boolean isAutoload)

Shortcut version of ZMLoader::instance()->resolveClass($name).

Parameters:
name - The class name (without the ZM prefix).
isAutoload - Optional boolean to indicate that this is an autoload call; default is false.
Returns:
The resolved class name; this is either the given name, the ZenMagick default * implementation or null.

resolveClass

public string resolveClass(string name, mixed isAutoLoad, boolean isAutoload)

Resolve and load the class code for the given class name.

Parameters:
name - The class name (without the ZM prefix).
isAutoload - Optional boolean to indicate that this is an autoload call; default is false.
Returns:
The resolved class name; this is either the given name, the ZenMagick default * implementation or null.

resolveFromClassPath

private string resolveFromClassPath(string name, mixed isAutoLoad, boolean isAutoload)

Resolve and load the class given.

Parameters:
name - The class name (without the ZM prefix).
isAutoload - Optional boolean to indicate that this is an autoload call; default is false.
Returns:
The resolved class name or null.

scan

protected array scan(string path, boolean recursive)

Scan the given path for PHP files.

Parameters:
path - The path to scan.
recursive - Flag to indicate if the path should be scanned recursively.
Returns:
A file map for the given path.

setParent

public void setParent(mixed parent)

Set the parent loader. /


ZenMagick 0.9.6