Source for file mvblog_autoloader.php
Documentation is available at mvblog_autoloader.php
* MvBlog -- An open source no-nosense blogtool
* Copyright (C) 2005-2006, Michiel van Baak
* Michiel van Baak <mvanbaak@users.sourceforge.net>
* See http://dev.mvblog.org for more information on MvBlog.
* That page also provides Bugtrackers, Filereleases etc.
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
* @copyright 2005-2006 Ferry Boender
* AutoLoader class handles auto loading of classes/objects.
* require_once("mvblog_AutoLoader.php");
* $mvblog_AutoLoader = new mvblog_AutoLoader();
* // Add the directory in which the current file resides to the autoloader.
* $pathInfo = pathinfo(__FILE__);
* $mvblog_AutoLoader->registerPath($pathInfo["dirname"]);
* // Register the AutoLoader object as the autoloader.
* function __autoload($className) {
* global $mvblog_AutoLoader;
* $mvblog_AutoLoader->autoload($className);
* Create a new mvblog_AutoLoader object. It will automatically parse
* your PHP ini include_path for paths in which is should look
* for objects. The default format it will look for is "CLASSNAME.php"
* (case-sensitive). The current directory is usually included in
* your include_path, so you won't have to add that. Add new
* paths using ->registerPath($path, $format).
* @param array $paths (optional) An array containing paths and formats. Each element in $paths is an associative array with "path", "format" and "options" keys. I.e. new mvblog_AutoLoader(array(array("path"=>"/usr/share/lib/app", "format" => "class_%s.php", "options" => mvblog_AutoLoader::OPT_LOWERCASE)));
// Add paths in include_path ini setting of PHP.
$phpIncludePath =
ini_get("include_path");
foreach (explode(':', $phpIncludePath) as $path) {
// Add user-defined paths
foreach($paths as $path) {
* Add a new path to the list of paths where mvblog_AutoLoader will look for classes.
* @param string $path The path. This will be automatically expanded to an absolute pathname (i.e. ../../foo will become /var/www/foo/, depending on your current path).
* @param string $format (optional) The format of filenames to look for. %s will be expanded to the classname that needs to be loaded. Example: "class_%s.php".
* @return bool false if path is not a dir or not set.
public function registerPath($path, $format =
"%s.php", $options =
0) {
if ($path ===
false ||
!is_dir($path))
$pathInfo =
array("path" =>
$path, "format" =>
$format, "options" =>
$options);
$this->paths[] =
$pathInfo;
* The autoloader. It looks through all the paths and tries to find a file that contains the class to include.
* This method should be called from an __autoload() function in your initializing code.
* @param string className. The name of the class to load.
foreach($this->paths as $path) {
$finalClassName =
$className;
$filename =
$path["path"] .
'/' .
sprintf($path["format"], $finalClassName);
Documentation generated on Fri, 28 Dec 2007 13:17:38 +0100 by phpDocumentor 1.4.1