Complex classes like Response often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Response, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
61 | class Response extends \yii\base\Response |
||
62 | { |
||
63 | /** |
||
64 | * @event ResponseEvent an event that is triggered at the beginning of [[send()]]. |
||
65 | */ |
||
66 | const EVENT_BEFORE_SEND = 'beforeSend'; |
||
67 | /** |
||
68 | * @event ResponseEvent an event that is triggered at the end of [[send()]]. |
||
69 | */ |
||
70 | const EVENT_AFTER_SEND = 'afterSend'; |
||
71 | /** |
||
72 | * @event ResponseEvent an event that is triggered right after [[prepare()]] is called in [[send()]]. |
||
73 | * You may respond to this event to filter the response content before it is sent to the client. |
||
74 | */ |
||
75 | const EVENT_AFTER_PREPARE = 'afterPrepare'; |
||
76 | const FORMAT_RAW = 'raw'; |
||
77 | const FORMAT_HTML = 'html'; |
||
78 | const FORMAT_JSON = 'json'; |
||
79 | const FORMAT_JSONP = 'jsonp'; |
||
80 | const FORMAT_XML = 'xml'; |
||
81 | |||
82 | /** |
||
83 | * @var string the response format. This determines how to convert [[data]] into [[content]] |
||
84 | * when the latter is not set. The value of this property must be one of the keys declared in the [[formatters]] array. |
||
85 | * By default, the following formats are supported: |
||
86 | * |
||
87 | * - [[FORMAT_RAW]]: the data will be treated as the response content without any conversion. |
||
88 | * No extra HTTP header will be added. |
||
89 | * - [[FORMAT_HTML]]: the data will be treated as the response content without any conversion. |
||
90 | * The "Content-Type" header will set as "text/html". |
||
91 | * - [[FORMAT_JSON]]: the data will be converted into JSON format, and the "Content-Type" |
||
92 | * header will be set as "application/json". |
||
93 | * - [[FORMAT_JSONP]]: the data will be converted into JSONP format, and the "Content-Type" |
||
94 | * header will be set as "text/javascript". Note that in this case `$data` must be an array |
||
95 | * with "data" and "callback" elements. The former refers to the actual data to be sent, |
||
96 | * while the latter refers to the name of the JavaScript callback. |
||
97 | * - [[FORMAT_XML]]: the data will be converted into XML format. Please refer to [[XmlResponseFormatter]] |
||
98 | * for more details. |
||
99 | * |
||
100 | * You may customize the formatting process or support additional formats by configuring [[formatters]]. |
||
101 | * @see formatters |
||
102 | */ |
||
103 | public $format = self::FORMAT_HTML; |
||
104 | /** |
||
105 | * @var string the MIME type (e.g. `application/json`) from the request ACCEPT header chosen for this response. |
||
106 | * This property is mainly set by [[\yii\filters\ContentNegotiator]]. |
||
107 | */ |
||
108 | public $acceptMimeType; |
||
109 | /** |
||
110 | * @var array the parameters (e.g. `['q' => 1, 'version' => '1.0']`) associated with the [[acceptMimeType|chosen MIME type]]. |
||
111 | * This is a list of name-value pairs associated with [[acceptMimeType]] from the ACCEPT HTTP header. |
||
112 | * This property is mainly set by [[\yii\filters\ContentNegotiator]]. |
||
113 | */ |
||
114 | public $acceptParams = []; |
||
115 | /** |
||
116 | * @var array the formatters for converting data into the response content of the specified [[format]]. |
||
117 | * The array keys are the format names, and the array values are the corresponding configurations |
||
118 | * for creating the formatter objects. |
||
119 | * @see format |
||
120 | * @see defaultFormatters |
||
121 | */ |
||
122 | public $formatters = []; |
||
123 | /** |
||
124 | * @var mixed the original response data. When this is not null, it will be converted into [[content]] |
||
125 | * according to [[format]] when the response is being sent out. |
||
126 | * @see content |
||
127 | */ |
||
128 | public $data; |
||
129 | /** |
||
130 | * @var string the response content. When [[data]] is not null, it will be converted into [[content]] |
||
131 | * according to [[format]] when the response is being sent out. |
||
132 | * @see data |
||
133 | */ |
||
134 | public $content; |
||
135 | /** |
||
136 | * @var resource|array the stream to be sent. This can be a stream handle or an array of stream handle, |
||
137 | * the begin position and the end position. Note that when this property is set, the [[data]] and [[content]] |
||
138 | * properties will be ignored by [[send()]]. |
||
139 | */ |
||
140 | public $stream; |
||
141 | /** |
||
142 | * @var string the charset of the text response. If not set, it will use |
||
143 | * the value of [[Application::charset]]. |
||
144 | */ |
||
145 | public $charset; |
||
146 | /** |
||
147 | * @var string the HTTP status description that comes together with the status code. |
||
148 | * @see httpStatuses |
||
149 | */ |
||
150 | public $statusText = 'OK'; |
||
151 | /** |
||
152 | * @var string the version of the HTTP protocol to use. If not set, it will be determined via `$_SERVER['SERVER_PROTOCOL']`, |
||
153 | * or '1.1' if that is not available. |
||
154 | */ |
||
155 | public $version; |
||
156 | /** |
||
157 | * @var bool whether the response has been sent. If this is true, calling [[send()]] will do nothing. |
||
158 | */ |
||
159 | public $isSent = false; |
||
160 | /** |
||
161 | * @var array list of HTTP status codes and the corresponding texts |
||
162 | */ |
||
163 | public static $httpStatuses = [ |
||
164 | 100 => 'Continue', |
||
165 | 101 => 'Switching Protocols', |
||
166 | 102 => 'Processing', |
||
167 | 118 => 'Connection timed out', |
||
168 | 200 => 'OK', |
||
169 | 201 => 'Created', |
||
170 | 202 => 'Accepted', |
||
171 | 203 => 'Non-Authoritative', |
||
172 | 204 => 'No Content', |
||
173 | 205 => 'Reset Content', |
||
174 | 206 => 'Partial Content', |
||
175 | 207 => 'Multi-Status', |
||
176 | 208 => 'Already Reported', |
||
177 | 210 => 'Content Different', |
||
178 | 226 => 'IM Used', |
||
179 | 300 => 'Multiple Choices', |
||
180 | 301 => 'Moved Permanently', |
||
181 | 302 => 'Found', |
||
182 | 303 => 'See Other', |
||
183 | 304 => 'Not Modified', |
||
184 | 305 => 'Use Proxy', |
||
185 | 306 => 'Reserved', |
||
186 | 307 => 'Temporary Redirect', |
||
187 | 308 => 'Permanent Redirect', |
||
188 | 310 => 'Too many Redirect', |
||
189 | 400 => 'Bad Request', |
||
190 | 401 => 'Unauthorized', |
||
191 | 402 => 'Payment Required', |
||
192 | 403 => 'Forbidden', |
||
193 | 404 => 'Not Found', |
||
194 | 405 => 'Method Not Allowed', |
||
195 | 406 => 'Not Acceptable', |
||
196 | 407 => 'Proxy Authentication Required', |
||
197 | 408 => 'Request Time-out', |
||
198 | 409 => 'Conflict', |
||
199 | 410 => 'Gone', |
||
200 | 411 => 'Length Required', |
||
201 | 412 => 'Precondition Failed', |
||
202 | 413 => 'Request Entity Too Large', |
||
203 | 414 => 'Request-URI Too Long', |
||
204 | 415 => 'Unsupported Media Type', |
||
205 | 416 => 'Requested range unsatisfiable', |
||
206 | 417 => 'Expectation failed', |
||
207 | 418 => 'I\'m a teapot', |
||
208 | 421 => 'Misdirected Request', |
||
209 | 422 => 'Unprocessable entity', |
||
210 | 423 => 'Locked', |
||
211 | 424 => 'Method failure', |
||
212 | 425 => 'Unordered Collection', |
||
213 | 426 => 'Upgrade Required', |
||
214 | 428 => 'Precondition Required', |
||
215 | 429 => 'Too Many Requests', |
||
216 | 431 => 'Request Header Fields Too Large', |
||
217 | 449 => 'Retry With', |
||
218 | 450 => 'Blocked by Windows Parental Controls', |
||
219 | 500 => 'Internal Server Error', |
||
220 | 501 => 'Not Implemented', |
||
221 | 502 => 'Bad Gateway or Proxy Error', |
||
222 | 503 => 'Service Unavailable', |
||
223 | 504 => 'Gateway Time-out', |
||
224 | 505 => 'HTTP Version not supported', |
||
225 | 507 => 'Insufficient storage', |
||
226 | 508 => 'Loop Detected', |
||
227 | 509 => 'Bandwidth Limit Exceeded', |
||
228 | 510 => 'Not Extended', |
||
229 | 511 => 'Network Authentication Required', |
||
230 | ]; |
||
231 | |||
232 | /** |
||
233 | * @var int the HTTP status code to send with the response. |
||
234 | */ |
||
235 | private $_statusCode = 200; |
||
236 | /** |
||
237 | * @var HeaderCollection |
||
238 | */ |
||
239 | private $_headers; |
||
240 | |||
241 | |||
242 | /** |
||
243 | * Initializes this component. |
||
244 | */ |
||
245 | 140 | public function init() |
|
259 | |||
260 | /** |
||
261 | * @return int the HTTP status code to send with the response. |
||
262 | */ |
||
263 | 31 | public function getStatusCode() |
|
267 | |||
268 | /** |
||
269 | * Sets the response status code. |
||
270 | * This method will set the corresponding status text if `$text` is null. |
||
271 | * @param int $value the status code |
||
272 | * @param string $text the status text. If not set, it will be set automatically based on the status code. |
||
273 | * @throws InvalidParamException if the status code is invalid. |
||
274 | * @return $this the response object itself |
||
275 | */ |
||
276 | 29 | public function setStatusCode($value, $text = null) |
|
292 | |||
293 | /** |
||
294 | * Sets the response status code based on the exception. |
||
295 | * @param \Exception $e |
||
296 | * @throws InvalidParamException if the status code is invalid. |
||
297 | * @return $this the response object itself |
||
298 | * |
||
299 | * @since 2.0.12 |
||
300 | */ |
||
301 | 7 | public function setStatusCodeByException(\Exception $e) |
|
310 | |||
311 | /** |
||
312 | * Returns the header collection. |
||
313 | * The header collection contains the currently registered HTTP headers. |
||
314 | * @return HeaderCollection the header collection |
||
315 | */ |
||
316 | 75 | public function getHeaders() |
|
323 | |||
324 | /** |
||
325 | * Sends the response to the client. |
||
326 | */ |
||
327 | 21 | public function send() |
|
340 | |||
341 | /** |
||
342 | * Clears the headers, cookies, content, status code of the response. |
||
343 | */ |
||
344 | public function clear() |
||
355 | |||
356 | /** |
||
357 | * Sends the response headers to the client |
||
358 | */ |
||
359 | 21 | protected function sendHeaders() |
|
380 | |||
381 | /** |
||
382 | * Sends the cookies to the client. |
||
383 | */ |
||
384 | protected function sendCookies() |
||
404 | |||
405 | /** |
||
406 | * Sends the response content to the client |
||
407 | */ |
||
408 | 21 | protected function sendContent() |
|
438 | |||
439 | /** |
||
440 | * Sends a file to the browser. |
||
441 | * |
||
442 | * Note that this method only prepares the response for file sending. The file is not sent |
||
443 | * until [[send()]] is called explicitly or implicitly. The latter is done after you return from a controller action. |
||
444 | * |
||
445 | * The following is an example implementation of a controller action that allows requesting files from a directory |
||
446 | * that is not accessible from web: |
||
447 | * |
||
448 | * ```php |
||
449 | * public function actionFile($filename) |
||
450 | * { |
||
451 | * $storagePath = Yii::getAlias('@app/files'); |
||
452 | * |
||
453 | * // check filename for allowed chars (do not allow ../ to avoid security issue: downloading arbitrary files) |
||
454 | * if (!preg_match('/^[a-z0-9]+\.[a-z0-9]+$/i', $filename) || !is_file("$storagePath/$filename")) { |
||
455 | * throw new \yii\web\NotFoundHttpException('The file does not exists.'); |
||
456 | * } |
||
457 | * return Yii::$app->response->sendFile("$storagePath/$filename", $filename); |
||
458 | * } |
||
459 | * ``` |
||
460 | * |
||
461 | * @param string $filePath the path of the file to be sent. |
||
462 | * @param string $attachmentName the file name shown to the user. If null, it will be determined from `$filePath`. |
||
463 | * @param array $options additional options for sending the file. The following options are supported: |
||
464 | * |
||
465 | * - `mimeType`: the MIME type of the content. If not set, it will be guessed based on `$filePath` |
||
466 | * - `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false, |
||
467 | * meaning a download dialog will pop up. |
||
468 | * |
||
469 | * @return $this the response object itself |
||
470 | * @see sendContentAsFile() |
||
471 | * @see sendStreamAsFile() |
||
472 | * @see xSendFile() |
||
473 | */ |
||
474 | 7 | public function sendFile($filePath, $attachmentName = null, $options = []) |
|
487 | |||
488 | /** |
||
489 | * Sends the specified content as a file to the browser. |
||
490 | * |
||
491 | * Note that this method only prepares the response for file sending. The file is not sent |
||
492 | * until [[send()]] is called explicitly or implicitly. The latter is done after you return from a controller action. |
||
493 | * |
||
494 | * @param string $content the content to be sent. The existing [[content]] will be discarded. |
||
495 | * @param string $attachmentName the file name shown to the user. |
||
496 | * @param array $options additional options for sending the file. The following options are supported: |
||
497 | * |
||
498 | * - `mimeType`: the MIME type of the content. Defaults to 'application/octet-stream'. |
||
499 | * - `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false, |
||
500 | * meaning a download dialog will pop up. |
||
501 | * |
||
502 | * @return $this the response object itself |
||
503 | * @throws RangeNotSatisfiableHttpException if the requested range is not satisfiable |
||
504 | * @see sendFile() for an example implementation. |
||
505 | */ |
||
506 | 1 | public function sendContentAsFile($content, $attachmentName, $options = []) |
|
535 | |||
536 | /** |
||
537 | * Sends the specified stream as a file to the browser. |
||
538 | * |
||
539 | * Note that this method only prepares the response for file sending. The file is not sent |
||
540 | * until [[send()]] is called explicitly or implicitly. The latter is done after you return from a controller action. |
||
541 | * |
||
542 | * @param resource $handle the handle of the stream to be sent. |
||
543 | * @param string $attachmentName the file name shown to the user. |
||
544 | * @param array $options additional options for sending the file. The following options are supported: |
||
545 | * |
||
546 | * - `mimeType`: the MIME type of the content. Defaults to 'application/octet-stream'. |
||
547 | * - `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false, |
||
548 | * meaning a download dialog will pop up. |
||
549 | * - `fileSize`: the size of the content to stream this is useful when size of the content is known |
||
550 | * and the content is not seekable. Defaults to content size using `ftell()`. |
||
551 | * This option is available since version 2.0.4. |
||
552 | * |
||
553 | * @return $this the response object itself |
||
554 | * @throws RangeNotSatisfiableHttpException if the requested range is not satisfiable |
||
555 | * @see sendFile() for an example implementation. |
||
556 | */ |
||
557 | 7 | public function sendStreamAsFile($handle, $attachmentName, $options = []) |
|
589 | |||
590 | /** |
||
591 | * Sets a default set of HTTP headers for file downloading purpose. |
||
592 | * @param string $attachmentName the attachment file name |
||
593 | * @param string $mimeType the MIME type for the response. If null, `Content-Type` header will NOT be set. |
||
594 | * @param bool $inline whether the browser should open the file within the browser window. Defaults to false, |
||
595 | * meaning a download dialog will pop up. |
||
596 | * @param int $contentLength the byte length of the file being downloaded. If null, `Content-Length` header will NOT be set. |
||
597 | * @return $this the response object itself |
||
598 | */ |
||
599 | 4 | public function setDownloadHeaders($attachmentName, $mimeType = null, $inline = false, $contentLength = null) |
|
620 | |||
621 | /** |
||
622 | * Determines the HTTP range given in the request. |
||
623 | * @param int $fileSize the size of the file that will be used to validate the requested HTTP range. |
||
624 | * @return array|bool the range (begin, end), or false if the range request is invalid. |
||
625 | */ |
||
626 | 8 | protected function getHttpRange($fileSize) |
|
653 | |||
654 | /** |
||
655 | * Sends existing file to a browser as a download using x-sendfile. |
||
656 | * |
||
657 | * X-Sendfile is a feature allowing a web application to redirect the request for a file to the webserver |
||
658 | * that in turn processes the request, this way eliminating the need to perform tasks like reading the file |
||
659 | * and sending it to the user. When dealing with a lot of files (or very big files) this can lead to a great |
||
660 | * increase in performance as the web application is allowed to terminate earlier while the webserver is |
||
661 | * handling the request. |
||
662 | * |
||
663 | * The request is sent to the server through a special non-standard HTTP-header. |
||
664 | * When the web server encounters the presence of such header it will discard all output and send the file |
||
665 | * specified by that header using web server internals including all optimizations like caching-headers. |
||
666 | * |
||
667 | * As this header directive is non-standard different directives exists for different web servers applications: |
||
668 | * |
||
669 | * - Apache: [X-Sendfile](http://tn123.org/mod_xsendfile) |
||
670 | * - Lighttpd v1.4: [X-LIGHTTPD-send-file](http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file) |
||
671 | * - Lighttpd v1.5: [X-Sendfile](http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file) |
||
672 | * - Nginx: [X-Accel-Redirect](http://wiki.nginx.org/XSendfile) |
||
673 | * - Cherokee: [X-Sendfile and X-Accel-Redirect](http://www.cherokee-project.com/doc/other_goodies.html#x-sendfile) |
||
674 | * |
||
675 | * So for this method to work the X-SENDFILE option/module should be enabled by the web server and |
||
676 | * a proper xHeader should be sent. |
||
677 | * |
||
678 | * **Note** |
||
679 | * |
||
680 | * This option allows to download files that are not under web folders, and even files that are otherwise protected |
||
681 | * (deny from all) like `.htaccess`. |
||
682 | * |
||
683 | * **Side effects** |
||
684 | * |
||
685 | * If this option is disabled by the web server, when this method is called a download configuration dialog |
||
686 | * will open but the downloaded file will have 0 bytes. |
||
687 | * |
||
688 | * **Known issues** |
||
689 | * |
||
690 | * There is a Bug with Internet Explorer 6, 7 and 8 when X-SENDFILE is used over an SSL connection, it will show |
||
691 | * an error message like this: "Internet Explorer was not able to open this Internet site. The requested site |
||
692 | * is either unavailable or cannot be found.". You can work around this problem by removing the `Pragma`-header. |
||
693 | * |
||
694 | * **Example** |
||
695 | * |
||
696 | * ```php |
||
697 | * Yii::$app->response->xSendFile('/home/user/Pictures/picture1.jpg'); |
||
698 | * ``` |
||
699 | * |
||
700 | * @param string $filePath file name with full path |
||
701 | * @param string $attachmentName file name shown to the user. If null, it will be determined from `$filePath`. |
||
702 | * @param array $options additional options for sending the file. The following options are supported: |
||
703 | * |
||
704 | * - `mimeType`: the MIME type of the content. If not set, it will be guessed based on `$filePath` |
||
705 | * - `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false, |
||
706 | * meaning a download dialog will pop up. |
||
707 | * - xHeader: string, the name of the x-sendfile header. Defaults to "X-Sendfile". |
||
708 | * |
||
709 | * @return $this the response object itself |
||
710 | * @see sendFile() |
||
711 | */ |
||
712 | public function xSendFile($filePath, $attachmentName = null, $options = []) |
||
738 | |||
739 | /** |
||
740 | * Returns Content-Disposition header value that is safe to use with both old and new browsers |
||
741 | * |
||
742 | * Fallback name: |
||
743 | * |
||
744 | * - Causes issues if contains non-ASCII characters with codes less than 32 or more than 126. |
||
745 | * - Causes issues if contains urlencoded characters (starting with `%`) or `%` character. Some browsers interpret |
||
746 | * `filename="X"` as urlencoded name, some don't. |
||
747 | * - Causes issues if contains path separator characters such as `\` or `/`. |
||
748 | * - Since value is wrapped with `"`, it should be escaped as `\"`. |
||
749 | * - Since input could contain non-ASCII characters, fallback is obtained by transliteration. |
||
750 | * |
||
751 | * UTF name: |
||
752 | * |
||
753 | * - Causes issues if contains path separator characters such as `\` or `/`. |
||
754 | * - Should be urlencoded since headers are ASCII-only. |
||
755 | * - Could be omitted if it exactly matches fallback name. |
||
756 | * |
||
757 | * @param string $disposition |
||
758 | * @param string $attachmentName |
||
759 | * @return string |
||
760 | * |
||
761 | * @since 2.0.10 |
||
762 | */ |
||
763 | 4 | protected function getDispositionHeaderValue($disposition, $attachmentName) |
|
774 | |||
775 | /** |
||
776 | * Redirects the browser to the specified URL. |
||
777 | * |
||
778 | * This method adds a "Location" header to the current response. Note that it does not send out |
||
779 | * the header until [[send()]] is called. In a controller action you may use this method as follows: |
||
780 | * |
||
781 | * ```php |
||
782 | * return Yii::$app->getResponse()->redirect($url); |
||
783 | * ``` |
||
784 | * |
||
785 | * In other places, if you want to send out the "Location" header immediately, you should use |
||
786 | * the following code: |
||
787 | * |
||
788 | * ```php |
||
789 | * Yii::$app->getResponse()->redirect($url)->send(); |
||
790 | * return; |
||
791 | * ``` |
||
792 | * |
||
793 | * In AJAX mode, this normally will not work as expected unless there are some |
||
794 | * client-side JavaScript code handling the redirection. To help achieve this goal, |
||
795 | * this method will send out a "X-Redirect" header instead of "Location". |
||
796 | * |
||
797 | * If you use the "yii" JavaScript module, it will handle the AJAX redirection as |
||
798 | * described above. Otherwise, you should write the following JavaScript code to |
||
799 | * handle the redirection: |
||
800 | * |
||
801 | * ```javascript |
||
802 | * $document.ajaxComplete(function (event, xhr, settings) { |
||
803 | * var url = xhr && xhr.getResponseHeader('X-Redirect'); |
||
804 | * if (url) { |
||
805 | * window.location = url; |
||
806 | * } |
||
807 | * }); |
||
808 | * ``` |
||
809 | * |
||
810 | * @param string|array $url the URL to be redirected to. This can be in one of the following formats: |
||
811 | * |
||
812 | * - a string representing a URL (e.g. "http://example.com") |
||
813 | * - a string representing a URL alias (e.g. "@example.com") |
||
814 | * - an array in the format of `[$route, ...name-value pairs...]` (e.g. `['site/index', 'ref' => 1]`). |
||
815 | * Note that the route is with respect to the whole application, instead of relative to a controller or module. |
||
816 | * [[Url::to()]] will be used to convert the array into a URL. |
||
817 | * |
||
818 | * Any relative URL will be converted into an absolute one by prepending it with the host info |
||
819 | * of the current request. |
||
820 | * |
||
821 | * @param int $statusCode the HTTP status code. Defaults to 302. |
||
822 | * See <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html> |
||
823 | * for details about HTTP status code |
||
824 | * @param bool $checkAjax whether to specially handle AJAX (and PJAX) requests. Defaults to true, |
||
825 | * meaning if the current request is an AJAX or PJAX request, then calling this method will cause the browser |
||
826 | * to redirect to the given URL. If this is false, a `Location` header will be sent, which when received as |
||
827 | * an AJAX/PJAX response, may NOT cause browser redirection. |
||
828 | * Takes effect only when request header `X-Ie-Redirect-Compatibility` is absent. |
||
829 | * @return $this the response object itself |
||
830 | */ |
||
831 | 3 | public function redirect($url, $statusCode = 302, $checkAjax = true) |
|
864 | |||
865 | /** |
||
866 | * Refreshes the current page. |
||
867 | * The effect of this method call is the same as the user pressing the refresh button of his browser |
||
868 | * (without re-posting data). |
||
869 | * |
||
870 | * In a controller action you may use this method like this: |
||
871 | * |
||
872 | * ```php |
||
873 | * return Yii::$app->getResponse()->refresh(); |
||
874 | * ``` |
||
875 | * |
||
876 | * @param string $anchor the anchor that should be appended to the redirection URL. |
||
877 | * Defaults to empty. Make sure the anchor starts with '#' if you want to specify it. |
||
878 | * @return Response the response object itself |
||
879 | */ |
||
880 | public function refresh($anchor = '') |
||
884 | |||
885 | private $_cookies; |
||
886 | |||
887 | /** |
||
888 | * Returns the cookie collection. |
||
889 | * Through the returned cookie collection, you add or remove cookies as follows, |
||
890 | * |
||
891 | * ```php |
||
892 | * // add a cookie |
||
893 | * $response->cookies->add(new Cookie([ |
||
894 | * 'name' => $name, |
||
895 | * 'value' => $value, |
||
896 | * ]); |
||
897 | * |
||
898 | * // remove a cookie |
||
899 | * $response->cookies->remove('name'); |
||
900 | * // alternatively |
||
901 | * unset($response->cookies['name']); |
||
902 | * ``` |
||
903 | * |
||
904 | * @return CookieCollection the cookie collection. |
||
905 | */ |
||
906 | 33 | public function getCookies() |
|
913 | |||
914 | /** |
||
915 | * @return bool whether this response has a valid [[statusCode]]. |
||
916 | */ |
||
917 | 29 | public function getIsInvalid() |
|
921 | |||
922 | /** |
||
923 | * @return bool whether this response is informational |
||
924 | */ |
||
925 | public function getIsInformational() |
||
929 | |||
930 | /** |
||
931 | * @return bool whether this response is successful |
||
932 | */ |
||
933 | public function getIsSuccessful() |
||
937 | |||
938 | /** |
||
939 | * @return bool whether this response is a redirection |
||
940 | */ |
||
941 | 1 | public function getIsRedirection() |
|
945 | |||
946 | /** |
||
947 | * @return bool whether this response indicates a client error |
||
948 | */ |
||
949 | public function getIsClientError() |
||
953 | |||
954 | /** |
||
955 | * @return bool whether this response indicates a server error |
||
956 | */ |
||
957 | public function getIsServerError() |
||
961 | |||
962 | /** |
||
963 | * @return bool whether this response is OK |
||
964 | */ |
||
965 | public function getIsOk() |
||
969 | |||
970 | /** |
||
971 | * @return bool whether this response indicates the current request is forbidden |
||
972 | */ |
||
973 | public function getIsForbidden() |
||
977 | |||
978 | /** |
||
979 | * @return bool whether this response indicates the currently requested resource is not found |
||
980 | */ |
||
981 | public function getIsNotFound() |
||
985 | |||
986 | /** |
||
987 | * @return bool whether this response is empty |
||
988 | */ |
||
989 | public function getIsEmpty() |
||
993 | |||
994 | /** |
||
995 | * @return array the formatters that are supported by default |
||
996 | */ |
||
997 | 140 | protected function defaultFormatters() |
|
1009 | |||
1010 | /** |
||
1011 | * Prepares for sending the response. |
||
1012 | * The default implementation will convert [[data]] into [[content]] and set headers accordingly. |
||
1013 | * @throws InvalidConfigException if the formatter for the specified format is invalid or [[format]] is not supported |
||
1014 | */ |
||
1015 | 21 | protected function prepare() |
|
1049 | } |
||
1050 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.