Changeset 83

Show
Ignore:
Timestamp:
02/28/08 00:05:48 (5 years ago)
Author:
tobias382
Message:

Fixes #17
* Added named argument support to the request event class

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Phergie/Event/Request.php

    r60 r83  
    99{ 
    1010    /** 
    11     * Password message 
    12     * 
    13     * @const string 
    14     */ 
    15     const TYPE_PASS = 'pass'; 
    16  
    17     /** 
    1811    * Nick message 
    1912    * 
     
    2316 
    2417    /** 
    25     * User message 
    26     * 
    27     * @const string 
    28     */ 
    29     const TYPE_USER = 'user'; 
    30  
    31     /** 
    32     * Operator command 
    33     * 
    34     * @const string 
    35     */ 
    36     const TYPE_OPER = 'oper'; 
    37  
    38     /** 
    3918    * Quit command 
    4019    * 
     
    10584    */ 
    10685    const TYPE_ACTION = 'action'; 
     86 
     87    /** 
     88    * Mapping of event types to their named parameters  
     89    * 
     90    * @var array 
     91    */ 
     92    protected static $map = array 
     93    ( 
     94        self::TYPE_QUIT => array( 
     95            'message' => 0 
     96        ), 
     97 
     98        self::TYPE_JOIN => array( 
     99            'channel' => 0 
     100        ), 
     101         
     102        self::TYPE_KICK => array( 
     103            'channel' => 0, 
     104            'user'    => 1, 
     105            'comment' => 2 
     106        ), 
     107 
     108        self::TYPE_PART => array( 
     109            'channel' => 0 
     110        ), 
     111 
     112        self::TYPE_MODE => array( 
     113            'channel|nickname' => 0, 
     114            'mode'             => 1, 
     115            'limit'            => 2, 
     116            'user'             => 3, 
     117            'ban mask'         => 4 
     118        ), 
     119 
     120        self::TYPE_TOPIC => array( 
     121            'channel' => 0, 
     122            'topic'   => 1 
     123        ), 
     124 
     125        self::TYPE_PRIVMSG => array( 
     126            'receiver' => 0, 
     127            'text'     => 1 
     128        ), 
     129 
     130        self::TYPE_NOTICE => array( 
     131            'nickname' => 0, 
     132            'text'     => 1 
     133        ), 
     134             
     135        self::TYPE_ACTION => array( 
     136            'action' => 0 
     137        ) 
     138    ); 
    107139 
    108140    /** 
     
    270302        if (isset($this->arguments[$argument])) { 
    271303            return $this->arguments[$argument]; 
     304        } else { 
     305            $argument = strtolower($argument); 
     306            if (isset(self::$map[$this->type][$argument]) 
     307                && isset($this->arguments[self::$map[$this->type][$argument]])) { 
     308                echo 'returning ' . $this->arguments[self::$map[$this->type][$argument]] . "\n"; 
     309                return $this->arguments[self::$map[$this->type][$argument]]; 
     310            } 
    272311        } 
    273312        return null; 
     
    317356        return empty($this->username); 
    318357    } 
     358 
     359    /** 
     360    * Provides access to named parameters via virtual "getter" methods. 
     361    * 
     362    * @param string $name Name of the method called 
     363    * @param array $arguments Arguments passed to the method (should always  
     364    *                         be empty) 
     365    * @return mixed 
     366    */ 
     367    public function __call($name, array $arguments) 
     368    { 
     369        $index = strtolower(substr($name, 4)); 
     370        if (count($arguments) == 0 
     371            && substr($name, 0, 3) == 'get') { 
     372            return $this->getArgument(substr($name, 3));  
     373        } 
     374    } 
    319375}