Advertisement
fruffl

AOP Test

Jan 13th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 KB | None | 0 0
  1.  
  2.     class Collection extends \ILLI\Core\Object
  3.     {
  4.         protected function prototypeMethod($data, $bar)
  5.         {
  6.             $data[] = 'Execute Proto-Method '.__METHOD__;
  7.             return compact('data', 'bar');
  8.         }
  9.        
  10.         public function method($data, $bar)
  11.         {
  12.             $data[] = 'Execute Method '.__METHOD__;
  13.             return $this->prototype(__FUNCTION__, get_defined_vars());
  14.         }
  15.     }
  16.  
  17.     $test = new Collection([
  18.         '__proto' =>
  19.         [
  20.             'method' => function($data, $bar)
  21.             {
  22.                 $data[] = 'Execute Proto-Method '.__METHOD__;
  23.                 return compact('data', 'bar');
  24.             }
  25.         ],
  26.         '__method' =>
  27.         [
  28.             'methodx' => function($data, $bar)
  29.             {
  30.                 $data[] = 'Execute Method '.__METHOD__;
  31.                 return compact('data', 'bar');
  32.             }
  33.         ]
  34.     ]);
  35.    
  36.     $test->applyMethodFilter('method', function(array $params = [], \ILLI\Core\Filter $chain)
  37.     {
  38.         $params['data'][] = 'Starting filter';
  39.         $params = $chain->next($params, $chain);
  40.         $params['data'][] = 'Ending filter';
  41.         return $params;
  42.     });
  43.    
  44.     $test->applyMethodFilter('method', function(array $params = [], \ILLI\Core\Filter $chain)
  45.     {
  46.         $params['data'][] = 'Starting inner filter';
  47.         $params = $chain->next($params, $chain);
  48.         $params['data'][] = 'Ending inner filter';
  49.         return $params;
  50.     });
  51.    
  52.     $result = $test->method(['Starting test'], 'Hello World');
  53.  
  54.  
  55.  
  56.  
  57. /*
  58. array(1) {
  59.   ["result"]=>
  60.   array(2) {
  61.     ["data"]=>
  62.     array(7) {
  63.       [0]=>
  64.       string(13) "Starting test"
  65.       [1]=>
  66.       string(38) "Execute Method root\Collection::method"
  67.       [2]=>
  68.       string(15) "Starting filter"
  69.       [3]=>
  70.       string(21) "Starting inner filter"
  71.       [4]=>
  72.       string(35) "Execute Proto-Method root\{closure}"
  73.       [5]=>
  74.       string(19) "Ending inner filter"
  75.       [6]=>
  76.       string(13) "Ending filter"
  77.     }
  78.     ["bar"]=>
  79.     string(11) "Hello World"
  80.   }
  81. }
  82. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement