New Classes for WBCE CMS,  1.4.1
Documentation for all new Classes in WBCE CMS
Static Public Member Functions | Static Public Attributes
WbAuto Class Reference

This is the main autoloader class in WBCE CMS More...

Static Public Member Functions

static Loader ($ClassName)
 The actual loader that is registered whith spl_autoload_register('WbAuto::Loader');. More...
 
static AddFile ($ClassName="", $ClassFile="", $Overwrite=false)
 Adds a single class <-> file combination to the autoload list. More...
 
static AddDir ($Dir="")
 Add a directory to be searched for matching class names/files. More...
 
static AddType ($Type)
 Adds a new search template to the list of search templates. More...
 

Static Public Attributes

static $Dirs =array()
 Stores the dirs to search in loader. More...
 
static $Files =array()
 Stores class filename combinations for loader. More...
 
static $Types
 Stores search templates to search for in the search dirs. More...
 

Detailed Description

This is the main autoloader class in WBCE CMS

Actually this is the only one too besides from the Twig autoloader which is moved to a module soon.

The autoloader is registry based , so all directories/files/patterns need to be registered somwhere in the CMS code. The registry allows Modules snipits Droplets and any other piece of code anywhere in WBCE to register its classes for further execution.

Here some examples for register actions, all path values are expected to be given from WB_PATH as the starting point.

// register a new directory to be searched
WbAuto::AddDir("/classes/");
WbAuto::AddDir("/classes/fields");
// register a single file, this allows for classname != filename
WbAuto::AddFile("MultiCrud","/classes/multicrud.php");
WbAuto::AddFile("R","/includes/rb.php");
// register additional search patterns for file search in directory %s is the classname.
WbAuto::AddType("class.%s.inc.php");

Everything is Global and can easyly be called from everywhere even the internal variables (for debugging if you like)

echo "<pre>"; print_r(WbAuto::$Dirs); echo "</pre>";
echo "<pre>"; print_r(WbAuto::$Files); echo "</pre>";
echo "<pre>"; print_r(WbAuto::$Types); echo "</pre>";
Attention
There is one very usefull thing to keep in mind
class_exists('MyClass');
triggers the autoloader, so it tests if the class is available and loads it.

Member Function Documentation

static Loader (   $ClassName)
static

The actual loader that is registered whith spl_autoload_register('WbAuto::Loader');.

This is the workhorse that does the actual loading.

static AddFile (   $ClassName = "",
  $ClassFile = "",
  $Overwrite = false 
)
static

Adds a single class <-> file combination to the autoload list.

These combinations allow for filename != clasname and are loaded first as it needs no directory searching. The path starts from WB_PATH. And it allows for overwrite of already existing entries.

WbAuto::AddFile("MultiCrud","/modules/multicrud/classes/multicrud.php");
WbAuto::AddFile("R","/classes/rb.php");
WbAuto::AddFile("R","/includes/rb.php", true);
Parameters
string$ClassNameThe actual name of the class to be loaded.
string$ClassFileThe path to the file to load for this class.
boolean$OverwriteSet to true already set entries are overwritten.
Return values
boolean/stringReturns false on success, and an error message on failure.
static AddDir (   $Dir = "")
static

Add a directory to be searched for matching class names/files.

Directories added here are searched for matching classfiles using patterns from the types array. The direcctory path starts from WB_PATH(webroot). The defautl patters in WB is class.classname.php all lowercase letters.

WbAuto::AddDir("/classes/");
WbAuto::AddDir("/modules/mymodule/classes/");
Parameters
string$DirThe path to the Directory to include starting from WB_PATH
Return values
boolean/stringReturns false on success, and an error message on failure.
static AddType (   $Type)
static

Adds a new search template to the list of search templates.

Templates are used to look for matching files in the directory search.

// %s is the classname.
WbAuto::AddType("class.%s.inc.php");
WbAuto::AddType("%s.php");
WbAuto::AddType("%s.class.php");
Parameters
string$TypeThe search pattern/template to add.
Return values
boolean/stringReturns false on success, and an error message on failure.

Field Documentation

array $Dirs =array()
static

Stores the dirs to search in loader.

array $Files =array()
static

Stores class filename combinations for loader.

array $Types
static
Initial value:
=array('class.%s.php',
'%s.class.php',
'%s.class.inc',
'%s.php',
'%s.inc',
'%s.inc.php',
'class.%s.inc')

Stores search templates to search for in the search dirs.


The documentation for this class was generated from the following file: