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 WebRequest 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 WebRequest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
37 | class WebRequest { |
||
38 | protected $data, $headers = []; |
||
|
|||
39 | |||
40 | /** |
||
41 | * Flag to make WebRequest::getHeader return an array of values. |
||
42 | * @since 1.26 |
||
43 | */ |
||
44 | const GETHEADER_LIST = 1; |
||
45 | |||
46 | /** |
||
47 | * The unique request ID. |
||
48 | * @var string |
||
49 | */ |
||
50 | private static $reqId; |
||
51 | |||
52 | /** |
||
53 | * Lazy-init response object |
||
54 | * @var WebResponse |
||
55 | */ |
||
56 | private $response; |
||
57 | |||
58 | /** |
||
59 | * Cached client IP address |
||
60 | * @var string |
||
61 | */ |
||
62 | private $ip; |
||
63 | |||
64 | /** |
||
65 | * The timestamp of the start of the request, with microsecond precision. |
||
66 | * @var float |
||
67 | */ |
||
68 | protected $requestTime; |
||
69 | |||
70 | /** |
||
71 | * Cached URL protocol |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $protocol; |
||
75 | |||
76 | /** |
||
77 | * @var SessionId|null Session ID to use for this |
||
78 | * request. We can't save the session directly due to reference cycles not |
||
79 | * working too well (slow GC in Zend and never collected in HHVM). |
||
80 | */ |
||
81 | protected $sessionId = null; |
||
82 | |||
83 | /** @var bool Whether this HTTP request is "safe" (even if it is an HTTP post) */ |
||
84 | protected $markedAsSafe = false; |
||
85 | |||
86 | public function __construct() { |
||
94 | |||
95 | /** |
||
96 | * Extract relevant query arguments from the http request uri's path |
||
97 | * to be merged with the normal php provided query arguments. |
||
98 | * Tries to use the REQUEST_URI data if available and parses it |
||
99 | * according to the wiki's configuration looking for any known pattern. |
||
100 | * |
||
101 | * If the REQUEST_URI is not provided we'll fall back on the PATH_INFO |
||
102 | * provided by the server if any and use that to set a 'title' parameter. |
||
103 | * |
||
104 | * @param string $want If this is not 'all', then the function |
||
105 | * will return an empty array if it determines that the URL is |
||
106 | * inside a rewrite path. |
||
107 | * |
||
108 | * @return array Any query arguments found in path matches. |
||
109 | */ |
||
110 | public static function getPathInfo( $want = 'all' ) { |
||
186 | |||
187 | /** |
||
188 | * Work out an appropriate URL prefix containing scheme and host, based on |
||
189 | * information detected from $_SERVER |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | public static function detectServer() { |
||
231 | |||
232 | /** |
||
233 | * Detect the protocol from $_SERVER. |
||
234 | * This is for use prior to Setup.php, when no WebRequest object is available. |
||
235 | * At other times, use the non-static function getProtocol(). |
||
236 | * |
||
237 | * @return array |
||
238 | */ |
||
239 | public static function detectProtocol() { |
||
248 | |||
249 | /** |
||
250 | * Get the number of seconds to have elapsed since request start, |
||
251 | * in fractional seconds, with microsecond resolution. |
||
252 | * |
||
253 | * @return float |
||
254 | * @since 1.25 |
||
255 | */ |
||
256 | public function getElapsedTime() { |
||
259 | |||
260 | /** |
||
261 | * Get the unique request ID. |
||
262 | * This is either the value of the UNIQUE_ID envvar (if present) or a |
||
263 | * randomly-generated 24-character string. |
||
264 | * |
||
265 | * @return string |
||
266 | * @since 1.27 |
||
267 | */ |
||
268 | public static function getRequestId() { |
||
276 | |||
277 | /** |
||
278 | * Override the unique request ID. This is for sub-requests, such as jobs, |
||
279 | * that wish to use the same id but are not part of the same execution context. |
||
280 | * |
||
281 | * @param string $id |
||
282 | * @since 1.27 |
||
283 | */ |
||
284 | public static function overrideRequestId( $id ) { |
||
287 | |||
288 | /** |
||
289 | * Get the current URL protocol (http or https) |
||
290 | * @return string |
||
291 | */ |
||
292 | public function getProtocol() { |
||
298 | |||
299 | /** |
||
300 | * Check for title, action, and/or variant data in the URL |
||
301 | * and interpolate it into the GET variables. |
||
302 | * This should only be run after $wgContLang is available, |
||
303 | * as we may need the list of language variants to determine |
||
304 | * available variant URLs. |
||
305 | */ |
||
306 | public function interpolateTitle() { |
||
317 | |||
318 | /** |
||
319 | * URL rewriting function; tries to extract page title and, |
||
320 | * optionally, one other fixed parameter value from a URL path. |
||
321 | * |
||
322 | * @param string $path The URL path given from the client |
||
323 | * @param array $bases One or more URLs, optionally with $1 at the end |
||
324 | * @param string|bool $key If provided, the matching key in $bases will be |
||
325 | * passed on as the value of this URL parameter |
||
326 | * @return array Array of URL variables to interpolate; empty if no match |
||
327 | */ |
||
328 | static function extractTitle( $path, $bases, $key = false ) { |
||
346 | |||
347 | /** |
||
348 | * Recursively normalizes UTF-8 strings in the given array. |
||
349 | * |
||
350 | * @param string|array $data |
||
351 | * @return array|string Cleaned-up version of the given |
||
352 | * @private |
||
353 | */ |
||
354 | function normalizeUnicode( $data ) { |
||
367 | |||
368 | /** |
||
369 | * Fetch a value from the given array or return $default if it's not set. |
||
370 | * |
||
371 | * @param array $arr |
||
372 | * @param string $name |
||
373 | * @param mixed $default |
||
374 | * @return mixed |
||
375 | */ |
||
376 | private function getGPCVal( $arr, $name, $default ) { |
||
396 | |||
397 | /** |
||
398 | * Fetch a scalar from the input without normalization, or return $default |
||
399 | * if it's not set. |
||
400 | * |
||
401 | * Unlike self::getVal(), this does not perform any normalization on the |
||
402 | * input value. |
||
403 | * |
||
404 | * @since 1.28 |
||
405 | * @param string $name |
||
406 | * @param string|null $default Optional default |
||
407 | * @return string |
||
408 | */ |
||
409 | public function getRawVal( $name, $default = null ) { |
||
422 | |||
423 | /** |
||
424 | * Fetch a scalar from the input or return $default if it's not set. |
||
425 | * Returns a string. Arrays are discarded. Useful for |
||
426 | * non-freeform text inputs (e.g. predefined internal text keys |
||
427 | * selected by a drop-down menu). For freeform input, see getText(). |
||
428 | * |
||
429 | * @param string $name |
||
430 | * @param string $default Optional default (or null) |
||
431 | * @return string |
||
432 | */ |
||
433 | public function getVal( $name, $default = null ) { |
||
444 | |||
445 | /** |
||
446 | * Set an arbitrary value into our get/post data. |
||
447 | * |
||
448 | * @param string $key Key name to use |
||
449 | * @param mixed $value Value to set |
||
450 | * @return mixed Old value if one was present, null otherwise |
||
451 | */ |
||
452 | public function setVal( $key, $value ) { |
||
457 | |||
458 | /** |
||
459 | * Unset an arbitrary value from our get/post data. |
||
460 | * |
||
461 | * @param string $key Key name to use |
||
462 | * @return mixed Old value if one was present, null otherwise |
||
463 | */ |
||
464 | public function unsetVal( $key ) { |
||
473 | |||
474 | /** |
||
475 | * Fetch an array from the input or return $default if it's not set. |
||
476 | * If source was scalar, will return an array with a single element. |
||
477 | * If no source and no default, returns null. |
||
478 | * |
||
479 | * @param string $name |
||
480 | * @param array $default Optional default (or null) |
||
481 | * @return array |
||
482 | */ |
||
483 | public function getArray( $name, $default = null ) { |
||
491 | |||
492 | /** |
||
493 | * Fetch an array of integers, or return $default if it's not set. |
||
494 | * If source was scalar, will return an array with a single element. |
||
495 | * If no source and no default, returns null. |
||
496 | * If an array is returned, contents are guaranteed to be integers. |
||
497 | * |
||
498 | * @param string $name |
||
499 | * @param array $default Option default (or null) |
||
500 | * @return array Array of ints |
||
501 | */ |
||
502 | public function getIntArray( $name, $default = null ) { |
||
509 | |||
510 | /** |
||
511 | * Fetch an integer value from the input or return $default if not set. |
||
512 | * Guaranteed to return an integer; non-numeric input will typically |
||
513 | * return 0. |
||
514 | * |
||
515 | * @param string $name |
||
516 | * @param int $default |
||
517 | * @return int |
||
518 | */ |
||
519 | public function getInt( $name, $default = 0 ) { |
||
522 | |||
523 | /** |
||
524 | * Fetch an integer value from the input or return null if empty. |
||
525 | * Guaranteed to return an integer or null; non-numeric input will |
||
526 | * typically return null. |
||
527 | * |
||
528 | * @param string $name |
||
529 | * @return int|null |
||
530 | */ |
||
531 | public function getIntOrNull( $name ) { |
||
537 | |||
538 | /** |
||
539 | * Fetch a floating point value from the input or return $default if not set. |
||
540 | * Guaranteed to return a float; non-numeric input will typically |
||
541 | * return 0. |
||
542 | * |
||
543 | * @since 1.23 |
||
544 | * @param string $name |
||
545 | * @param float $default |
||
546 | * @return float |
||
547 | */ |
||
548 | public function getFloat( $name, $default = 0.0 ) { |
||
551 | |||
552 | /** |
||
553 | * Fetch a boolean value from the input or return $default if not set. |
||
554 | * Guaranteed to return true or false, with normal PHP semantics for |
||
555 | * boolean interpretation of strings. |
||
556 | * |
||
557 | * @param string $name |
||
558 | * @param bool $default |
||
559 | * @return bool |
||
560 | */ |
||
561 | public function getBool( $name, $default = false ) { |
||
564 | |||
565 | /** |
||
566 | * Fetch a boolean value from the input or return $default if not set. |
||
567 | * Unlike getBool, the string "false" will result in boolean false, which is |
||
568 | * useful when interpreting information sent from JavaScript. |
||
569 | * |
||
570 | * @param string $name |
||
571 | * @param bool $default |
||
572 | * @return bool |
||
573 | */ |
||
574 | public function getFuzzyBool( $name, $default = false ) { |
||
577 | |||
578 | /** |
||
579 | * Return true if the named value is set in the input, whatever that |
||
580 | * value is (even "0"). Return false if the named value is not set. |
||
581 | * Example use is checking for the presence of check boxes in forms. |
||
582 | * |
||
583 | * @param string $name |
||
584 | * @return bool |
||
585 | */ |
||
586 | public function getCheck( $name ) { |
||
591 | |||
592 | /** |
||
593 | * Fetch a text string from the given array or return $default if it's not |
||
594 | * set. Carriage returns are stripped from the text. This should generally |
||
595 | * be used for form "<textarea>" and "<input>" fields, and for |
||
596 | * user-supplied freeform text input. |
||
597 | * |
||
598 | * @param string $name |
||
599 | * @param string $default Optional |
||
600 | * @return string |
||
601 | */ |
||
602 | public function getText( $name, $default = '' ) { |
||
606 | |||
607 | /** |
||
608 | * Extracts the given named values into an array. |
||
609 | * If no arguments are given, returns all input values. |
||
610 | * No transformation is performed on the values. |
||
611 | * |
||
612 | * @return array |
||
613 | */ |
||
614 | public function getValues() { |
||
629 | |||
630 | /** |
||
631 | * Returns the names of all input values excluding those in $exclude. |
||
632 | * |
||
633 | * @param array $exclude |
||
634 | * @return array |
||
635 | */ |
||
636 | public function getValueNames( $exclude = [] ) { |
||
639 | |||
640 | /** |
||
641 | * Get the values passed in the query string. |
||
642 | * No transformation is performed on the values. |
||
643 | * |
||
644 | * @return array |
||
645 | */ |
||
646 | public function getQueryValues() { |
||
649 | |||
650 | /** |
||
651 | * Return the contents of the Query with no decoding. Use when you need to |
||
652 | * know exactly what was sent, e.g. for an OAuth signature over the elements. |
||
653 | * |
||
654 | * @return string |
||
655 | */ |
||
656 | public function getRawQueryString() { |
||
659 | |||
660 | /** |
||
661 | * Return the contents of the POST with no decoding. Use when you need to |
||
662 | * know exactly what was sent, e.g. for an OAuth signature over the elements. |
||
663 | * |
||
664 | * @return string |
||
665 | */ |
||
666 | public function getRawPostString() { |
||
672 | |||
673 | /** |
||
674 | * Return the raw request body, with no processing. Cached since some methods |
||
675 | * disallow reading the stream more than once. As stated in the php docs, this |
||
676 | * does not work with enctype="multipart/form-data". |
||
677 | * |
||
678 | * @return string |
||
679 | */ |
||
680 | public function getRawInput() { |
||
687 | |||
688 | /** |
||
689 | * Get the HTTP method used for this request. |
||
690 | * |
||
691 | * @return string |
||
692 | */ |
||
693 | public function getMethod() { |
||
696 | |||
697 | /** |
||
698 | * Returns true if the present request was reached by a POST operation, |
||
699 | * false otherwise (GET, HEAD, or command-line). |
||
700 | * |
||
701 | * Note that values retrieved by the object may come from the |
||
702 | * GET URL etc even on a POST request. |
||
703 | * |
||
704 | * @return bool |
||
705 | */ |
||
706 | public function wasPosted() { |
||
709 | |||
710 | /** |
||
711 | * Return the session for this request |
||
712 | * @since 1.27 |
||
713 | * @note For performance, keep the session locally if you will be making |
||
714 | * much use of it instead of calling this method repeatedly. |
||
715 | * @return Session |
||
716 | */ |
||
717 | public function getSession() { |
||
729 | |||
730 | /** |
||
731 | * Set the session for this request |
||
732 | * @since 1.27 |
||
733 | * @private For use by MediaWiki\Session classes only |
||
734 | * @param SessionId $sessionId |
||
735 | */ |
||
736 | public function setSessionId( SessionId $sessionId ) { |
||
739 | |||
740 | /** |
||
741 | * Get the session id for this request, if any |
||
742 | * @since 1.27 |
||
743 | * @private For use by MediaWiki\Session classes only |
||
744 | * @return SessionId|null |
||
745 | */ |
||
746 | public function getSessionId() { |
||
749 | |||
750 | /** |
||
751 | * Returns true if the request has a persistent session. |
||
752 | * This does not necessarily mean that the user is logged in! |
||
753 | * |
||
754 | * @deprecated since 1.27, use |
||
755 | * \MediaWiki\Session\SessionManager::singleton()->getPersistedSessionId() |
||
756 | * instead. |
||
757 | * @return bool |
||
758 | */ |
||
759 | public function checkSessionCookie() { |
||
765 | |||
766 | /** |
||
767 | * Get a cookie from the $_COOKIE jar |
||
768 | * |
||
769 | * @param string $key The name of the cookie |
||
770 | * @param string $prefix A prefix to use for the cookie name, if not $wgCookiePrefix |
||
771 | * @param mixed $default What to return if the value isn't found |
||
772 | * @return mixed Cookie value or $default if the cookie not set |
||
773 | */ |
||
774 | public function getCookie( $key, $prefix = null, $default = null ) { |
||
781 | |||
782 | /** |
||
783 | * Return the path and query string portion of the main request URI. |
||
784 | * This will be suitable for use as a relative link in HTML output. |
||
785 | * |
||
786 | * @throws MWException |
||
787 | * @return string |
||
788 | */ |
||
789 | public static function getGlobalRequestURL() { |
||
825 | |||
826 | /** |
||
827 | * Return the path and query string portion of the request URI. |
||
828 | * This will be suitable for use as a relative link in HTML output. |
||
829 | * |
||
830 | * @throws MWException |
||
831 | * @return string |
||
832 | */ |
||
833 | public function getRequestURL() { |
||
836 | |||
837 | /** |
||
838 | * Return the request URI with the canonical service and hostname, path, |
||
839 | * and query string. This will be suitable for use as an absolute link |
||
840 | * in HTML or other output. |
||
841 | * |
||
842 | * If $wgServer is protocol-relative, this will return a fully |
||
843 | * qualified URL with the protocol that was used for this request. |
||
844 | * |
||
845 | * @return string |
||
846 | */ |
||
847 | public function getFullRequestURL() { |
||
850 | |||
851 | /** |
||
852 | * @param string $key |
||
853 | * @param string $value |
||
854 | * @return string |
||
855 | */ |
||
856 | public function appendQueryValue( $key, $value ) { |
||
859 | |||
860 | /** |
||
861 | * Appends or replaces value of query variables. |
||
862 | * |
||
863 | * @param array $array Array of values to replace/add to query |
||
864 | * @return string |
||
865 | */ |
||
866 | public function appendQueryArray( $array ) { |
||
873 | |||
874 | /** |
||
875 | * Check for limit and offset parameters on the input, and return sensible |
||
876 | * defaults if not given. The limit must be positive and is capped at 5000. |
||
877 | * Offset must be positive but is not capped. |
||
878 | * |
||
879 | * @param int $deflimit Limit to use if no input and the user hasn't set the option. |
||
880 | * @param string $optionname To specify an option other than rclimit to pull from. |
||
881 | * @return int[] First element is limit, second is offset |
||
882 | */ |
||
883 | public function getLimitOffset( $deflimit = 50, $optionname = 'rclimit' ) { |
||
907 | |||
908 | /** |
||
909 | * Return the path to the temporary file where PHP has stored the upload. |
||
910 | * |
||
911 | * @param string $key |
||
912 | * @return string|null String or null if no such file. |
||
913 | */ |
||
914 | public function getFileTempname( $key ) { |
||
918 | |||
919 | /** |
||
920 | * Return the upload error or 0 |
||
921 | * |
||
922 | * @param string $key |
||
923 | * @return int |
||
924 | */ |
||
925 | public function getUploadError( $key ) { |
||
929 | |||
930 | /** |
||
931 | * Return the original filename of the uploaded file, as reported by |
||
932 | * the submitting user agent. HTML-style character entities are |
||
933 | * interpreted and normalized to Unicode normalization form C, in part |
||
934 | * to deal with weird input from Safari with non-ASCII filenames. |
||
935 | * |
||
936 | * Other than this the name is not verified for being a safe filename. |
||
937 | * |
||
938 | * @param string $key |
||
939 | * @return string|null String or null if no such file. |
||
940 | */ |
||
941 | public function getFileName( $key ) { |
||
945 | |||
946 | /** |
||
947 | * Return a WebRequestUpload object corresponding to the key |
||
948 | * |
||
949 | * @param string $key |
||
950 | * @return WebRequestUpload |
||
951 | */ |
||
952 | public function getUpload( $key ) { |
||
955 | |||
956 | /** |
||
957 | * Return a handle to WebResponse style object, for setting cookies, |
||
958 | * headers and other stuff, for Request being worked on. |
||
959 | * |
||
960 | * @return WebResponse |
||
961 | */ |
||
962 | public function response() { |
||
970 | |||
971 | /** |
||
972 | * Initialise the header list |
||
973 | */ |
||
974 | protected function initHeaders() { |
||
995 | |||
996 | /** |
||
997 | * Get an array containing all request headers |
||
998 | * |
||
999 | * @return array Mapping header name to its value |
||
1000 | */ |
||
1001 | public function getAllHeaders() { |
||
1005 | |||
1006 | /** |
||
1007 | * Get a request header, or false if it isn't set. |
||
1008 | * |
||
1009 | * @param string $name Case-insensitive header name |
||
1010 | * @param int $flags Bitwise combination of: |
||
1011 | * WebRequest::GETHEADER_LIST Treat the header as a comma-separated list |
||
1012 | * of values, as described in RFC 2616 § 4.2. |
||
1013 | * (since 1.26). |
||
1014 | * @return string|array|bool False if header is unset; otherwise the |
||
1015 | * header value(s) as either a string (the default) or an array, if |
||
1016 | * WebRequest::GETHEADER_LIST flag was set. |
||
1017 | */ |
||
1018 | public function getHeader( $name, $flags = 0 ) { |
||
1030 | |||
1031 | /** |
||
1032 | * Get data from the session |
||
1033 | * |
||
1034 | * @note Prefer $this->getSession() instead if making multiple calls. |
||
1035 | * @param string $key Name of key in the session |
||
1036 | * @return mixed |
||
1037 | */ |
||
1038 | public function getSessionData( $key ) { |
||
1041 | |||
1042 | /** |
||
1043 | * Set session data |
||
1044 | * |
||
1045 | * @note Prefer $this->getSession() instead if making multiple calls. |
||
1046 | * @param string $key Name of key in the session |
||
1047 | * @param mixed $data |
||
1048 | */ |
||
1049 | public function setSessionData( $key, $data ) { |
||
1052 | |||
1053 | /** |
||
1054 | * Check if Internet Explorer will detect an incorrect cache extension in |
||
1055 | * PATH_INFO or QUERY_STRING. If the request can't be allowed, show an error |
||
1056 | * message or redirect to a safer URL. Returns true if the URL is OK, and |
||
1057 | * false if an error message has been shown and the request should be aborted. |
||
1058 | * |
||
1059 | * @param array $extWhitelist |
||
1060 | * @throws HttpError |
||
1061 | * @return bool |
||
1062 | */ |
||
1063 | public function checkUrlExtension( $extWhitelist = [] ) { |
||
1079 | |||
1080 | /** |
||
1081 | * Attempt to redirect to a URL with a QUERY_STRING that's not dangerous in |
||
1082 | * IE 6. Returns true if it was successful, false otherwise. |
||
1083 | * |
||
1084 | * @param string $url |
||
1085 | * @return bool |
||
1086 | */ |
||
1087 | protected function doSecurityRedirect( $url ) { |
||
1112 | |||
1113 | /** |
||
1114 | * Parse the Accept-Language header sent by the client into an array |
||
1115 | * |
||
1116 | * @return array Array( languageCode => q-value ) sorted by q-value in |
||
1117 | * descending order then appearing time in the header in ascending order. |
||
1118 | * May contain the "language" '*', which applies to languages other than those explicitly listed. |
||
1119 | * This is aligned with rfc2616 section 14.4 |
||
1120 | * Preference for earlier languages appears in rfc3282 as an extension to HTTP/1.1. |
||
1121 | */ |
||
1122 | public function getAcceptLang() { |
||
1166 | |||
1167 | /** |
||
1168 | * Fetch the raw IP from the request |
||
1169 | * |
||
1170 | * @since 1.19 |
||
1171 | * |
||
1172 | * @throws MWException |
||
1173 | * @return string |
||
1174 | */ |
||
1175 | protected function getRawIP() { |
||
1189 | |||
1190 | /** |
||
1191 | * Work out the IP address based on various globals |
||
1192 | * For trusted proxies, use the XFF client IP (first of the chain) |
||
1193 | * |
||
1194 | * @since 1.19 |
||
1195 | * |
||
1196 | * @throws MWException |
||
1197 | * @return string |
||
1198 | */ |
||
1199 | public function getIP() { |
||
1264 | |||
1265 | /** |
||
1266 | * @param string $ip |
||
1267 | * @return void |
||
1268 | * @since 1.21 |
||
1269 | */ |
||
1270 | public function setIP( $ip ) { |
||
1273 | |||
1274 | /** |
||
1275 | * Check if this request uses a "safe" HTTP method |
||
1276 | * |
||
1277 | * Safe methods are verbs (e.g. GET/HEAD/OPTIONS) used for obtaining content. Such requests |
||
1278 | * are not expected to mutate content, especially in ways attributable to the client. Verbs |
||
1279 | * like POST and PUT are typical of non-safe requests which often change content. |
||
1280 | * |
||
1281 | * @return bool |
||
1282 | * @see https://tools.ietf.org/html/rfc7231#section-4.2.1 |
||
1283 | * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html |
||
1284 | * @since 1.28 |
||
1285 | */ |
||
1286 | public function hasSafeMethod() { |
||
1293 | |||
1294 | /** |
||
1295 | * Whether this request should be identified as being "safe" |
||
1296 | * |
||
1297 | * This means that the client is not requesting any state changes and that database writes |
||
1298 | * are not inherently required. Ideally, no visible updates would happen at all. If they |
||
1299 | * must, then they should not be publically attributed to the end user. |
||
1300 | * |
||
1301 | * In more detail: |
||
1302 | * - Cache populations and refreshes MAY occur. |
||
1303 | * - Private user session updates and private server logging MAY occur. |
||
1304 | * - Updates to private viewing activity data MAY occur via DeferredUpdates. |
||
1305 | * - Other updates SHOULD NOT occur (e.g. modifying content assets). |
||
1306 | * |
||
1307 | * @return bool |
||
1308 | * @see https://tools.ietf.org/html/rfc7231#section-4.2.1 |
||
1309 | * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html |
||
1310 | * @since 1.28 |
||
1311 | */ |
||
1312 | public function isSafeRequest() { |
||
1319 | |||
1320 | /** |
||
1321 | * Mark this request as identified as being nullipotent even if it is a POST request |
||
1322 | * |
||
1323 | * POST requests are often used due to the need for a client payload, even if the request |
||
1324 | * is otherwise equivalent to a "safe method" request. |
||
1325 | * |
||
1326 | * @see https://tools.ietf.org/html/rfc7231#section-4.2.1 |
||
1327 | * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html |
||
1328 | * @since 1.28 |
||
1329 | */ |
||
1330 | public function markAsSafeRequest() { |
||
1333 | } |
||
1334 |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.