Project owner: creatics, Olaf Gleba 50939 Köln, Germany http://www.creatics.de
This file is licensed under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE v3 http://www.opensource.org/licenses/agpl-v3.html
object load(
string $token, [bool $args = array()])
|
|
Class loader
Common function to load a class. Takes the class name as first argument and returns the object. Makes it easier to change the functionality of a class.
How to modify a class
Let's say you like to modify a class named balance, especially their method add(). The first step is to create an empty file called my_balance.class.php. Then you create a new class that extends balance and add your own add() method:
Now you can change the loader for balance within load(). If the old loader looks like
case 'balance':
require_once('balance.class.php');
return balance::instance();the new loader for my_balance is
case 'balance': // <- leave this one alone!
require_once('my_balance.class.php');
return my_balance::instance();Now, every part of the application will invoke my_balance instead of balance.
PLEASE NOTE: ONLY MODIFY THE ORIGINAL CLASSES IF IT'S IMPOSSIBLE TO AVOID THAT. AND IF YOU DO THAT, CREATE A PATCH (diff -Naur) SO THAT YOU CAN REPRODUCE THE CHANGES AFTER AN UPDATE! IF YOU CREATE A FORK YOU'LL END IN HELL WHEN IT COMES TO AN UPDATE!
Parameters
| string |
$token |
Name of the class to load |
| bool |
$args |
Array of arguments to be passed to the singleton |