Source for file Loader.class.php
Documentation is available at Loader.class.php
* Zikula Application Framework
* @copyright Robert Gasch
* @link http://www.zikula.org
* @version $Id: Loader.class.php 24342 2008-06-06 12:03:14Z markwest $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @author Robert Gasch rgasch@gmail.com
* @uses class utililty class (class loader)
* Load a file from the specified location in the pn file tree
* @param fileName The name of the file to load
* @param path The path prefix to use (optional) (default=null)
* @param exitOnError whether or not exit upon error (optional) (default=true)
* @param returnVar The variable to return from the sourced file (optional) (default=null)
* @return string The file which was loaded
function loadFile ($fileName, $path= null, $exitOnError= true, $returnVar= null)
return pn_exit ("Invalid file specification [$fileName] ...");
$file = "$path/$fileName";
return pn_exit ("Unable to load file [$fileName] ...");
* Load all files from the specified location in the pn file tree
* @param files An array of filenames to load
* @param path The path prefix to use (optional) (default='null')
* @param exitOnError whether or not exit upon error (optional) (default=true)
function loadAllFiles ($files, $path= null, $exitOnError= false)
* Return after the first successful file load. This corresponds to the
* default behaviour of loadFiles().
* @param files An array of filenames to load
* @param path The path prefix to use (optional) (default='null')
* @param exitOnError whether or not exit upon error (optional) (default=true)
function loadOneFile ($files, $path= null, $exitOnError= false)
* Load multiple files from the specified location in the pn file tree
* Note that in it's default invokation, this method exits after the
* first successful file load.
* @param files Array of filenames to load
* @param path The path prefix to use (optional) (default='null')
* @param all whether or not to load all files or exit upon 1st successful load (optional) (default=false)
* @param exitOnError whether or not exit upon error (optional) (default=true)
* @param returnVar The variable to return if $all==false (optional) (default=null)
function loadFiles ($files, $path= null, $all= false, $exitOnError= false, $returnVar= '')
return pn_exit ("Invalid file array specification ...");
foreach ($files as $file) {
if ($returnVar && !$all) {
* Load a class file from the specified location in the file tree
* @param className The class-basename to load
* @param classPath The path prefix to use (optional) (default='includes/pnobjlib')
* @param exitOnError whether or not exit upon error (optional) (default=true)
* @return string The file name which was loaded
function loadClass ($className, $classPath= 'includes/pnobjlib', $exitOnError= true)
return pn_exit ("Invalid class specification [$className] ...");
$classFile = $className . '.class.php';
$rc = Loader::loadFile ($classFile, "config/classes/$classPath", false);
* Load a PNObject extended class from the given module. The given class name is
* prefixed with 'PN' and underscores are removed to produce a proper class name.
* @param module The module to load from
* @param base_obj_type The base object type for which to load the class
* @param array If true, load the array class instead of the single-object class.
* @param exitOnError whether or not exit upon error (optional) (default=true)
* @param prefix Override parameter for the default PN prefix (default=PN)
* @return string The ClassName which was loaded from the file
function loadClassFromModule ($module, $base_obj_type, $array= false, $exitOnError= false, $prefix= 'PN')
return pn_exit ("Invalid module specification [$module] ...");
return pn_exit ("Invalid base_obj_type specification [$base_obj_type] ...");
$prefix = (string) $prefix;
if (strpos($base_obj_type,'_') !== false) {
while (($p= strpos($c,'_')) !== false) {
$class = $prefix . $class;
// prevent unncessary reloading
$classFiles[] = "config/classes/$module/{$class}.class.php";
$classFiles[] = "system/$module/classes/{$class}.class.php";
$classFiles[] = "modules/$module/classes/{$class}.class.php";
foreach ($classFiles as $classFile) {
return pn_exit ("Unable to load class [$classFile] ...");
* Load a PNObjectArray extended class from the given module. The given class name is
* prefixed with 'PN' and underscores are removed to produce a proper class name.
* @param module The module to load from
* @param base_obj_type The base object type for which to load the class
* @param exitOnError whether or not exit upon error (optional) (default=true)
* @param prefix Override parameter for the default PN prefix (default=PN)
* @return string The ClassName which was loaded from the file
* cache for results of includes
* done this was because min version is not PHP5
if (isset ($cache[$file])) {
* Internal include_once, considerably faster
* @return bool True if file was included - false if not found or included before.
return include_once($file);
// check if file has been included already
// if we manaed to include it, cache the result
* Internal require_once, considerably faster
return require_once($file);
// check if file has been included already
// if we manaed to include it, cache the result
|