ZenMagick 0.9.10


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

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

Constant Summary
final static str

DEFAULT_CLASS_PREFIX

Method Summary
void

__construct(string name, string prefix)

Create a new loader.

void

addPath(string path, string baseNamespace, boolean recursive)

Add a given path to the loaders path.

static array

findIncludes(string dir, string ext, boolean recursive, int 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.

array

getStatic()

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

void

getStats(bool 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, string baseNamespace, boolean recursive)

Scan the given path for PHP files.

void

setParent(mixed parent)

Set the parent loader.

Constant Detail

core\ZMLoader.php at line 56

DEFAULT_CLASS_PREFIX

public final static str DEFAULT_CLASS_PREFIX = 'ZM'

Method Detail

core\ZMLoader.php at line 73

__construct

public void __construct(string name, string prefix)

Create a new loader.

Parameters:
name - Optional class loader name.
prefix - Optional prefix to use; defaults to self::DEFAULT_CLASS_PREFIX.

core\ZMLoader.php at line 137

addPath

public void addPath(string path, string baseNamespace, boolean recursive)

Add a given path to the loaders path.

Parameters:
path - The path to add.
baseNamespace - Optional base namespace; default is an empty string for none.
recursive - Flag to indicate if the path should be scanned recursively.

core\ZMLoader.php at line 363

findIncludes

public static array findIncludes(string dir, string ext, boolean recursive, int 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 183

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 452

getStats

public void getStats(bool 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 self::DEFAULT_CLASS_PREFIX.
Returns:
The root loader.

core\ZMLoader.php at line 168

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 293

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 307

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 435

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 147

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 213

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 246

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 397

scan

protected array scan(string path, string baseNamespace, boolean recursive)

Scan the given path for PHP files.

Parameters:
path - The path to scan.
baseNamespace - Optional base namespace; default is an empty string for none.
recursive - Flag to indicate if the path should be scanned recursively.
Returns:
A file map for the given path.

core\ZMLoader.php at line 154

setParent

public void setParent(mixed parent)

Set the parent loader.


ZenMagick 0.9.10