SitePoint Sponsor

User Tag List

Results 1 to 25 of 76

Threaded View

  1. #14
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In fairness to Harry, I wanted to provide some code to show that I'm not just a critical bystander.
    PHP Code:
    <?php
    class EventMarshall
    {
        
    //Constructor
        
    function EventMarshall()
        {
            if(
    $_GET)  $this->trigger_get();
            if(
    $_POST$this->trigger_post();
            
            if(
    $_SERVER['PATH_INFO']) $this->trigger_path_info();
            
            
    // default page trigger
            
    if(function_exists('main')){
                
    main( &$this );
            }
        }
        function 
    trigger_get()
        {
            
    // GET trigger
            
    if(function_exists('on_get_value')){
                
    reset($_GET);
                while(list(
    $key,$value)=each($_GET)){
                    
    on_get_value( &$this$key$value );
                }
            }
            if(
    function_exists('on_get')){
                
    on_get(&$this$_GET);
            }
        }
        function 
    trigger_post()
        {
            
    // POST trigger
            
    if(function_exists('on_post_value')){
                
    reset($_POST);
                while(list(
    $key,$value)=each($_POST)){
                    
    on_post_value(&$this$key$value);
                }
            }
            if(
    function_exists('on_post')){
                
    on_post(&$this$_POST);
            }
        }
        function 
    trigger_path_info()
        {
            
    // PATH_INFO trigger
            
    $data explode('/'$_SERVER['PATH_INFO']);
            if(
    function_exists('on_path_data')){
                for(
    $i=0;$i<count($data);$i++){
                    if(
    $data[$i])
                        
    on_path_data(&$this$data[$i]);
                }
            }
        }
    }
    new 
    EventMarshall();
    ?>
    which could be implemented in the following manner...
    PHP Code:
    <?php

    require_once 'EventMarshall';

    function 
    on_path_data$sender$value ){
        switch(
    $value){
            case 
    'foo':
                print 
    '<b>foo</b> command issued.<br/>';
                break;
            default:
                
    printf('unrecognized command "%s" issued.<br/>'$value);
                break;
        }
    }
    function 
    on_get_value$sender$key$value ){
        
    printf('<b>%s</b> = %s<br/>'$key$value);
    }
    function 
    main$sender ){
        print 
    'hello world.<br/>';
    }

    ?>
    Last edited by randem; Oct 23, 2002 at 12:50.
    ----Adopt-a-Sig----
    Your message here!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •