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