Ferreteria/v0.5/@cls/tExecutableTwig/DoLocalMethod()

From Woozle Writes Code
Jump to navigation Jump to search
ferret\layout\tExecutableTwig->DoLocalMethod()

About

This method determines what local method to call for the received event-type by checking the Code against known types. Podling classes can override it to add support for additional event-types. (tRenderableTwig does this for OnRender().)

Changes

2022-11-29

This method was originally created to handle the automatic dispatch of events by calling whatever method was specified by caEvent::Method. Although this methodology is kind of clever, and reduces a bit of code complexity, I'm discovering that it leads to coding confusion because of making it more difficult to figure out where the event-methods are called and initially defined. (It also may pose an obstacle for porting Ferreteria to other languages, especially those that are compiled rather than interpreted.)

I'm now converting this to just dispatch via explicit switch/case, and allowing podling classes to override it (removing final) to add support for additional event-types.

Method code was:

    final protected function DoLocalMethod(caEvent $oe) : void {
        $sMeth = $oe->Method();
            
        // +DEBUG
        
        #$oc = new F\cClassWrapper($this);
        #$sc = get_called_class();
        #$om = $oc->GetMethod($sMeth);
        #$ftMeth = $om->RenderFunc();
        #echo " &gt; DISPATCH <b>[$sc::$ftMeth]</b><br>";
        
        // -DEBUG
        
        $this->$sMeth($oe);
        $oe->DoCallback($this);  // do any requested callback
            
        // +DEBUG
        #echo " &lt; [$sc::$sMeth]<br>";
        // -DEBUG
            
    }