Dynamically Loading Plugins
| From: | Todd Nine | Date: | Sat, 22 Oct 2005 22:56:24 +0000 |
| Subject: | Dynamically Loading Plugins | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-224469@lists.php.net to get a copy of this message | ||
Hi all.
I have need to dynamically load some classes. I have created an
abstract class that defines a function. Note that I'm using PHP 4 so
abstract is not enforced. 3rd party plugins will then implement this
interface. Users will upload their plugins via a web interface. After
I save the php class file to the directory ./plugins, I will need to
load it later. Basically I need to do something like.
$dir = dir("plugins");
while($entry=$dir->read() ) {
//skip non class php files.
if(!eregi(".+\.class\.php$", $entry )) {
continue;
}//end if
//dynamically load class and call it
//require class
require_once("plugins/".$entry);
//get the class name from the entry
$classname = ??? ?;
$plugin = new $classname();
//result array
$results = $plugin->getObjects();
//do other stuff
}//end while