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