1. sfFilter.class.php
  2. /** * sfFilter provides a way for you to intercept incoming requests or outgoing responses. * * @package symfony * @subpackage filter * @author Fabien Potencier * @author Sean Kerr * @version SVN: $Id: sfFilter.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ */
  3. abstract class sfFilter
  4. {
  5. protected
  6. $parameterHolder = null,
  7. $context = null;
  8. public static
  9. $filterCalled = array();
  10. /**
  11. * Class constructor.
  12. *
  13. * @see initialize()
  14. */
  15. public function __construct($context, $parameters = array())
  16. {
  17. $this->initialize($context, $parameters);
  18. }
  19. /**
  20. * Initializes this Filter.
  21. *
  22. * @param sfContext $context The current application context
  23. * @param array $parameters An associative array of initialization parameters
  24. *
  25. * @return boolean true
  26. */
  27. public function initialize($context, $parameters = array())
  28. {
  29. $this->context = $context;
  30. $this->parameterHolder = new sfParameterHolder();
  31. $this->parameterHolder->add($parameters);
  32. return true;
  33. }
  34. /**
  35. * Returns true if this is the first call to the sfFilter instance.
  36. *
  37. * @return boolean true if this is the first call to the sfFilter instance, false otherwise
  38. */
  39. protected function isFirstCall()
  40. {
  41. $class = get_class($this);
  42. if (isset(self::$filterCalled[$class]))
  43. {
  44. return false;
  45. }
  46. else
  47. {
  48. self::$filterCalled[$class] = true;
  49. return true;
  50. }
  51. }
  52. /**
  53. * Retrieves the current application context.
  54. *
  55. * @return sfContext The current sfContext instance
  56. */
  57. public final function getContext()
  58. {
  59. return $this->context;
  60. }
  61. /**
  62. * Gets the parameter holder for this object.
  63. *
  64. * @return sfParameterHolder A sfParameterHolder instance
  65. */
  66. public function getParameterHolder()
  67. {
  68. return $this->parameterHolder;
  69. }
  70. /**
  71. * Gets the parameter associated with the given key.
  72. *
  73. * This is a shortcut for:
  74. *
  75. * <code>$this->getParameterHolder()->get()</code>
  76. *
  77. * @param string $name The key name
  78. * @param string $default The default value
  79. *
  80. * @return string The value associated with the key
  81. *
  82. * @see sfParameterHolder
  83. */
  84. public function getParameter($name, $default = null)
  85. {
  86. return $this->parameterHolder->get($name, $default);
  87. }
  88. /**
  89. * Returns true if the given key exists in the parameter holder.
  90. *
  91. * This is a shortcut for:
  92. *
  93. * <code>$this->getParameterHolder()->has()</code>
  94. *
  95. * @param string $name The key name
  96. *
  97. * @return boolean true if the given key exists, false otherwise
  98. *
  99. * @see sfParameterHolder
  100. */
  101. public function hasParameter($name)
  102. {
  103. return $this->parameterHolder->has($name);
  104. }
  105. /**
  106. * Sets the value for the given key.
  107. *
  108. * This is a shortcut for:
  109. *
  110. * <code>$this->getParameterHolder()->set()</code>
  111. *
  112. * @param string $name The key name
  113. * @param string $value The value
  114. *
  115. * @see sfParameterHolder
  116. */
  117. public function setParameter($name, $value)
  118. {
  119. return $this->parameterHolder->set($name, $value);
  120. }
  121. }

Debug toolbar