Assembla home | Assembla project page
 

Changeset 30

Show
Ignore:
Timestamp:
02/09/08 19:28:36 (10 months ago)
Author:
tobias382
Message:

* Added support to Command for optional arguments
* Modified JoinPart? to use the new Command enhancements

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Phergie/Event/Handler/Command.php

    r29 r30  
    3333                $cache['needs_event'] = false;  
    3434                foreach ($method->getParameters() as $key => $param) { 
    35                     if ($param->getClass()->getName() == 'Phergie_Event_Request') { 
     35                    $paramClass = $param->getClass(); 
     36                    if ($paramClass && $paramClass->getName() == 'Phergie_Event_Request') { 
    3637                        $cache['needs_event'] = true;  
    3738                        $cache['event_position'] = $key; 
     
    4647 
    4748        if ($method['exists']) { 
    48             $params = preg_split('/\s+/', $message, $method['num_args'] + 1);  
    49             array_shift($params); 
     49            $params = array_slice(preg_split('/\s+/', $message, $method['num_args'] + 1), 1); 
     50            $paramsCount = count($params); 
     51            if ($method['num_args'] > $paramsCount) { 
     52                $params += array_fill(0, $method['num_args'] - $paramsCount, null); 
     53            } 
    5054            if ($method['needs_event']) { 
    51                 array_splice($params, $method['event_position'], 0, array($event))
     55                $params[$method['event_position']] = $event
    5256            } 
    5357            if (count($params) == $method['num_args']) { 
  • trunk/Phergie/Event/Handler/JoinPart.php

    r24 r30  
    2222    * specified. 
    2323    * 
    24     * @param mixed $spec A string containing the name of the channel to part 
    25     *                    or an instance of Phergie_Event_Request for the  
    26     *                    original event that occurred 
     24    * @param string $channel Name of the channel to part (optional) 
     25    * @param Phergie_Event_Request $event Intercepted event 
    2726    */ 
    28     public function onDoPart($spec
     27    public function onDoPart($channel = null, Phergie_Event_Request $event
    2928    { 
    30         if ($spec instanceof Phergie_Event_Request) { 
    31             $this->doPart($spec->getArgument(0)); 
     29        if (empty($channel)) { 
     30            $this->doPart($event->getArgument(0)); 
    3231        } else { 
    33             $this->doPart($spec); 
     32            $this->doPart($channel); 
    3433        } 
    3534    }