Advertisement
fruffl

AOP/Injectable Proto

Jan 15th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.30 KB | None | 0 0
  1.  
  2.     CLASS Dispatcher EXTENDS StaticObject
  3.     {
  4.         protected static function prototypeRun($request, $options)
  5.         {
  6.             $class  = get_called_class();
  7.             $params = compact('request', 'options');
  8.             $router = 'bla\blaz\Router';
  9.             $result = $router.'::process('.$request.')';
  10.            
  11.             //if (($result = $router::process($request)) instanceof Response)
  12.                 return $result;
  13.            
  14.             $params = $class::applyRules($result->params);
  15.  
  16.             if(!$params)
  17.                 throw new DispatchException('Could not route request.');
  18.            
  19.             $callable = $class::ctrl($result, $params, $options);
  20.             return $class::dispatch($callable, $result, $params);
  21.         }
  22.        
  23.         public static function run($request, array $options = array())
  24.         {
  25.             //$params = compact('request', 'options');
  26.             return static::prototype(__FUNCTION__, get_defined_vars());
  27.         }
  28.        
  29.         protected static function prototypeCtrl($request, $params, $options)
  30.         {
  31.             var_dump('_CALLABLE: void');
  32.             var_dump(func_get_args());
  33.         }
  34.        
  35.         protected static function ctrl($request, $params, $options)
  36.         {
  37.             return static::prototype(__FUNCTION__, get_defined_vars());
  38.         }
  39.        
  40.         protected static function prototypeDispatch($callable, $request, $params)
  41.         {
  42.             if(is_callable($callable))
  43.                 return $callable($request, $params);
  44.            
  45.             var_dump('_CALL');
  46.             var_dump(func_get_args());
  47.            
  48.             return 'lala';
  49.         }
  50.        
  51.         protected static function dispatch($callable, $request, $params)
  52.         {
  53.             return static::prototype(__FUNCTION__, get_defined_vars());
  54.         }
  55.     }
  56.  
  57.     CLASS StaticObject
  58.     {
  59.         public static function prototype($__function, array $__parameters = [])
  60.         {
  61.             $__class = get_called_class();
  62.            
  63.             if(isset($__parameters['this']))
  64.                 unset($__parameters['this']);
  65.            
  66.             if(TRUE === static::Core_StaticObject_tAdapter_exists($__function))
  67.                 return static::Core_StaticObject_tAdapter_emit($__function, $__parameters);
  68.            
  69.             $__parameters = static::Core_StaticObject_tFilter_emit($__function, 'PARAMS', $__parameters, ['return' => $__parameters]);
  70.            
  71.             static::Core_StaticObject_tSignal_emit($__function, 'PRE_EVENT', [$__parameters], ['return' => $__parameters]);
  72.            
  73.             $__result = static::Core_StaticObject_tMethodFacade_emit($__function, $__parameters, function(array $__params, Filter $__chain) use ($__class, $__function)
  74.             {
  75.                 $result = NULL;
  76.                
  77.                 if(TRUE === static::Core_StaticObject_tMethod_exists($__function))
  78.                 {
  79.                     $result = static::Core_StaticObject_tMethod_emit($__function, $__params);
  80.                 }
  81.                 else
  82.                 if(TRUE === static::Core_StaticObject_tMethodProto_exists($__function))
  83.                 {
  84.                     $result = static::Core_StaticObject_tMethodProto_emit($__function, $params);
  85.                 }
  86.                 else
  87.                 {
  88.                     $proto = 'prototype'.$__function;
  89.                
  90.                     if($proto === $__function)
  91.                     {
  92.                     }
  93.                     else
  94.                     if(method_exists($__class, $proto))
  95.                     {
  96.                         $result = static::Core_StaticObject_tInvoke_method('prototype'.$__function, $__params);
  97.                     }
  98.                 }
  99.                
  100.                 return $result;
  101.             });
  102.            
  103.             $__result = static::Core_StaticObject_tFilter_emit($__function, 'RETURN', $__result, ['return' => $__result]);
  104.            
  105.             static::Core_StaticObject_tObserver_emit($__function, [$__result, $__parameters]);
  106.             static::Core_StaticObject_tSignal_emit($__function, 'POST_EVENT',  [$__result, $__parameters], ['return' => $__result]);
  107.            
  108.             return $__result;
  109.         }
  110.  
  111.     ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement