1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: *
6: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
7: *
8: * For the full copyright and license information, please view
9: * the file license.txt that was distributed with this source code.
10: * @package Nette\Application
11: */
12:
13:
14:
15: /**
16: * Presenter request. Immutable object.
17: *
18: * @author David Grudl
19: *
20: * @property string $presenterName
21: * @property array $parameters
22: * @property array $post
23: * @property array $files
24: * @property string $method
25: * @package Nette\Application
26: */
27: final class NPresenterRequest extends NFreezableObject
28: {
29: /** method */
30: const FORWARD = 'FORWARD';
31:
32: /** flag */
33: const SECURED = 'secured';
34:
35: /** flag */
36: const RESTORED = 'restored';
37:
38: /** @var string */
39: private $method;
40:
41: /** @var array */
42: private $flags = array();
43:
44: /** @var string */
45: private $name;
46:
47: /** @var array */
48: private $params;
49:
50: /** @var array */
51: private $post;
52:
53: /** @var array */
54: private $files;
55:
56:
57:
58: /**
59: * @param string fully qualified presenter name (module:module:presenter)
60: * @param string method
61: * @param array variables provided to the presenter usually via URL
62: * @param array variables provided to the presenter via POST
63: * @param array all uploaded files
64: * @param array flags
65: */
66: public function __construct($name, $method, array $params, array $post = array(), array $files = array(), array $flags = array())
67: {
68: $this->name = $name;
69: $this->method = $method;
70: $this->params = $params;
71: $this->post = $post;
72: $this->files = $files;
73: $this->flags = $flags;
74: }
75:
76:
77:
78: /**
79: * Sets the presenter name.
80: * @param string
81: * @return NPresenterRequest provides a fluent interface
82: */
83: public function setPresenterName($name)
84: {
85: $this->updating();
86: $this->name = $name;
87: return $this;
88: }
89:
90:
91:
92: /**
93: * Retrieve the presenter name.
94: * @return string
95: */
96: public function getPresenterName()
97: {
98: return $this->name;
99: }
100:
101:
102:
103: /**
104: * Sets variables provided to the presenter.
105: * @return NPresenterRequest provides a fluent interface
106: */
107: public function setParameters(array $params)
108: {
109: $this->updating();
110: $this->params = $params;
111: return $this;
112: }
113:
114:
115:
116: /**
117: * Returns all variables provided to the presenter (usually via URL).
118: * @return array
119: */
120: public function getParameters()
121: {
122: return $this->params;
123: }
124:
125:
126:
127: /** @deprecated */
128: function setParams(array $params)
129: {
130: trigger_error(__METHOD__ . '() is deprecated; use setParameters() instead.', E_USER_WARNING);
131: return $this->setParameters($params);
132: }
133:
134:
135:
136: /** @deprecated */
137: function getParams()
138: {
139: trigger_error(__METHOD__ . '() is deprecated; use getParameters() instead.', E_USER_WARNING);
140: return $this->getParameters();
141: }
142:
143:
144:
145: /**
146: * Sets variables provided to the presenter via POST.
147: * @return NPresenterRequest provides a fluent interface
148: */
149: public function setPost(array $params)
150: {
151: $this->updating();
152: $this->post = $params;
153: return $this;
154: }
155:
156:
157:
158: /**
159: * Returns all variables provided to the presenter via POST.
160: * @return array
161: */
162: public function getPost()
163: {
164: return $this->post;
165: }
166:
167:
168:
169: /**
170: * Sets all uploaded files.
171: * @return NPresenterRequest provides a fluent interface
172: */
173: public function setFiles(array $files)
174: {
175: $this->updating();
176: $this->files = $files;
177: return $this;
178: }
179:
180:
181:
182: /**
183: * Returns all uploaded files.
184: * @return array
185: */
186: public function getFiles()
187: {
188: return $this->files;
189: }
190:
191:
192:
193: /**
194: * Sets the method.
195: * @param string
196: * @return NPresenterRequest provides a fluent interface
197: */
198: public function setMethod($method)
199: {
200: $this->method = $method;
201: return $this;
202: }
203:
204:
205:
206: /**
207: * Returns the method.
208: * @return string
209: */
210: public function getMethod()
211: {
212: return $this->method;
213: }
214:
215:
216:
217: /**
218: * Checks if the method is the given one.
219: * @param string
220: * @return bool
221: */
222: public function isMethod($method)
223: {
224: return strcasecmp($this->method, $method) === 0;
225: }
226:
227:
228:
229: /**
230: * Checks if the method is POST.
231: * @return bool
232: */
233: public function isPost()
234: {
235: return strcasecmp($this->method, 'post') === 0;
236: }
237:
238:
239:
240: /**
241: * Sets the flag.
242: * @param string
243: * @param bool
244: * @return NPresenterRequest provides a fluent interface
245: */
246: public function setFlag($flag, $value = TRUE)
247: {
248: $this->updating();
249: $this->flags[$flag] = (bool) $value;
250: return $this;
251: }
252:
253:
254:
255: /**
256: * Checks the flag.
257: * @param string
258: * @return bool
259: */
260: public function hasFlag($flag)
261: {
262: return !empty($this->flags[$flag]);
263: }
264:
265: }
266: