Advertisement
fruffl

AOP Bootstrap

Jan 13th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.49 KB | None | 0 0
  1.  
  2.         /**
  3.          * allows you to replaace the core-function of a method without editing your class-file
  4.          *
  5.          * <code>
  6.          * function myMethod()
  7.          * {
  8.          *  // do additional stuff
  9.          *  $this->prototype('myMethod');
  10.          *  // do additional stuff
  11.          *  // return $whatever;
  12.          * }
  13.          * </code>
  14.          *
  15.          *  1.  adapter-lookup
  16.          *
  17.          *  2.1 send signal PRE_EVENT with unfiltered parameters
  18.          *  2.2 filter parameters
  19.          *  2.3 run method-filters
  20.          *  2.3.1   run outer-filters
  21.          *  2.3.2   execute virtual method
  22.          *  2.3.3   execute virtual proto or physical existing proto
  23.          *  2.4 filter result
  24.          *  2.5 observer notify with filtered result
  25.          *  2.6 send signal POST_EVENT with filtered result
  26.          *  2.7 return filtered result
  27.          */
  28.         protected function prototype($__function, $__parameters)
  29.         {
  30.             if(isset($__parameters['this']))
  31.                 unset($__parameters['this']);
  32.                
  33.             $class = get_called_class();
  34.             $function = $__function;
  35.            
  36.             if(TRUE === $this->Core_Object_tAdapter_exists($class, $function))
  37.                 return $this->Core_Object_tAdapter_emit($class, $function, $__parameters);
  38.            
  39.             $this->Core_Object_tSignal_emit($class, $function, 'PRE_EVENT', $__parameters);
  40.            
  41.             $data   = $this->Core_Object_tFilter_emit($class, $function, $__parameters, ['event' => 'DATA']);
  42.            
  43.             $result = $this->Core_Object_tMethodFilter_emit($class, $function, $data, function(array $__params) use ($function, $data)
  44.             {
  45.                 $result = NULL;
  46.                
  47.                 if(TRUE === $this->Core_Object_tMethod_exists($function))
  48.                 {
  49.                     $result = $__params = $this->Core_Object_tMethod_emit($function, $__params);
  50.                 }
  51.                
  52.                 if(TRUE === $this->Core_Object_tMethodProto_exists($function))
  53.                 {
  54.                     $result = $this->Core_Object_tMethodProto_emit($function, $__params);
  55.                 }
  56.                 else
  57.                 {
  58.                     $proto = $function === '__construct'
  59.                         ? $this->__initConfig['__main']
  60.                         : $this->__initConfig['__protoprefix'].$function;
  61.                
  62.                     if($proto === $function)
  63.                     {
  64.                         throw new \Exception('Proto is called method '.$function);
  65.                         return $__params;
  66.                     }
  67.                    
  68.                     if(method_exists($this, $proto))
  69.                         $result = $this->Core_Object_tInvoke_method($proto, $__params);
  70.                 }
  71.                
  72.                 return $result;
  73.             });
  74.            
  75.             $result = [$result];
  76.             $result = $this->Core_Object_tFilter_emit($class, $function, $result, ['event' => 'RESULT']);
  77.            
  78.             $this->Core_Object_tObserver_emit($class, $function, $result);
  79.             $this->Core_Object_tSignal_emit($class, $function, 'POST_EVENT', $result);
  80.            
  81.             return $result[0];
  82.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement