PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
  Classes of David Bittencourt  >  phpPlugin  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: phpPlugin
Dynamically extend a PHP class using plug-ins
Author: By
Last change: Uptaded with "Force Reload"
Date: 14 years ago
Size: 1,084 bytes
 

Contents

Class file image Download
<?php

// Example file for phpPlugin

require "plugin.class.php";

// Class that will be extended with new plugins
class foo
{
    var
$good;
    function
foo($str='')
    {
       
$this->good = $str;
    }

}

// Plugin object that will manage all the plugin requests in this script
// The path to the plugins is set 'plugins/'
$plugin = new phpPlugin('plugins/');

// Class that will be extended with new plugins
$foo = new foo();

// Sets the filename format for the plugins 'foo'
// The plugin name will replace the character '?'
// The filename will be modified with the function 'strtolower' passed as parameter
$plugin->set_filename("?.func.php", "foo", "strtolower");

// Loads the plugin
// The filename must be 'plugins/func.bar.php'
$class = $plugin->load("bar", $foo, "foo");

// Try to load again
$newclass = $plugin->load("bar", $foo, "foo");

if(
$newclass==$class){
    print
"Already loaded."; // this will show up
}

// But you can force the script to reload the plugin and replace it
$newclass = $plugin->load("bar", $foo, "foo", true);

?>