0

this question is strongly related to yesterdays one.

What I want to achieve: One perfectly object-oriented plugin-system in php where I can access the plugins this way:

$plugins->testplugin->dosomethingcool();

What I've got: With some help, I managed to solve first basic problems. The first problem, I thought about was, that with this structure, a non existant plugin would blow the whole system with a fatal error. So I have to handle these errors. So actually, I have this class:

<?php

    class pluginmanager {

        // Simplyfied everything here... 
        // Basically this class catches the fatal error for calling an object, that has not been defined

        public function __get($name) {
           if (!isset($this->$name)) {
               try{
                   throw new Exception(...);
               }
               catch(Exception $e){
                   // Do something with the exception
               }

               // Make sure to handle a "Call to member function a non-object"-error.
               // The object beneath will use __call() for the error catch.
               $this->$name= new DummyPlugin();
           }
           return $this->$name;
        }
    }

?>

Until now, that will work and allow me to have the object-based plugin-manager. I now realized, that for instance the possible plugin "blog" will have to use the other plugin "database-layer". Are there ways, to make this possible?

I already thought of:

  1. make the plugin-object globally available. Two concerns - 1) bad practice (not for no reasons...) and 2) not really safe and performance-oriented.
  2. make the plugin call a sub-plugin. This really is performance kill - but could it work?
  3. hooking-system or else: not sweet enough... ;-)

Couldn't I make a dependency-check after all the plugins are loaded and give each plugin a reference of all the plugins it relys on? Would this reference be a complete copy or would it stay a reference in the sense of the word?

Thanks for your thoughts!

4

0 回答 0