Advertisement
fruffl

Signal reseiver

Jan 26th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1.  
  2.         protected function Core_Object_T_Signal_emit($__functionName, $__slotName, array $__parameters = [], array $__options = [])
  3.         {
  4.             $__options += ['return' => $__parameters, 'until' => null];
  5.            
  6.             if(FALSE === $this->Core_Object_T_Signal_exists($__functionName, $__slotName))
  7.                 return $__options['return'];
  8.            
  9.             $stack      = &$this->__Core_Object_T_Signal_registry[$__functionName][$__slotName];
  10.             $results    = &$this->__Core_Object_T_Signal_results[$__functionName][$__slotName];
  11.             $sender     = [$this, $__functionName, $__slotName];
  12.             $result     = $__parameters;
  13.            
  14.             foreach($stack as $slotPosition => $Delegate)
  15.             {
  16.                 if(!isset($Delegate[0]))
  17.                     continue;
  18.                    
  19.                 $last       = NULL;
  20.                 $resiverParams  = array_merge($sender, [$Delegate[1]], $__parameters);
  21.                 $interfaces = class_implements($Delegate[0]);
  22.                
  23.                 if($Delegate[0] === $this)
  24.                 {
  25.                     $last = $this->Core_Object_T_Invoke_method('Core_Object_T_Signal_reseive', $resiverParams);
  26.                 }
  27.                 else
  28.                 if((is_object($Delegate[0]) && $Delegate[0] instanceOf I_Signal)
  29.                 || (is_string($Delegate[0]) && isset($interfaces['ILLI\Core\StaticObject\I_Signal'])))
  30.                 {
  31.                     $last = Invoke::emit($Delegate[0], 'reseiveSignal', $resiverParams);
  32.                 }
  33.                 else
  34.                 {
  35.                     $last = isset($Delegate[1])
  36.                         ? Invoke::emit($Delegate[0], $Delegate[1], $resiverParams)
  37.                         : Invoke::emit($Delegate[0], $resiverParams);
  38.                 }
  39.                
  40.                 $results[$slotPosition] = $last;
  41.                
  42.                 if($last === I_Signal::T_SIGNAL_EMIT_STOP)
  43.                     break;
  44.                
  45.                 $result = $last;
  46.                
  47.                 if(is_callable($__options['until']))
  48.                 {
  49.                     if(TRUE === $__options['until']($result))
  50.                         break;
  51.                 }
  52.             }
  53.            
  54.             return $results;
  55.         }
  56.        
  57.         protected function Core_Object_T_Signal_reseive($__sender, $__senderFunctionName, $__senderSlotName, $__function, array $__parameters = [])
  58.         {
  59.             return is_string($__function)
  60.                 ? $this->Core_Object_T_Invoke_method($__function, $__parameters)
  61.                 : Invoke::emiT_Callable($__function, [$__sender, $__senderFunctionName, $__senderSlotName, $__parameters]);
  62.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement