SwatObject
└─SwatAutoloader
public class SwatAutoloader
extends SwatObject
| Method Summary | |
|---|---|
| static void | addRule(string expression, string replacement, boolean last) Adds an autoloader rule to the autoloader. |
| static void | autoload(string class_name) Provides an opportunity to define a class before causing a fatal error when an undefined class is used. |
| static string | getFileFromClass(string class_name) Gets the filename of a class name. |
| static void | loadRules(string filename) Loads a list of autoloader rules from a file. |
| static void | Registers SwatAutoload::autoload() as an autoload function with the spl_autoload function. |
public static void addRule(string expression, string replacement, boolean last)
Adds an autoloader rule to the autoloader
expression - the class name expression. Uses PERL regular expression syntax.replacement - the format string of the filename for the class expression.last - whether or not the added rule is final or not.public static void autoload(string class_name)
Provides an opportunity to define a class before causing a fatal error when an undefined class is used
If an appropriate file exists for the given class name, it is required.
class_name - the name of the undefined class.public static string getFileFromClass(string class_name)
Gets the filename of a class name
This method uses the autoloader's list of rules to find an appropriate filename for a class name. This is used by PHP5's __autoload() method to find an appropriate file for undefined classes.
class_name - the name of the class to get the filename for.public static void loadRules(string filename)
Loads a list of autoloader rules from a file
This format of the file is as follows:
Each line defines a rule. The line is tokenized into fields based on whitespace characters (tab and space). The first field on the line is the rule expression. The next field on the line is the rule replacement. After the rule replacement field, there is an optional field to specify whether of not the rule is final. If this field is present and its value is 1, the rule is final. If the field is present and its value is 0 or if the field is omitted, the rule is not final. Lines beginning with a hash character (#) are ignored.
An example file containing two rules is:
<?php
/^Swat(.*)/ Swat/Swat$1.php
/^Swat(.*)?Exception$/ Swat/exceptions/Swat$1Exception.php 1
?>
filename - the name of the file from which to load the autoloader rules.public static void registerAutoload()
Registers SwatAutoload::autoload() as an autoload function with
the spl_autoload function
See documentation on SPL autoloading for details.
Automatically requires PHP files for undefined classes
This static class is responsible for resolving filenames from class names of undefined classes. The PHP5 spl_autoload function is used to load files based on rules defined in this static class.
To add a new autoloader rule, use the
SwatAutoloader::addRule()method.