views:

31

answers:

2

This is a tricky one.

I am "emulating" ZF Bootstrapping (surface appearance). Don't ask me why, call it academic interest. So I have a Bootstrap Abstract with a method "run" that iterates over itself to locate any methods prefixed with "init".

The application looks for a user defined class which extends this class, in which the user can define any number of methods in this way. However, I want to prevent the user from being able to execute the "run" command of it's parent class, while still exposing the same command for the client code.

[edit] for clarity

class Bootstrap_Abstract{
    protected final function run(){
    // if method exists that starts 'init' - execute the method
    }

}

class Bootstrap extends Bootstrap_Abstract(){
    public function initSomething(){
    //do something
    }

    //PREVENT THIS
    public function initRun(){
        $this->run();
    }

}

//application code, not exposed to user - changes in behaviour require changes in this code directly
 class Application(){
     $Bootstrap = new Bootstrap();//load user bootstrap
     $Bootstrap->run();
 }

[/edit]

Anyone got any thoughts/advice/guidance? regards

SWK

+1  A: 

To determine "what" called a particular method, look into debug_backtrace

webbiedave
A: 

Post Script: the problem with my original code was an error in design. The responsibility for iterating through the Bootstrap methods should have been given to the invoking class, not the target class itself. I solved this problem by moving the function out to the invoker. Funny how obvious/simple refactoring is in hindsight...

sunwukung