1. sfFilterChain.class.php
  2. /** * sfFilterChain manages registered filters for a specific context. * * @package symfony * @subpackage filter * @author Fabien Potencier * @author Sean Kerr * @version SVN: $Id: sfFilterChain.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ */
  3. class sfFilterChain
  4. {
  5. protected
  6. $chain = array(),
  7. $index = -1;
  8. /**
  9. * Loads filters configuration for a given action instance.
  10. *
  11. * @param sfComponent $actionInstance A sfComponent instance
  12. */
  13. public function loadConfiguration($actionInstance)
  14. {
  15. require(sfContext::getInstance()->getConfigCache()->checkConfig('modules/'.$actionInstance->getModuleName().'/config/filters.yml'));
  16. }
  17. /**
  18. * Executes the next filter in this chain.
  19. */
  20. public function execute()
  21. {
  22. // skip to the next filter
  23. ++$this->index;
  24. if ($this->index < count($this->chain))
  25. {
  26. if (sfConfig::get('sf_logging_enabled'))
  27. {
  28. sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Executing filter "%s"', get_class($this->chain[$this->index])))));
  29. }
  30. // execute the next filter
  31. $this->chain[$this->index]->execute($this);
  32. }
  33. }
  34. /**
  35. * Returns true if the filter chain contains a filter of a given class.
  36. *
  37. * @param string $class The class name of the filter
  38. *
  39. * @return boolean true if the filter exists, false otherwise
  40. */
  41. public function hasFilter($class)
  42. {
  43. foreach ($this->chain as $filter)
  44. {
  45. if ($filter instanceof $class)
  46. {
  47. return true;
  48. }
  49. }
  50. return false;
  51. }
  52. /**
  53. * Registers a filter with this chain.
  54. *
  55. * @param sfFilter $filter A sfFilter implementation instance.
  56. */
  57. public function register($filter)
  58. {
  59. $this->chain[] = $filter;
  60. }
  61. }

Debug toolbar