Middleware.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Slim - a micro PHP 5 framework
  4. *
  5. * @author Josh Lockhart <[email protected]>
  6. * @copyright 2011 Josh Lockhart
  7. * @link http://www.slimframework.com
  8. * @license http://www.slimframework.com/license
  9. * @version 2.2.0
  10. * @package Slim
  11. *
  12. * MIT LICENSE
  13. *
  14. * Permission is hereby granted, free of charge, to any person obtaining
  15. * a copy of this software and associated documentation files (the
  16. * "Software"), to deal in the Software without restriction, including
  17. * without limitation the rights to use, copy, modify, merge, publish,
  18. * distribute, sublicense, and/or sell copies of the Software, and to
  19. * permit persons to whom the Software is furnished to do so, subject to
  20. * the following conditions:
  21. *
  22. * The above copyright notice and this permission notice shall be
  23. * included in all copies or substantial portions of the Software.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  29. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32. */
  33. namespace Slim;
  34. /**
  35. * Middleware
  36. *
  37. * @package Slim
  38. * @author Josh Lockhart
  39. * @since 1.6.0
  40. */
  41. abstract class Middleware
  42. {
  43. /**
  44. * @var \Slim Reference to the primary application instance
  45. */
  46. protected $app;
  47. /**
  48. * @var mixed Reference to the next downstream middleware
  49. */
  50. protected $next;
  51. /**
  52. * Set application
  53. *
  54. * This method injects the primary Slim application instance into
  55. * this middleware.
  56. *
  57. * @param \Slim $application
  58. */
  59. final public function setApplication($application)
  60. {
  61. $this->app = $application;
  62. }
  63. /**
  64. * Get application
  65. *
  66. * This method retrieves the application previously injected
  67. * into this middleware.
  68. *
  69. * @return \Slim
  70. */
  71. final public function getApplication()
  72. {
  73. return $this->app;
  74. }
  75. /**
  76. * Set next middleware
  77. *
  78. * This method injects the next downstream middleware into
  79. * this middleware so that it may optionally be called
  80. * when appropriate.
  81. *
  82. * @param \Slim|\Slim\Middleware
  83. */
  84. final public function setNextMiddleware($nextMiddleware)
  85. {
  86. $this->next = $nextMiddleware;
  87. }
  88. /**
  89. * Get next middleware
  90. *
  91. * This method retrieves the next downstream middleware
  92. * previously injected into this middleware.
  93. *
  94. * @return \Slim|\Slim\Middleware
  95. */
  96. final public function getNextMiddleware()
  97. {
  98. return $this->next;
  99. }
  100. /**
  101. * Call
  102. *
  103. * Perform actions specific to this middleware and optionally
  104. * call the next downstream middleware.
  105. */
  106. abstract public function call();
  107. }