Base for a static organization website

DispatcherFilter.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @package Cake.Routing
  13. * @since CakePHP(tm) v 2.2
  14. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  15. */
  16. App::uses('CakeEventListener', 'Event');
  17. /**
  18. * This abstract class represents a filter to be applied to a dispatcher cycle. It acts as as
  19. * event listener with the ability to alter the request or response as needed before it is handled
  20. * by a controller or after the response body has already been built.
  21. *
  22. * @package Cake.Routing
  23. */
  24. abstract class DispatcherFilter implements CakeEventListener {
  25. /**
  26. * Default priority for all methods in this filter
  27. *
  28. * @var int
  29. */
  30. public $priority = 10;
  31. /**
  32. * Settings for this filter
  33. *
  34. * @var array
  35. */
  36. public $settings = array();
  37. /**
  38. * Constructor.
  39. *
  40. * @param array $settings Configuration settings for the filter.
  41. */
  42. public function __construct($settings = array()) {
  43. $this->settings = Hash::merge($this->settings, $settings);
  44. }
  45. /**
  46. * Returns the list of events this filter listens to.
  47. * Dispatcher notifies 2 different events `Dispatcher.before` and `Dispatcher.after`.
  48. * By default this class will attach `preDispatch` and `postDispatch` method respectively.
  49. *
  50. * Override this method at will to only listen to the events you are interested in.
  51. *
  52. * @return array
  53. */
  54. public function implementedEvents() {
  55. return array(
  56. 'Dispatcher.beforeDispatch' => array('callable' => 'beforeDispatch', 'priority' => $this->priority),
  57. 'Dispatcher.afterDispatch' => array('callable' => 'afterDispatch', 'priority' => $this->priority),
  58. );
  59. }
  60. /**
  61. * Method called before the controller is instantiated and called to serve a request.
  62. * If used with default priority, it will be called after the Router has parsed the
  63. * URL and set the routing params into the request object.
  64. *
  65. * If a CakeResponse object instance is returned, it will be served at the end of the
  66. * event cycle, not calling any controller as a result. This will also have the effect of
  67. * not calling the after event in the dispatcher.
  68. *
  69. * If false is returned, the event will be stopped and no more listeners will be notified.
  70. * Alternatively you can call `$event->stopPropagation()` to achieve the same result.
  71. *
  72. * @param CakeEvent $event container object having the `request`, `response` and `additionalParams`
  73. * keys in the data property.
  74. * @return CakeResponse|bool
  75. */
  76. public function beforeDispatch(CakeEvent $event) {
  77. }
  78. /**
  79. * Method called after the controller served a request and generated a response.
  80. * It is possible to alter the response object at this point as it is not sent to the
  81. * client yet.
  82. *
  83. * If false is returned, the event will be stopped and no more listeners will be notified.
  84. * Alternatively you can call `$event->stopPropagation()` to achieve the same result.
  85. *
  86. * @param CakeEvent $event container object having the `request` and `response`
  87. * keys in the data property.
  88. * @return mixed boolean to stop the event dispatching or null to continue
  89. */
  90. public function afterDispatch(CakeEvent $event) {
  91. }
  92. }