PageRenderTime 50ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/web/filters/CInlineFilter.php

https://bitbucket.org/mkwiek/hairdresser
PHP | 61 lines | 22 code | 3 blank | 36 comment | 1 complexity | 3e863606145ac431127160c4e9f5dea2 MD5 | raw file
Possible License(s): BSD-3-Clause, BSD-2-Clause, LGPL-2.1
  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. * @version $Id: CInlineFilter.php 3026 2011-03-06 10:41:56Z haertl.mike $
  18. * @package system.web.filters
  19. * @since 1.0
  20. */
  21. class CInlineFilter extends CFilter
  22. {
  23. /**
  24. * @var string name of the filter. It stands for 'XYZ' in the filter method name 'filterXYZ'.
  25. */
  26. public $name;
  27. /**
  28. * Creates an inline filter instance.
  29. * The creation is based on a string describing the inline method name
  30. * and action names that the filter shall or shall not apply to.
  31. * @param CController $controller the controller who hosts the filter methods
  32. * @param string $filterName the filter name
  33. * @return CInlineFilter the created instance
  34. * @throws CException if the filter method does not exist
  35. */
  36. public static function create($controller,$filterName)
  37. {
  38. if(method_exists($controller,'filter'.$filterName))
  39. {
  40. $filter=new CInlineFilter;
  41. $filter->name=$filterName;
  42. return $filter;
  43. }
  44. else
  45. throw new CException(Yii::t('yii','Filter "{filter}" is invalid. Controller "{class}" does not have the filter method "filter{filter}".',
  46. array('{filter}'=>$filterName, '{class}'=>get_class($controller))));
  47. }
  48. /**
  49. * Performs the filtering.
  50. * This method calls the filter method defined in the controller class.
  51. * @param CFilterChain $filterChain the filter chain that the filter is on.
  52. */
  53. public function filter($filterChain)
  54. {
  55. $method='filter'.$this->name;
  56. $filterChain->controller->$method($filterChain);
  57. }
  58. }