All pastes #100068 Raw Edit

Anonymous

public php v1 · immutable
#100068 ·published 2006-07-25 20:54 UTC
rendered paste body
// Basic plugin structureabstract class PluginApi{    public function __construct()     {        // Register ourselves at Core        Core::getInstance()->registerPlugin($this);    }    /* Observer-Pattern */    abstract public function update();}// Some concrete pluginclass SuperPlugin extends PluginApi{    public function update()     {         // ...    }}new SuperPlugin();// Application coreclass Core{    private static $instance;    /* Constructor */    public function __construct()    {        self::$instance = $this;    }    /* Singleton pattern */    public static function getInstance()    {        if (! self::$instance) {            return new Core();        }        return self::$instance;    }    /* Init idiom */    private function init()    {    }    /* Observer-Pattern */    public function registerPlugin(& $pPlugin)     {        $this->plugins[] =& $pPlugin;    }    protected function notify()    {        foreach($this->plugins as $observer) {            $observer->update();        }    }}new Core();