Source for file Autoloader.php
Documentation is available at Autoloader.php
// /* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Stig Bakken <ssb@php.net> |
// +----------------------------------------------------------------------+
// $Id: Autoloader.php,v 1.11 2004/02/27 02:21:29 cellog Exp $
// die hard without ext/overload
die ("Rebuild PHP with the `overload' extension to use PEAR_Autoloader");
* This class is for objects where you want to separate the code for
* some methods into separate classes. This is useful if you have a
* class with not-frequently-used methods that contain lots of code
* that you would like to avoid always parsing.
* The PEAR_Autoloader class provides autoloading and aggregation.
* The autoloading lets you set up in which classes the separated
* methods are found. Aggregation is the technique used to import new
* methods, an instance of each class providing separated methods is
* stored and called every time the aggregated method is called.
class PEAR_Autoloader extends PEAR
* Map of methods and classes where they are defined
var $_autoload_map = array ();
* Map of methods and aggregate objects
var $_method_map = array ();
* Add one or more autoload entries.
* @param string $method which method to autoload
* @param string $classname (optional) which class to find the method in.
* If the $method parameter is an array, this
* parameter may be omitted (and will be ignored
* if not), and the $method parameter will be
* treated as an associative array with method
* names as keys and class names as values.
function addAutoload ($method, $classname = null )
$this->_autoload_map = array_merge($this->_autoload_map, $method);
$this->_autoload_map[strtolower($method)] = $classname;
* Remove an autoload entry.
* @param string $method which method to remove the autoload entry for
* @return bool TRUE if an entry was removed, FALSE if not
function removeAutoload ($method)
$ok = isset ($this->_autoload_map[$method]);
unset ($this->_autoload_map[$method]);
// {{{ addAggregateObject()
* Add an aggregate object to this object. If the specified class
* is not defined, loading it will be attempted following PEAR's
* file naming scheme. All the methods in the class will be
* aggregated, except private ones (name starting with an
* underscore) and constructors.
* @param string $classname what class to instantiate for the object.
function addAggregateObject ($classname)
$include_file = preg_replace('/[^a-z0-9]/i', '_', $classname);
include_once $include_file;
foreach ($methods as $method) {
// don't import priviate methods and constructors
if ($method{0 } != '_' && $method != $classname) {
$this->_method_map[$method] = $obj;
// {{{ removeAggregateObject()
* Remove an aggregate object.
* @param string $classname the class of the object to remove
* @return bool TRUE if an object was removed, FALSE if not
function removeAggregateObject ($classname)
reset($this->_method_map);
while (list ($method, $obj) = each($this->_method_map)) {
if (is_a($obj, $classname)) {
unset ($this->_method_map[$method]);
* Overloaded object call handler, called each time an
* undefined/aggregated method is invoked. This method repeats
* the call in the right aggregate object and passes on the return
* @param string $method which method that was called
* @param string $args An array of the parameters passed in the
* @return mixed The return value from the aggregated method, or a PEAR
* error if the called method was unknown.
function __call ($method, $args, &$retval)
if (empty ($this->_method_map[$method]) && isset ($this->_autoload_map[$method])) {
$this->addAggregateObject ($this->_autoload_map[$method]);
if (isset ($this->_method_map[$method])) {
overload ("PEAR_Autoloader");
Documentation generated on Mon, 11 Mar 2019 14:23:54 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|