1: <?php
2: /**
3: * Slim - a micro PHP 5 framework
4: *
5: * @author Josh Lockhart <info@slimframework.com>
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: /**
36: * Middleware
37: *
38: * @package Slim
39: * @author Josh Lockhart
40: * @since 1.6.0
41: */
42: abstract class Middleware
43: {
44: /**
45: * @var \Slim Reference to the primary application instance
46: */
47: protected $app;
48:
49: /**
50: * @var mixed Reference to the next downstream middleware
51: */
52: protected $next;
53:
54: /**
55: * Set application
56: *
57: * This method injects the primary Slim application instance into
58: * this middleware.
59: *
60: * @param \Slim $application
61: */
62: final public function setApplication($application)
63: {
64: $this->app = $application;
65: }
66:
67: /**
68: * Get application
69: *
70: * This method retrieves the application previously injected
71: * into this middleware.
72: *
73: * @return \Slim
74: */
75: final public function getApplication()
76: {
77: return $this->app;
78: }
79:
80: /**
81: * Set next middleware
82: *
83: * This method injects the next downstream middleware into
84: * this middleware so that it may optionally be called
85: * when appropriate.
86: *
87: * @param \Slim|\Slim\Middleware
88: */
89: final public function setNextMiddleware($nextMiddleware)
90: {
91: $this->next = $nextMiddleware;
92: }
93:
94: /**
95: * Get next middleware
96: *
97: * This method retrieves the next downstream middleware
98: * previously injected into this middleware.
99: *
100: * @return \Slim|\Slim\Middleware
101: */
102: final public function getNextMiddleware()
103: {
104: return $this->next;
105: }
106:
107: /**
108: * Call
109: *
110: * Perform actions specific to this middleware and optionally
111: * call the next downstream middleware.
112: */
113: abstract public function call();
114: }
115: