Overview of the action invocation system

Action specific pre- and post-methods

As you hopefully know by now an application using Ismo consists of a number of states each state containing some amount of actions, usually related in some way. (When I talk about actions I mean the action methods which are usually named exedFoo, execBar etc.) So one might have something like this:

            class App_States_Foo extends Ismo_Core_State_HTTP
            {
                function App_States_Foo()
                {
                    parent::Ismo_Core_States_HTTP();
                }
                
                function execBar()
                {
                    echo "In the bar state!";
                    return 'menu';
                }
                
                function execFoo()
                {
                    echo "In the foo state!";
                    return 'index';
                }
            }
        

When the action foo is called on the state foo 'In the foo state!' will be echoed to the screen. This makes sense I hope... after this the show method showIndex() is called, because the action returns the string 'index'.

But it might be useful in certain circumstances to do some kind of check or something before the execFoo() method is invoced. So there is is a "hook" that can be used, if a method named preExecFoo() exists it will be called before execFoo() is called (the same goes if there is a method named preExecBar() for the execBar() metod.) So let's add such a metod:

                function preExecFoo()
                {
                    echo "I'll be called before execFoo()";
                }
        

If the pre-method returns false the execution will stop after that method and it will not continue to the action method. So let's add something a bit more useful in the bar action method's pre-method.

                function preExecBar()
                {
                    // only let user's named steve access the bar action method
                    $user = $_SESSION['user'];
                    if (strcmp($user->name, 'steve') != 0)
                    {
                        return false;
                    }
                    
                    echo "Hello Steve! How are you?";
                }
        

If one wants to do something special after the action method has been executed one can implement a post-method. Like this:

                function postExecFoo()
                {
                    echo "I'll be called after execFoo()";
                }
        

and

                function postExecBar()
                {
                    echo "Goodbye Steve!";
                }
        

Global pre- and post-methods

There are also global (in a state-sense) pre- and post-methods. They are called preExec() and postExec(). The preExec() method is called before the action specific pre-method and the postExec() method is called last, after the action specific method.

                function preExec()
                {
                    echo "I'm called first!";
                }

                function postExec()
                {
                    echo "I'm called last!";
                }
        

Pre- and post-methods for show-methods

It works the same for the show-methods as for the action methods. One can have both show-method specific pre- and post-methods and "global" ones:

                function preShow($show)
                {
                    // $show is a string containing what was returned from the
                    // action
                    echo "I'm always called if a show-method is called";
                    echo " (the show method for " . $show . " is going to be called)";
                }

                function preShowIndex()
                {
                    // this one doesn't get a parameter because it's already
                    // obvious what was returned from the action
                    echo "I'm called before the showIndex() method";
                }

                function showIndex()
                {
                    echo "This is the showIndex() method";
                    return 'menu';
                }

                function postShowIndex()
                {
                    // this one doesn't get a parameter because it's already
                    // obvious what was returned from the action
                    echo "I'm called after the showIndex() method";
                }

                function preShowMenu()
                {
                    echo "I'm called before the showMenu()  method";
                }

                function showMenu()
                {
                    echo "I'm showing the magnificent menu";
                }

                function postShowMenu()
                {
                    echo "I'm called after the showMenu() method";
                }

                function postShow($show)
                {
                    // $show is a string containing what was returned from the
                    // action
                    echo "I'm call last, after all show methods have been called";
                }