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 | public function init() |
||
259 | |||
260 | /** |
||
261 | * @return int the HTTP status code to send with the response. |
||
262 | */ |
||
263 | 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 | */ |
||
275 | public function setStatusCode($value, $text = null) |
||
290 | |||
291 | /** |
||
292 | * Returns the header collection. |
||
293 | * The header collection contains the currently registered HTTP headers. |
||
294 | * @return HeaderCollection the header collection |
||
295 | */ |
||
296 | public function getHeaders() |
||
303 | |||
304 | /** |
||
305 | * Sends the response to the client. |
||
306 | */ |
||
307 | public function send() |
||
320 | |||
321 | /** |
||
322 | * Clears the headers, cookies, content, status code of the response. |
||
323 | */ |
||
324 | public function clear() |
||
335 | |||
336 | /** |
||
337 | * Sends the response headers to the client |
||
338 | */ |
||
339 | protected function sendHeaders() |
||
360 | |||
361 | /** |
||
362 | * Sends the cookies to the client. |
||
363 | */ |
||
364 | protected function sendCookies() |
||
384 | |||
385 | /** |
||
386 | * Sends the response content to the client |
||
387 | */ |
||
388 | protected function sendContent() |
||
418 | |||
419 | /** |
||
420 | * Sends a file to the browser. |
||
421 | * |
||
422 | * Note that this method only prepares the response for file sending. The file is not sent |
||
423 | * until [[send()]] is called explicitly or implicitly. The latter is done after you return from a controller action. |
||
424 | * |
||
425 | * The following is an example implementation of a controller action that allows requesting files from a directory |
||
426 | * that is not accessible from web: |
||
427 | * |
||
428 | * ```php |
||
429 | * public function actionFile($filename) |
||
430 | * { |
||
431 | * $storagePath = Yii::getAlias('@app/files'); |
||
432 | * |
||
433 | * // check filename for allowed chars (do not allow ../ to avoid security issue: downloading arbitrary files) |
||
434 | * if (!preg_match('/^[a-z0-9]+\.[a-z0-9]+$/i', $filename) || !is_file("$storagePath/$filename")) { |
||
435 | * throw new \yii\web\NotFoundHttpException('The file does not exists.'); |
||
436 | * } |
||
437 | * return Yii::$app->response->sendFile("$storagePath/$filename", $filename); |
||
438 | * } |
||
439 | * ``` |
||
440 | * |
||
441 | * @param string $filePath the path of the file to be sent. |
||
442 | * @param string $attachmentName the file name shown to the user. If null, it will be determined from `$filePath`. |
||
443 | * @param array $options additional options for sending the file. The following options are supported: |
||
444 | * |
||
445 | * - `mimeType`: the MIME type of the content. If not set, it will be guessed based on `$filePath` |
||
446 | * - `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false, |
||
447 | * meaning a download dialog will pop up. |
||
448 | * |
||
449 | * @return $this the response object itself |
||
450 | * @see sendContentAsFile() |
||
451 | * @see sendStreamAsFile() |
||
452 | * @see xSendFile() |
||
453 | */ |
||
454 | public function sendFile($filePath, $attachmentName = null, $options = []) |
||
467 | |||
468 | /** |
||
469 | * Sends the specified content as a file to the browser. |
||
470 | * |
||
471 | * Note that this method only prepares the response for file sending. The file is not sent |
||
472 | * until [[send()]] is called explicitly or implicitly. The latter is done after you return from a controller action. |
||
473 | * |
||
474 | * @param string $content the content to be sent. The existing [[content]] will be discarded. |
||
475 | * @param string $attachmentName the file name shown to the user. |
||
476 | * @param array $options additional options for sending the file. The following options are supported: |
||
477 | * |
||
478 | * - `mimeType`: the MIME type of the content. Defaults to 'application/octet-stream'. |
||
479 | * - `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false, |
||
480 | * meaning a download dialog will pop up. |
||
481 | * |
||
482 | * @return $this the response object itself |
||
483 | * @throws RangeNotSatisfiableHttpException if the requested range is not satisfiable |
||
484 | * @see sendFile() for an example implementation. |
||
485 | */ |
||
486 | public function sendContentAsFile($content, $attachmentName, $options = []) |
||
515 | |||
516 | /** |
||
517 | * Sends the specified stream as a file to the browser. |
||
518 | * |
||
519 | * Note that this method only prepares the response for file sending. The file is not sent |
||
520 | * until [[send()]] is called explicitly or implicitly. The latter is done after you return from a controller action. |
||
521 | * |
||
522 | * @param resource $handle the handle of the stream to be sent. |
||
523 | * @param string $attachmentName the file name shown to the user. |
||
524 | * @param array $options additional options for sending the file. The following options are supported: |
||
525 | * |
||
526 | * - `mimeType`: the MIME type of the content. Defaults to 'application/octet-stream'. |
||
527 | * - `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false, |
||
528 | * meaning a download dialog will pop up. |
||
529 | * - `fileSize`: the size of the content to stream this is useful when size of the content is known |
||
530 | * and the content is not seekable. Defaults to content size using `ftell()`. |
||
531 | * This option is available since version 2.0.4. |
||
532 | * |
||
533 | * @return $this the response object itself |
||
534 | * @throws RangeNotSatisfiableHttpException if the requested range is not satisfiable |
||
535 | * @see sendFile() for an example implementation. |
||
536 | */ |
||
537 | public function sendStreamAsFile($handle, $attachmentName, $options = []) |
||
569 | |||
570 | /** |
||
571 | * Sets a default set of HTTP headers for file downloading purpose. |
||
572 | * @param string $attachmentName the attachment file name |
||
573 | * @param string $mimeType the MIME type for the response. If null, `Content-Type` header will NOT be set. |
||
574 | * @param bool $inline whether the browser should open the file within the browser window. Defaults to false, |
||
575 | * meaning a download dialog will pop up. |
||
576 | * @param int $contentLength the byte length of the file being downloaded. If null, `Content-Length` header will NOT be set. |
||
577 | * @return $this the response object itself |
||
578 | */ |
||
579 | public function setDownloadHeaders($attachmentName, $mimeType = null, $inline = false, $contentLength = null) |
||
600 | |||
601 | /** |
||
602 | * Determines the HTTP range given in the request. |
||
603 | * @param int $fileSize the size of the file that will be used to validate the requested HTTP range. |
||
604 | * @return array|bool the range (begin, end), or false if the range request is invalid. |
||
605 | */ |
||
606 | protected function getHttpRange($fileSize) |
||
633 | |||
634 | /** |
||
635 | * Sends existing file to a browser as a download using x-sendfile. |
||
636 | * |
||
637 | * X-Sendfile is a feature allowing a web application to redirect the request for a file to the webserver |
||
638 | * that in turn processes the request, this way eliminating the need to perform tasks like reading the file |
||
639 | * and sending it to the user. When dealing with a lot of files (or very big files) this can lead to a great |
||
640 | * increase in performance as the web application is allowed to terminate earlier while the webserver is |
||
641 | * handling the request. |
||
642 | * |
||
643 | * The request is sent to the server through a special non-standard HTTP-header. |
||
644 | * When the web server encounters the presence of such header it will discard all output and send the file |
||
645 | * specified by that header using web server internals including all optimizations like caching-headers. |
||
646 | * |
||
647 | * As this header directive is non-standard different directives exists for different web servers applications: |
||
648 | * |
||
649 | * - Apache: [X-Sendfile](http://tn123.org/mod_xsendfile) |
||
650 | * - Lighttpd v1.4: [X-LIGHTTPD-send-file](http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file) |
||
651 | * - Lighttpd v1.5: [X-Sendfile](http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file) |
||
652 | * - Nginx: [X-Accel-Redirect](http://wiki.nginx.org/XSendfile) |
||
653 | * - Cherokee: [X-Sendfile and X-Accel-Redirect](http://www.cherokee-project.com/doc/other_goodies.html#x-sendfile) |
||
654 | * |
||
655 | * So for this method to work the X-SENDFILE option/module should be enabled by the web server and |
||
656 | * a proper xHeader should be sent. |
||
657 | * |
||
658 | * **Note** |
||
659 | * |
||
660 | * This option allows to download files that are not under web folders, and even files that are otherwise protected |
||
661 | * (deny from all) like `.htaccess`. |
||
662 | * |
||
663 | * **Side effects** |
||
664 | * |
||
665 | * If this option is disabled by the web server, when this method is called a download configuration dialog |
||
666 | * will open but the downloaded file will have 0 bytes. |
||
667 | * |
||
668 | * **Known issues** |
||
669 | * |
||
670 | * There is a Bug with Internet Explorer 6, 7 and 8 when X-SENDFILE is used over an SSL connection, it will show |
||
671 | * an error message like this: "Internet Explorer was not able to open this Internet site. The requested site |
||
672 | * is either unavailable or cannot be found.". You can work around this problem by removing the `Pragma`-header. |
||
673 | * |
||
674 | * **Example** |
||
675 | * |
||
676 | * ```php |
||
677 | * Yii::$app->response->xSendFile('/home/user/Pictures/picture1.jpg'); |
||
678 | * ``` |
||
679 | * |
||
680 | * @param string $filePath file name with full path |
||
681 | * @param string $attachmentName file name shown to the user. If null, it will be determined from `$filePath`. |
||
682 | * @param array $options additional options for sending the file. The following options are supported: |
||
683 | * |
||
684 | * - `mimeType`: the MIME type of the content. If not set, it will be guessed based on `$filePath` |
||
685 | * - `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false, |
||
686 | * meaning a download dialog will pop up. |
||
687 | * - xHeader: string, the name of the x-sendfile header. Defaults to "X-Sendfile". |
||
688 | * |
||
689 | * @return $this the response object itself |
||
690 | * @see sendFile() |
||
691 | */ |
||
692 | public function xSendFile($filePath, $attachmentName = null, $options = []) |
||
718 | |||
719 | /** |
||
720 | * Returns Content-Disposition header value that is safe to use with both old and new browsers |
||
721 | * |
||
722 | * Fallback name: |
||
723 | * |
||
724 | * - Causes issues if contains non-ASCII characters with codes less than 32 or more than 126. |
||
725 | * - Causes issues if contains urlencoded characters (starting with `%`) or `%` character. Some browsers interpret |
||
726 | * `filename="X"` as urlencoded name, some don't. |
||
727 | * - Causes issues if contains path separator characters such as `\` or `/`. |
||
728 | * - Since value is wrapped with `"`, it should be escaped as `\"`. |
||
729 | * - Since input could contain non-ASCII characters, fallback is obtained by transliteration. |
||
730 | * |
||
731 | * UTF name: |
||
732 | * |
||
733 | * - Causes issues if contains path separator characters such as `\` or `/`. |
||
734 | * - Should be urlencoded since headers are ASCII-only. |
||
735 | * - Could be omitted if it exactly matches fallback name. |
||
736 | * |
||
737 | * @param string $disposition |
||
738 | * @param string $attachmentName |
||
739 | * @return string |
||
740 | * |
||
741 | * @since 2.0.10 |
||
742 | */ |
||
743 | protected function getDispositionHeaderValue($disposition, $attachmentName) |
||
754 | |||
755 | /** |
||
756 | * Redirects the browser to the specified URL. |
||
757 | * |
||
758 | * This method adds a "Location" header to the current response. Note that it does not send out |
||
759 | * the header until [[send()]] is called. In a controller action you may use this method as follows: |
||
760 | * |
||
761 | * ```php |
||
762 | * return Yii::$app->getResponse()->redirect($url); |
||
763 | * ``` |
||
764 | * |
||
765 | * In other places, if you want to send out the "Location" header immediately, you should use |
||
766 | * the following code: |
||
767 | * |
||
768 | * ```php |
||
769 | * Yii::$app->getResponse()->redirect($url)->send(); |
||
770 | * return; |
||
771 | * ``` |
||
772 | * |
||
773 | * In AJAX mode, this normally will not work as expected unless there are some |
||
774 | * client-side JavaScript code handling the redirection. To help achieve this goal, |
||
775 | * this method will send out a "X-Redirect" header instead of "Location". |
||
776 | * |
||
777 | * If you use the "yii" JavaScript module, it will handle the AJAX redirection as |
||
778 | * described above. Otherwise, you should write the following JavaScript code to |
||
779 | * handle the redirection: |
||
780 | * |
||
781 | * ```javascript |
||
782 | * $document.ajaxComplete(function (event, xhr, settings) { |
||
783 | * var url = xhr && xhr.getResponseHeader('X-Redirect'); |
||
784 | * if (url) { |
||
785 | * window.location = url; |
||
786 | * } |
||
787 | * }); |
||
788 | * ``` |
||
789 | * |
||
790 | * @param string|array $url the URL to be redirected to. This can be in one of the following formats: |
||
791 | * |
||
792 | * - a string representing a URL (e.g. "http://example.com") |
||
793 | * - a string representing a URL alias (e.g. "@example.com") |
||
794 | * - an array in the format of `[$route, ...name-value pairs...]` (e.g. `['site/index', 'ref' => 1]`). |
||
795 | * Note that the route is with respect to the whole application, instead of relative to a controller or module. |
||
796 | * [[Url::to()]] will be used to convert the array into a URL. |
||
797 | * |
||
798 | * Any relative URL will be converted into an absolute one by prepending it with the host info |
||
799 | * of the current request. |
||
800 | * |
||
801 | * @param int $statusCode the HTTP status code. Defaults to 302. |
||
802 | * See <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html> |
||
803 | * for details about HTTP status code |
||
804 | * @param bool $checkAjax whether to specially handle AJAX (and PJAX) requests. Defaults to true, |
||
805 | * meaning if the current request is an AJAX or PJAX request, then calling this method will cause the browser |
||
806 | * to redirect to the given URL. If this is false, a `Location` header will be sent, which when received as |
||
807 | * an AJAX/PJAX response, may NOT cause browser redirection. |
||
808 | * Takes effect only when request header `X-Ie-Redirect-Compatibility` is absent. |
||
809 | * @return $this the response object itself |
||
810 | */ |
||
811 | public function redirect($url, $statusCode = 302, $checkAjax = true) |
||
844 | |||
845 | /** |
||
846 | * Refreshes the current page. |
||
847 | * The effect of this method call is the same as the user pressing the refresh button of his browser |
||
848 | * (without re-posting data). |
||
849 | * |
||
850 | * In a controller action you may use this method like this: |
||
851 | * |
||
852 | * ```php |
||
853 | * return Yii::$app->getResponse()->refresh(); |
||
854 | * ``` |
||
855 | * |
||
856 | * @param string $anchor the anchor that should be appended to the redirection URL. |
||
857 | * Defaults to empty. Make sure the anchor starts with '#' if you want to specify it. |
||
858 | * @return Response the response object itself |
||
859 | */ |
||
860 | public function refresh($anchor = '') |
||
864 | |||
865 | private $_cookies; |
||
866 | |||
867 | /** |
||
868 | * Returns the cookie collection. |
||
869 | * Through the returned cookie collection, you add or remove cookies as follows, |
||
870 | * |
||
871 | * ```php |
||
872 | * // add a cookie |
||
873 | * $response->cookies->add(new Cookie([ |
||
874 | * 'name' => $name, |
||
875 | * 'value' => $value, |
||
876 | * ]); |
||
877 | * |
||
878 | * // remove a cookie |
||
879 | * $response->cookies->remove('name'); |
||
880 | * // alternatively |
||
881 | * unset($response->cookies['name']); |
||
882 | * ``` |
||
883 | * |
||
884 | * @return CookieCollection the cookie collection. |
||
885 | */ |
||
886 | public function getCookies() |
||
893 | |||
894 | /** |
||
895 | * @return bool whether this response has a valid [[statusCode]]. |
||
896 | */ |
||
897 | public function getIsInvalid() |
||
901 | |||
902 | /** |
||
903 | * @return bool whether this response is informational |
||
904 | */ |
||
905 | public function getIsInformational() |
||
909 | |||
910 | /** |
||
911 | * @return bool whether this response is successful |
||
912 | */ |
||
913 | public function getIsSuccessful() |
||
917 | |||
918 | /** |
||
919 | * @return bool whether this response is a redirection |
||
920 | */ |
||
921 | public function getIsRedirection() |
||
925 | |||
926 | /** |
||
927 | * @return bool whether this response indicates a client error |
||
928 | */ |
||
929 | public function getIsClientError() |
||
933 | |||
934 | /** |
||
935 | * @return bool whether this response indicates a server error |
||
936 | */ |
||
937 | public function getIsServerError() |
||
941 | |||
942 | /** |
||
943 | * @return bool whether this response is OK |
||
944 | */ |
||
945 | public function getIsOk() |
||
949 | |||
950 | /** |
||
951 | * @return bool whether this response indicates the current request is forbidden |
||
952 | */ |
||
953 | public function getIsForbidden() |
||
957 | |||
958 | /** |
||
959 | * @return bool whether this response indicates the currently requested resource is not found |
||
960 | */ |
||
961 | public function getIsNotFound() |
||
965 | |||
966 | /** |
||
967 | * @return bool whether this response is empty |
||
968 | */ |
||
969 | public function getIsEmpty() |
||
973 | |||
974 | /** |
||
975 | * @return array the formatters that are supported by default |
||
976 | */ |
||
977 | protected function defaultFormatters() |
||
989 | |||
990 | /** |
||
991 | * Prepares for sending the response. |
||
992 | * The default implementation will convert [[data]] into [[content]] and set headers accordingly. |
||
993 | * @throws InvalidConfigException if the formatter for the specified format is invalid or [[format]] is not supported |
||
994 | */ |
||
995 | protected function prepare() |
||
1029 | } |
||
1030 |
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.