ZenMagick 0.9.8


org.zenmagick.core.ZMLoader
\core\ZMLoader.php at line 56

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:

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

Note2: Static methods operate all on the root loader.

Note3: Custom classes without prefix that extend prefixed classes must extend ZMObject in order to be recognized properly.

Author:
DerManoMann
Version:
$Id: ZMLoader.php 2787 2009-12-28 23:24:26Z dermanomann $

Field Summary
final str

CLASS_PREFIX

Constructor Summary

ZMLoader(string name)

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(string prefix)

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)

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

string

resolveClass(string name, string key)

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

protected array

scan(string path, boolean recursive)

Scan the given path for PHP files.

void

setParent(mixed parent)

Set the parent loader.

Field Detail

\core\ZMLoader.php at line 57

CLASS_PREFIX

public final str CLASS_PREFIX = 'ZM'

Constructor Detail

\core\ZMLoader.php at line 73

ZMLoader

public ZMLoader(string name)

Create a new loader.

Parameters:
name - Optional class loader name.

Method Detail

\core\ZMLoader.php at line 166

addGlobal

public void addGlobal(string filename)

Add a file to be loaded in global context.

Parameters:
filename - The file to load.

\core\ZMLoader.php at line 136

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.

\core\ZMLoader.php at line 376

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.

\core\ZMLoader.php at line 121

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.

\core\ZMLoader.php at line 106

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.

\core\ZMLoader.php at line 175

getGlobal

public void getGlobal(array List)

Get files to be loaded in global context.

Parameters:
List - of filenames.

\core\ZMLoader.php at line 204

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).

\core\ZMLoader.php at line 451

getStats

public void getStats(mixed all, all Optional)

Get loader stats.

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

\core\ZMLoader.php at line 92

instance

public static ZMLoader instance(string prefix)

Get the root loader.

Parameters:
prefix - Optional prefix to be used for class resolving; default is ZM.
Returns:
The root loader.

\core\ZMLoader.php at line 189

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.


\core\ZMLoader.php at line 307

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.

\core\ZMLoader.php at line 321

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.

\core\ZMLoader.php at line 434

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.

\core\ZMLoader.php at line 146

registerClass

public void registerClass(string clazz, string filename)

Manually register a class.

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

\core\ZMLoader.php at line 234

resolve

public static string resolve(string name)

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

Parameters:
name - The class name (without the ZM prefix).
Returns:
The resolved class name; this is either the given name, the ZenMagick default implementation or null.

\core\ZMLoader.php at line 267

resolveClass

public string resolveClass(string name, string key)

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

Parameters:
name - The class name (without the ZM prefix).
key - Optional key for the internal cache; default is null.
Returns:
The resolved class name; this is either the given name, the ZenMagick default implementation or null.

\core\ZMLoader.php at line 409

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.

\core\ZMLoader.php at line 153

setParent

public void setParent(mixed parent)

Set the parent loader.


ZenMagick 0.9.8