filter.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. class Filter_Controller extends Controller {
  3. public function __construct()
  4. {
  5. Filter::register('test-all-before', function() { $_SERVER['test-all-before'] = true; });
  6. Filter::register('test-all-after', function() { $_SERVER['test-all-after'] = true; });
  7. Filter::register('test-profile-before', function() { $_SERVER['test-profile-before'] = true; });
  8. Filter::register('test-except', function() { $_SERVER['test-except'] = true; });
  9. Filter::register('test-on-post', function() { $_SERVER['test-on-post'] = true; });
  10. Filter::register('test-on-get-put', function() { $_SERVER['test-on-get-put'] = true; });
  11. Filter::register('test-before-filter', function() { return 'Filtered!'; });
  12. Filter::register('test-param', function($var1, $var2) { return $var1.$var2; });
  13. Filter::register('test-multi-1', function() { $_SERVER['test-multi-1'] = true; });
  14. Filter::register('test-multi-2', function() { $_SERVER['test-multi-2'] = true; });
  15. $this->filter('before', 'test-all-before');
  16. $this->filter('after', 'test-all-after');
  17. $this->filter('before', 'test-profile-before')->only(array('profile'));
  18. $this->filter('before', 'test-except')->except(array('index', 'profile'));
  19. $this->filter('before', 'test-on-post')->on(array('post'));
  20. $this->filter('before', 'test-on-get-put')->on(array('get', 'put'));
  21. $this->filter('before', 'test-before-filter')->only('login');
  22. $this->filter('after', 'test-before-filter')->only('logout');
  23. $this->filter('before', 'test-param:1,2')->only('edit');
  24. $this->filter('before', 'test-multi-1|test-multi-2')->only('save');
  25. }
  26. public function action_index()
  27. {
  28. return __FUNCTION__;
  29. }
  30. public function action_profile()
  31. {
  32. return __FUNCTION__;
  33. }
  34. public function action_show()
  35. {
  36. return __FUNCTION__;
  37. }
  38. public function action_edit()
  39. {
  40. return __FUNCTION__;
  41. }
  42. public function action_save()
  43. {
  44. return __FUNCTION__;
  45. }
  46. public function action_login()
  47. {
  48. return __FUNCTION__;
  49. }
  50. public function action_logout()
  51. {
  52. return __FUNCTION__;
  53. }
  54. }