Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
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 |
||
19 | class Response |
||
20 | { |
||
21 | const HTTP_CONTINUE = 100; |
||
22 | const HTTP_SWITCHING_PROTOCOLS = 101; |
||
23 | const HTTP_PROCESSING = 102; // RFC2518 |
||
24 | const HTTP_OK = 200; |
||
25 | const HTTP_CREATED = 201; |
||
26 | const HTTP_ACCEPTED = 202; |
||
27 | const HTTP_NON_AUTHORITATIVE_INFORMATION = 203; |
||
28 | const HTTP_NO_CONTENT = 204; |
||
29 | const HTTP_RESET_CONTENT = 205; |
||
30 | const HTTP_PARTIAL_CONTENT = 206; |
||
31 | const HTTP_MULTI_STATUS = 207; // RFC4918 |
||
32 | const HTTP_ALREADY_REPORTED = 208; // RFC5842 |
||
33 | const HTTP_IM_USED = 226; // RFC3229 |
||
34 | const HTTP_MULTIPLE_CHOICES = 300; |
||
35 | const HTTP_MOVED_PERMANENTLY = 301; |
||
36 | const HTTP_FOUND = 302; |
||
37 | const HTTP_SEE_OTHER = 303; |
||
38 | const HTTP_NOT_MODIFIED = 304; |
||
39 | const HTTP_USE_PROXY = 305; |
||
40 | const HTTP_RESERVED = 306; |
||
41 | const HTTP_TEMPORARY_REDIRECT = 307; |
||
42 | const HTTP_PERMANENTLY_REDIRECT = 308; // RFC7238 |
||
43 | const HTTP_BAD_REQUEST = 400; |
||
44 | const HTTP_UNAUTHORIZED = 401; |
||
45 | const HTTP_PAYMENT_REQUIRED = 402; |
||
46 | const HTTP_FORBIDDEN = 403; |
||
47 | const HTTP_NOT_FOUND = 404; |
||
48 | const HTTP_METHOD_NOT_ALLOWED = 405; |
||
49 | const HTTP_NOT_ACCEPTABLE = 406; |
||
50 | const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407; |
||
51 | const HTTP_REQUEST_TIMEOUT = 408; |
||
52 | const HTTP_CONFLICT = 409; |
||
53 | const HTTP_GONE = 410; |
||
54 | const HTTP_LENGTH_REQUIRED = 411; |
||
55 | const HTTP_PRECONDITION_FAILED = 412; |
||
56 | const HTTP_REQUEST_ENTITY_TOO_LARGE = 413; |
||
57 | const HTTP_REQUEST_URI_TOO_LONG = 414; |
||
58 | const HTTP_UNSUPPORTED_MEDIA_TYPE = 415; |
||
59 | const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; |
||
60 | const HTTP_EXPECTATION_FAILED = 417; |
||
61 | const HTTP_I_AM_A_TEAPOT = 418; // RFC2324 |
||
62 | const HTTP_MISDIRECTED_REQUEST = 421; // RFC7540 |
||
63 | const HTTP_UNPROCESSABLE_ENTITY = 422; // RFC4918 |
||
64 | const HTTP_LOCKED = 423; // RFC4918 |
||
65 | const HTTP_FAILED_DEPENDENCY = 424; // RFC4918 |
||
66 | const HTTP_RESERVED_FOR_WEBDAV_ADVANCED_COLLECTIONS_EXPIRED_PROPOSAL = 425; // RFC2817 |
||
67 | const HTTP_UPGRADE_REQUIRED = 426; // RFC2817 |
||
68 | const HTTP_PRECONDITION_REQUIRED = 428; // RFC6585 |
||
69 | const HTTP_TOO_MANY_REQUESTS = 429; // RFC6585 |
||
70 | const HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431; // RFC6585 |
||
71 | const HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451; |
||
72 | const HTTP_INTERNAL_SERVER_ERROR = 500; |
||
73 | const HTTP_NOT_IMPLEMENTED = 501; |
||
74 | const HTTP_BAD_GATEWAY = 502; |
||
75 | const HTTP_SERVICE_UNAVAILABLE = 503; |
||
76 | const HTTP_GATEWAY_TIMEOUT = 504; |
||
77 | const HTTP_VERSION_NOT_SUPPORTED = 505; |
||
78 | const HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506; // RFC2295 |
||
79 | const HTTP_INSUFFICIENT_STORAGE = 507; // RFC4918 |
||
80 | const HTTP_LOOP_DETECTED = 508; // RFC5842 |
||
81 | const HTTP_NOT_EXTENDED = 510; // RFC2774 |
||
82 | const HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511; // RFC6585 |
||
83 | |||
84 | /** |
||
85 | * @var \Symfony\Component\HttpFoundation\ResponseHeaderBag |
||
86 | */ |
||
87 | public $headers; |
||
88 | |||
89 | /** |
||
90 | * @var string |
||
91 | */ |
||
92 | protected $content; |
||
93 | |||
94 | /** |
||
95 | * @var string |
||
96 | */ |
||
97 | protected $version; |
||
98 | |||
99 | /** |
||
100 | * @var int |
||
101 | */ |
||
102 | protected $statusCode; |
||
103 | |||
104 | /** |
||
105 | * @var string |
||
106 | */ |
||
107 | protected $statusText; |
||
108 | |||
109 | /** |
||
110 | * @var string |
||
111 | */ |
||
112 | protected $charset; |
||
113 | |||
114 | /** |
||
115 | * Status codes translation table. |
||
116 | * |
||
117 | * The list of codes is complete according to the |
||
118 | * {@link http://www.iana.org/assignments/http-status-codes/ Hypertext Transfer Protocol (HTTP) Status Code Registry} |
||
119 | * (last updated 2016-03-01). |
||
120 | * |
||
121 | * Unless otherwise noted, the status code is defined in RFC2616. |
||
122 | * |
||
123 | * @var array |
||
124 | */ |
||
125 | public static $statusTexts = array( |
||
126 | 100 => 'Continue', |
||
127 | 101 => 'Switching Protocols', |
||
128 | 102 => 'Processing', // RFC2518 |
||
129 | 200 => 'OK', |
||
130 | 201 => 'Created', |
||
131 | 202 => 'Accepted', |
||
132 | 203 => 'Non-Authoritative Information', |
||
133 | 204 => 'No Content', |
||
134 | 205 => 'Reset Content', |
||
135 | 206 => 'Partial Content', |
||
136 | 207 => 'Multi-Status', // RFC4918 |
||
137 | 208 => 'Already Reported', // RFC5842 |
||
138 | 226 => 'IM Used', // RFC3229 |
||
139 | 300 => 'Multiple Choices', |
||
140 | 301 => 'Moved Permanently', |
||
141 | 302 => 'Found', |
||
142 | 303 => 'See Other', |
||
143 | 304 => 'Not Modified', |
||
144 | 305 => 'Use Proxy', |
||
145 | 306 => 'Reserved', |
||
146 | 307 => 'Temporary Redirect', |
||
147 | 308 => 'Permanent Redirect', // RFC7238 |
||
148 | 400 => 'Bad Request', |
||
149 | 401 => 'Unauthorized', |
||
150 | 402 => 'Payment Required', |
||
151 | 403 => 'Forbidden', |
||
152 | 404 => 'Not Found', |
||
153 | 405 => 'Method Not Allowed', |
||
154 | 406 => 'Not Acceptable', |
||
155 | 407 => 'Proxy Authentication Required', |
||
156 | 408 => 'Request Timeout', |
||
157 | 409 => 'Conflict', |
||
158 | 410 => 'Gone', |
||
159 | 411 => 'Length Required', |
||
160 | 412 => 'Precondition Failed', |
||
161 | 413 => 'Payload Too Large', |
||
162 | 414 => 'URI Too Long', |
||
163 | 415 => 'Unsupported Media Type', |
||
164 | 416 => 'Range Not Satisfiable', |
||
165 | 417 => 'Expectation Failed', |
||
166 | 418 => 'I\'m a teapot', // RFC2324 |
||
167 | 421 => 'Misdirected Request', // RFC7540 |
||
168 | 422 => 'Unprocessable Entity', // RFC4918 |
||
169 | 423 => 'Locked', // RFC4918 |
||
170 | 424 => 'Failed Dependency', // RFC4918 |
||
171 | 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 |
||
172 | 426 => 'Upgrade Required', // RFC2817 |
||
173 | 428 => 'Precondition Required', // RFC6585 |
||
174 | 429 => 'Too Many Requests', // RFC6585 |
||
175 | 431 => 'Request Header Fields Too Large', // RFC6585 |
||
176 | 451 => 'Unavailable For Legal Reasons', // RFC7725 |
||
177 | 500 => 'Internal Server Error', |
||
178 | 501 => 'Not Implemented', |
||
179 | 502 => 'Bad Gateway', |
||
180 | 503 => 'Service Unavailable', |
||
181 | 504 => 'Gateway Timeout', |
||
182 | 505 => 'HTTP Version Not Supported', |
||
183 | 506 => 'Variant Also Negotiates', // RFC2295 |
||
184 | 507 => 'Insufficient Storage', // RFC4918 |
||
185 | 508 => 'Loop Detected', // RFC5842 |
||
186 | 510 => 'Not Extended', // RFC2774 |
||
187 | 511 => 'Network Authentication Required', // RFC6585 |
||
188 | ); |
||
189 | |||
190 | /** |
||
191 | * Constructor. |
||
192 | * |
||
193 | * @param mixed $content The response content, see setContent() |
||
194 | * @param int $status The response status code |
||
195 | * @param array $headers An array of response headers |
||
196 | * |
||
197 | * @throws \InvalidArgumentException When the HTTP status code is not valid |
||
198 | */ |
||
199 | public function __construct($content = '', $status = 200, $headers = array()) |
||
209 | |||
210 | /** |
||
211 | * Factory method for chainability. |
||
212 | * |
||
213 | * Example: |
||
214 | * |
||
215 | * return Response::create($body, 200) |
||
216 | * ->setSharedMaxAge(300); |
||
217 | * |
||
218 | * @param mixed $content The response content, see setContent() |
||
219 | * @param int $status The response status code |
||
220 | * @param array $headers An array of response headers |
||
221 | * |
||
222 | * @return static |
||
223 | */ |
||
224 | public static function create($content = '', $status = 200, $headers = array()) |
||
228 | |||
229 | /** |
||
230 | * Returns the Response as an HTTP string. |
||
231 | * |
||
232 | * The string representation of the Response is the same as the |
||
233 | * one that will be sent to the client only if the prepare() method |
||
234 | * has been called before. |
||
235 | * |
||
236 | * @return string The Response as an HTTP string |
||
237 | * |
||
238 | * @see prepare() |
||
239 | */ |
||
240 | public function __toString() |
||
247 | |||
248 | /** |
||
249 | * Clones the current Response instance. |
||
250 | */ |
||
251 | public function __clone() |
||
255 | |||
256 | /** |
||
257 | * Prepares the Response before it is sent to the client. |
||
258 | * |
||
259 | * This method tweaks the Response to ensure that it is |
||
260 | * compliant with RFC 2616. Most of the changes are based on |
||
261 | * the Request that is "associated" with this Response. |
||
262 | * |
||
263 | * @param Request $request A Request instance |
||
264 | * |
||
265 | * @return $this |
||
266 | */ |
||
267 | public function prepare(Request $request) |
||
323 | |||
324 | /** |
||
325 | * Sends HTTP headers. |
||
326 | * |
||
327 | * @return $this |
||
328 | */ |
||
329 | public function sendHeaders() |
||
353 | |||
354 | /** |
||
355 | * Sends content for the current web response. |
||
356 | * |
||
357 | * @return $this |
||
358 | */ |
||
359 | public function sendContent() |
||
365 | |||
366 | /** |
||
367 | * Sends HTTP headers and content. |
||
368 | * |
||
369 | * @return $this |
||
370 | */ |
||
371 | public function send() |
||
384 | |||
385 | /** |
||
386 | * Sets the response content. |
||
387 | * |
||
388 | * Valid types are strings, numbers, null, and objects that implement a __toString() method. |
||
389 | * |
||
390 | * @param mixed $content Content that can be cast to string |
||
391 | * |
||
392 | * @return $this |
||
393 | * |
||
394 | * @throws \UnexpectedValueException |
||
395 | */ |
||
396 | public function setContent($content) |
||
406 | |||
407 | /** |
||
408 | * Gets the current response content. |
||
409 | * |
||
410 | * @return string Content |
||
411 | */ |
||
412 | public function getContent() |
||
416 | |||
417 | /** |
||
418 | * Sets the HTTP protocol version (1.0 or 1.1). |
||
419 | * |
||
420 | * @param string $version The HTTP protocol version |
||
421 | * |
||
422 | * @return $this |
||
423 | */ |
||
424 | public function setProtocolVersion($version) |
||
430 | |||
431 | /** |
||
432 | * Gets the HTTP protocol version. |
||
433 | * |
||
434 | * @return string The HTTP protocol version |
||
435 | */ |
||
436 | public function getProtocolVersion() |
||
440 | |||
441 | /** |
||
442 | * Sets the response status code. |
||
443 | * |
||
444 | * @param int $code HTTP status code |
||
445 | * @param mixed $text HTTP status text |
||
446 | * |
||
447 | * If the status text is null it will be automatically populated for the known |
||
448 | * status codes and left empty otherwise. |
||
449 | * |
||
450 | * @return $this |
||
451 | * |
||
452 | * @throws \InvalidArgumentException When the HTTP status code is not valid |
||
453 | */ |
||
454 | public function setStatusCode($code, $text = null) |
||
477 | |||
478 | /** |
||
479 | * Retrieves the status code for the current web response. |
||
480 | * |
||
481 | * @return int Status code |
||
482 | */ |
||
483 | public function getStatusCode() |
||
487 | |||
488 | /** |
||
489 | * Sets the response charset. |
||
490 | * |
||
491 | * @param string $charset Character set |
||
492 | * |
||
493 | * @return $this |
||
494 | */ |
||
495 | public function setCharset($charset) |
||
501 | |||
502 | /** |
||
503 | * Retrieves the response charset. |
||
504 | * |
||
505 | * @return string Character set |
||
506 | */ |
||
507 | public function getCharset() |
||
511 | |||
512 | /** |
||
513 | * Returns true if the response is worth caching under any circumstance. |
||
514 | * |
||
515 | * Responses marked "private" with an explicit Cache-Control directive are |
||
516 | * considered uncacheable. |
||
517 | * |
||
518 | * Responses with neither a freshness lifetime (Expires, max-age) nor cache |
||
519 | * validator (Last-Modified, ETag) are considered uncacheable. |
||
520 | * |
||
521 | * @return bool true if the response is worth caching, false otherwise |
||
522 | */ |
||
523 | public function isCacheable() |
||
535 | |||
536 | /** |
||
537 | * Returns true if the response is "fresh". |
||
538 | * |
||
539 | * Fresh responses may be served from cache without any interaction with the |
||
540 | * origin. A response is considered fresh when it includes a Cache-Control/max-age |
||
541 | * indicator or Expires header and the calculated age is less than the freshness lifetime. |
||
542 | * |
||
543 | * @return bool true if the response is fresh, false otherwise |
||
544 | */ |
||
545 | public function isFresh() |
||
549 | |||
550 | /** |
||
551 | * Returns true if the response includes headers that can be used to validate |
||
552 | * the response with the origin server using a conditional GET request. |
||
553 | * |
||
554 | * @return bool true if the response is validateable, false otherwise |
||
555 | */ |
||
556 | public function isValidateable() |
||
560 | |||
561 | /** |
||
562 | * Marks the response as "private". |
||
563 | * |
||
564 | * It makes the response ineligible for serving other clients. |
||
565 | * |
||
566 | * @return $this |
||
567 | */ |
||
568 | public function setPrivate() |
||
575 | |||
576 | /** |
||
577 | * Marks the response as "public". |
||
578 | * |
||
579 | * It makes the response eligible for serving other clients. |
||
580 | * |
||
581 | * @return $this |
||
582 | */ |
||
583 | public function setPublic() |
||
590 | |||
591 | /** |
||
592 | * Returns true if the response must be revalidated by caches. |
||
593 | * |
||
594 | * This method indicates that the response must not be served stale by a |
||
595 | * cache in any circumstance without first revalidating with the origin. |
||
596 | * When present, the TTL of the response should not be overridden to be |
||
597 | * greater than the value provided by the origin. |
||
598 | * |
||
599 | * @return bool true if the response must be revalidated by a cache, false otherwise |
||
600 | */ |
||
601 | public function mustRevalidate() |
||
605 | |||
606 | /** |
||
607 | * Returns the Date header as a DateTime instance. |
||
608 | * |
||
609 | * @return \DateTime A \DateTime instance |
||
610 | * |
||
611 | * @throws \RuntimeException When the header is not parseable |
||
612 | */ |
||
613 | public function getDate() |
||
617 | |||
618 | /** |
||
619 | * Sets the Date header. |
||
620 | * |
||
621 | * @param \DateTime $date A \DateTime instance |
||
622 | * |
||
623 | * @return $this |
||
624 | */ |
||
625 | public function setDate(\DateTime $date) |
||
632 | |||
633 | /** |
||
634 | * Returns the age of the response. |
||
635 | * |
||
636 | * @return int The age of the response in seconds |
||
637 | */ |
||
638 | public function getAge() |
||
646 | |||
647 | /** |
||
648 | * Marks the response stale by setting the Age header to be equal to the maximum age of the response. |
||
649 | * |
||
650 | * @return $this |
||
651 | */ |
||
652 | public function expire() |
||
660 | |||
661 | /** |
||
662 | * Returns the value of the Expires header as a DateTime instance. |
||
663 | * |
||
664 | * @return \DateTime|null A DateTime instance or null if the header does not exist |
||
665 | */ |
||
666 | public function getExpires() |
||
675 | |||
676 | /** |
||
677 | * Sets the Expires HTTP header with a DateTime instance. |
||
678 | * |
||
679 | * Passing null as value will remove the header. |
||
680 | * |
||
681 | * @param \DateTime|null $date A \DateTime instance or null to remove the header |
||
682 | * |
||
683 | * @return $this |
||
684 | */ |
||
685 | View Code Duplication | public function setExpires(\DateTime $date = null) |
|
697 | |||
698 | /** |
||
699 | * Returns the number of seconds after the time specified in the response's Date |
||
700 | * header when the response should no longer be considered fresh. |
||
701 | * |
||
702 | * First, it checks for a s-maxage directive, then a max-age directive, and then it falls |
||
703 | * back on an expires header. It returns null when no maximum age can be established. |
||
704 | * |
||
705 | * @return int|null Number of seconds |
||
706 | */ |
||
707 | public function getMaxAge() |
||
721 | |||
722 | /** |
||
723 | * Sets the number of seconds after which the response should no longer be considered fresh. |
||
724 | * |
||
725 | * This methods sets the Cache-Control max-age directive. |
||
726 | * |
||
727 | * @param int $value Number of seconds |
||
728 | * |
||
729 | * @return $this |
||
730 | */ |
||
731 | public function setMaxAge($value) |
||
737 | |||
738 | /** |
||
739 | * Sets the number of seconds after which the response should no longer be considered fresh by shared caches. |
||
740 | * |
||
741 | * This methods sets the Cache-Control s-maxage directive. |
||
742 | * |
||
743 | * @param int $value Number of seconds |
||
744 | * |
||
745 | * @return $this |
||
746 | */ |
||
747 | public function setSharedMaxAge($value) |
||
754 | |||
755 | /** |
||
756 | * Returns the response's time-to-live in seconds. |
||
757 | * |
||
758 | * It returns null when no freshness information is present in the response. |
||
759 | * |
||
760 | * When the responses TTL is <= 0, the response may not be served from cache without first |
||
761 | * revalidating with the origin. |
||
762 | * |
||
763 | * @return int|null The TTL in seconds |
||
764 | */ |
||
765 | public function getTtl() |
||
771 | |||
772 | /** |
||
773 | * Sets the response's time-to-live for shared caches. |
||
774 | * |
||
775 | * This method adjusts the Cache-Control/s-maxage directive. |
||
776 | * |
||
777 | * @param int $seconds Number of seconds |
||
778 | * |
||
779 | * @return $this |
||
780 | */ |
||
781 | public function setTtl($seconds) |
||
787 | |||
788 | /** |
||
789 | * Sets the response's time-to-live for private/client caches. |
||
790 | * |
||
791 | * This method adjusts the Cache-Control/max-age directive. |
||
792 | * |
||
793 | * @param int $seconds Number of seconds |
||
794 | * |
||
795 | * @return $this |
||
796 | */ |
||
797 | public function setClientTtl($seconds) |
||
803 | |||
804 | /** |
||
805 | * Returns the Last-Modified HTTP header as a DateTime instance. |
||
806 | * |
||
807 | * @return \DateTime|null A DateTime instance or null if the header does not exist |
||
808 | * |
||
809 | * @throws \RuntimeException When the HTTP header is not parseable |
||
810 | */ |
||
811 | public function getLastModified() |
||
815 | |||
816 | /** |
||
817 | * Sets the Last-Modified HTTP header with a DateTime instance. |
||
818 | * |
||
819 | * Passing null as value will remove the header. |
||
820 | * |
||
821 | * @param \DateTime|null $date A \DateTime instance or null to remove the header |
||
822 | * |
||
823 | * @return $this |
||
824 | */ |
||
825 | View Code Duplication | public function setLastModified(\DateTime $date = null) |
|
837 | |||
838 | /** |
||
839 | * Returns the literal value of the ETag HTTP header. |
||
840 | * |
||
841 | * @return string|null The ETag HTTP header or null if it does not exist |
||
842 | */ |
||
843 | public function getEtag() |
||
847 | |||
848 | /** |
||
849 | * Sets the ETag value. |
||
850 | * |
||
851 | * @param string|null $etag The ETag unique identifier or null to remove the header |
||
852 | * @param bool $weak Whether you want a weak ETag or not |
||
853 | * |
||
854 | * @return $this |
||
855 | */ |
||
856 | public function setEtag($etag = null, $weak = false) |
||
870 | |||
871 | /** |
||
872 | * Sets the response's cache headers (validation and/or expiration). |
||
873 | * |
||
874 | * Available options are: etag, last_modified, max_age, s_maxage, private, and public. |
||
875 | * |
||
876 | * @param array $options An array of cache options |
||
877 | * |
||
878 | * @return $this |
||
879 | * |
||
880 | * @throws \InvalidArgumentException |
||
881 | */ |
||
882 | public function setCache(array $options) |
||
922 | |||
923 | /** |
||
924 | * Modifies the response so that it conforms to the rules defined for a 304 status code. |
||
925 | * |
||
926 | * This sets the status, removes the body, and discards any headers |
||
927 | * that MUST NOT be included in 304 responses. |
||
928 | * |
||
929 | * @return $this |
||
930 | * |
||
931 | * @see http://tools.ietf.org/html/rfc2616#section-10.3.5 |
||
932 | */ |
||
933 | public function setNotModified() |
||
945 | |||
946 | /** |
||
947 | * Returns true if the response includes a Vary header. |
||
948 | * |
||
949 | * @return bool true if the response includes a Vary header, false otherwise |
||
950 | */ |
||
951 | public function hasVary() |
||
955 | |||
956 | /** |
||
957 | * Returns an array of header names given in the Vary header. |
||
958 | * |
||
959 | * @return array An array of Vary names |
||
960 | */ |
||
961 | public function getVary() |
||
974 | |||
975 | /** |
||
976 | * Sets the Vary header. |
||
977 | * |
||
978 | * @param string|array $headers |
||
979 | * @param bool $replace Whether to replace the actual value or not (true by default) |
||
980 | * |
||
981 | * @return $this |
||
982 | */ |
||
983 | public function setVary($headers, $replace = true) |
||
989 | |||
990 | /** |
||
991 | * Determines if the Response validators (ETag, Last-Modified) match |
||
992 | * a conditional value specified in the Request. |
||
993 | * |
||
994 | * If the Response is not modified, it sets the status code to 304 and |
||
995 | * removes the actual content by calling the setNotModified() method. |
||
996 | * |
||
997 | * @param Request $request A Request instance |
||
998 | * |
||
999 | * @return bool true if the Response validators match the Request, false otherwise |
||
1000 | */ |
||
1001 | public function isNotModified(Request $request) |
||
1025 | |||
1026 | /** |
||
1027 | * Is response invalid? |
||
1028 | * |
||
1029 | * @return bool |
||
1030 | * |
||
1031 | * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html |
||
1032 | */ |
||
1033 | public function isInvalid() |
||
1037 | |||
1038 | /** |
||
1039 | * Is response informative? |
||
1040 | * |
||
1041 | * @return bool |
||
1042 | */ |
||
1043 | public function isInformational() |
||
1047 | |||
1048 | /** |
||
1049 | * Is response successful? |
||
1050 | * |
||
1051 | * @return bool |
||
1052 | */ |
||
1053 | public function isSuccessful() |
||
1057 | |||
1058 | /** |
||
1059 | * Is the response a redirect? |
||
1060 | * |
||
1061 | * @return bool |
||
1062 | */ |
||
1063 | public function isRedirection() |
||
1067 | |||
1068 | /** |
||
1069 | * Is there a client error? |
||
1070 | * |
||
1071 | * @return bool |
||
1072 | */ |
||
1073 | public function isClientError() |
||
1077 | |||
1078 | /** |
||
1079 | * Was there a server side error? |
||
1080 | * |
||
1081 | * @return bool |
||
1082 | */ |
||
1083 | public function isServerError() |
||
1087 | |||
1088 | /** |
||
1089 | * Is the response OK? |
||
1090 | * |
||
1091 | * @return bool |
||
1092 | */ |
||
1093 | public function isOk() |
||
1097 | |||
1098 | /** |
||
1099 | * Is the response forbidden? |
||
1100 | * |
||
1101 | * @return bool |
||
1102 | */ |
||
1103 | public function isForbidden() |
||
1107 | |||
1108 | /** |
||
1109 | * Is the response a not found error? |
||
1110 | * |
||
1111 | * @return bool |
||
1112 | */ |
||
1113 | public function isNotFound() |
||
1117 | |||
1118 | /** |
||
1119 | * Is the response a redirect of some form? |
||
1120 | * |
||
1121 | * @param string $location |
||
1122 | * |
||
1123 | * @return bool |
||
1124 | */ |
||
1125 | public function isRedirect($location = null) |
||
1129 | |||
1130 | /** |
||
1131 | * Is the response empty? |
||
1132 | * |
||
1133 | * @return bool |
||
1134 | */ |
||
1135 | public function isEmpty() |
||
1139 | |||
1140 | /** |
||
1141 | * Cleans or flushes output buffers up to target level. |
||
1142 | * |
||
1143 | * Resulting level can be greater than target level if a non-removable buffer has been encountered. |
||
1144 | * |
||
1145 | * @param int $targetLevel The target output buffering level |
||
1146 | * @param bool $flush Whether to flush or clean the buffers |
||
1147 | */ |
||
1148 | public static function closeOutputBuffers($targetLevel, $flush) |
||
1162 | |||
1163 | /** |
||
1164 | * Checks if we need to remove Cache-Control for SSL encrypted downloads when using IE < 9. |
||
1165 | * |
||
1166 | * @see http://support.microsoft.com/kb/323308 |
||
1167 | */ |
||
1168 | protected function ensureIEOverSSLCompatibility(Request $request) |
||
1176 | } |
||
1177 |