PageRenderTime 54ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/yii/framework/web/filters/CInlineFilter.php

https://bitbucket.org/ddonthula/zurmofeb
PHP | 60 lines | 22 code | 3 blank | 35 comment | 1 complexity | 944711bf93b3340a8557aeae73d5940a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-2-Clause, GPL-3.0, BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /**
  3. * CInlineFilter class file.
  4. *
  5. * @author Qiang Xue <qiang.xue@gmail.com>
  6. * @link http://www.yiiframework.com/
  7. * @copyright Copyright &copy; 2008-2011 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. */
  10. /**
  11. * CInlineFilter represents a filter defined as a controller method.
  12. *
  13. * CInlineFilter executes the 'filterXYZ($action)' method defined
  14. * in the controller, where the name 'XYZ' can be retrieved from the {@link name} property.
  15. *
  16. * @author Qiang Xue <qiang.xue@gmail.com>
  17. * @package system.web.filters
  18. * @since 1.0
  19. */
  20. class CInlineFilter extends CFilter
  21. {
  22. /**
  23. * @var string name of the filter. It stands for 'XYZ' in the filter method name 'filterXYZ'.
  24. */
  25. public $name;
  26. /**
  27. * Creates an inline filter instance.
  28. * The creation is based on a string describing the inline method name
  29. * and action names that the filter shall or shall not apply to.
  30. * @param CController $controller the controller who hosts the filter methods
  31. * @param string $filterName the filter name
  32. * @return CInlineFilter the created instance
  33. * @throws CException if the filter method does not exist
  34. */
  35. public static function create($controller,$filterName)
  36. {
  37. if(method_exists($controller,'filter'.$filterName))
  38. {
  39. $filter=new CInlineFilter;
  40. $filter->name=$filterName;
  41. return $filter;
  42. }
  43. else
  44. throw new CException(Yii::t('yii','Filter "{filter}" is invalid. Controller "{class}" does not have the filter method "filter{filter}".',
  45. array('{filter}'=>$filterName, '{class}'=>get_class($controller))));
  46. }
  47. /**
  48. * Performs the filtering.
  49. * This method calls the filter method defined in the controller class.
  50. * @param CFilterChain $filterChain the filter chain that the filter is on.
  51. */
  52. public function filter($filterChain)
  53. {
  54. $method='filter'.$this->name;
  55. $filterChain->controller->$method($filterChain);
  56. }
  57. }