Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Collection extends \ILLI\Core\Collection
- {
- protected function prototypeMethod($data, $bar)
- {
- return get_defined_vars();
- }
- public function method($data, $bar)
- {
- return $this->prototype(__FUNCTION__, get_defined_vars());
- }
- }
- $test = new Collection;
- $test->applyMethodFilter('method', function($self, $params, $chain)
- {
- $params['data'][] = 'Starting filter';
- $params = $chain->next($self, $params, $chain);
- $params['data'][] = 'Ending filter';
- return $params;
- });
- $test->applyMethodFilter('method', function(Collection $self, array $params = [], \ILLI\Core\Filter $chain)
- {
- $params['data'][] = 'Starting inner filter';
- $params = $chain->next($self, $params, $chain);
- $params['data'][] = 'Ending inner filter';
- return $params;
- });
- $result = $test->method(['Starting test'], 'Hello World');
- var_dump(compact('result'));
- array(1) {
- ["result"]=>
- array(2) {
- ["data"]=>
- array(8) {
- [0]=>
- string(13) "Starting test"
- [1]=>
- string(26) "Starting outer method call"
- [2]=>
- string(15) "Starting filter"
- [3]=>
- string(21) "Starting inner filter"
- [4]=>
- string(27) "Proto method implementation"
- [5]=>
- string(19) "Ending inner filter"
- [6]=>
- string(13) "Ending filter"
- [7]=>
- string(24) "Ending outer method call"
- }
- ["bar"]=>
- string(11) "Hello World"
- }
- }
- protected function prototype($__function, $__parameters)
- {
- if(isset($__parameters['this']))
- unset($__parameters['this']);
- $class = get_called_class();
- if(TRUE === $this->Core_Object_tAdapter_exists($class, $__function))
- return $this->Core_Object_tAdapter_emit($class, $__function, $__parameters);
- $this->Core_Object_tSignal_emit($class, $__function, 'PRE_EVENT', $__parameters);
- $data = $this->Core_Object_tFilter_emit($class, $__function, $__parameters, ['event' => 'DATA']);
- $result = NULL;
- $data['data'][] = 'Starting outer method call';
- $result = $this->Core_Object_tMethodFilter_emit(get_called_class(), $__function, $data, function($self, $params, $chain) use ($__function, &$data, &$result)
- {
- $params['data'][] = 'Proto method implementation';
- if(TRUE === $this->Core_Object_tMethod_exists($__function))
- {
- $result = $this->Core_Object_tMethod_emit($__function, $data);
- }
- else
- {
- $proto = $__function === '__construct'
- ? $this->__initConfig['__main']
- : $this->__initConfig['__protoprefix'].$__function;
- if($proto === $__function)
- throw new \Exception('Proto is called method '.$__function);
- if(method_exists($this, $proto))
- $result = $this->Core_Object_tInvoke_method($proto, $data);
- }
- return $params;
- });
- $result['data'][] = 'Ending outer method call';
- $result = [$result];
- $result = $this->Core_Object_tFilter_emit($class, $__function, $result, ['event' => 'RESULT']);
- $this->Core_Object_tObserver_emit($class, $__function, $result);
- $this->Core_Object_tSignal_emit($class, $__function, 'POST_EVENT', $result);
- return $result[0];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement