Complex classes like Request 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 Request, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
104 | class Request extends \yii\base\Request implements ServerRequestInterface |
||
105 | { |
||
106 | use MessageTrait; |
||
107 | |||
108 | /** |
||
109 | * The name of the HTTP header for sending CSRF token. |
||
110 | */ |
||
111 | const CSRF_HEADER = 'X-CSRF-Token'; |
||
112 | /** |
||
113 | * The length of the CSRF token mask. |
||
114 | * @deprecated 2.0.12 The mask length is now equal to the token length. |
||
115 | */ |
||
116 | const CSRF_MASK_LENGTH = 8; |
||
117 | |||
118 | /** |
||
119 | * @var bool whether to enable CSRF (Cross-Site Request Forgery) validation. Defaults to true. |
||
120 | * When CSRF validation is enabled, forms submitted to an Yii Web application must be originated |
||
121 | * from the same application. If not, a 400 HTTP exception will be raised. |
||
122 | * |
||
123 | * Note, this feature requires that the user client accepts cookie. Also, to use this feature, |
||
124 | * forms submitted via POST method must contain a hidden input whose name is specified by [[csrfParam]]. |
||
125 | * You may use [[\yii\helpers\Html::beginForm()]] to generate his hidden input. |
||
126 | * |
||
127 | * In JavaScript, you may get the values of [[csrfParam]] and [[csrfToken]] via `yii.getCsrfParam()` and |
||
128 | * `yii.getCsrfToken()`, respectively. The [[\yii\web\YiiAsset]] asset must be registered. |
||
129 | * You also need to include CSRF meta tags in your pages by using [[\yii\helpers\Html::csrfMetaTags()]]. |
||
130 | * |
||
131 | * @see Controller::enableCsrfValidation |
||
132 | * @see http://en.wikipedia.org/wiki/Cross-site_request_forgery |
||
133 | */ |
||
134 | public $enableCsrfValidation = true; |
||
135 | /** |
||
136 | * @var string the name of the token used to prevent CSRF. Defaults to '_csrf'. |
||
137 | * This property is used only when [[enableCsrfValidation]] is true. |
||
138 | */ |
||
139 | public $csrfParam = '_csrf'; |
||
140 | /** |
||
141 | * @var array the configuration for creating the CSRF [[Cookie|cookie]]. This property is used only when |
||
142 | * both [[enableCsrfValidation]] and [[enableCsrfCookie]] are true. |
||
143 | */ |
||
144 | public $csrfCookie = ['httpOnly' => true]; |
||
145 | /** |
||
146 | * @var bool whether to use cookie to persist CSRF token. If false, CSRF token will be stored |
||
147 | * in session under the name of [[csrfParam]]. Note that while storing CSRF tokens in session increases |
||
148 | * security, it requires starting a session for every page, which will degrade your site performance. |
||
149 | */ |
||
150 | public $enableCsrfCookie = true; |
||
151 | /** |
||
152 | * @var bool whether cookies should be validated to ensure they are not tampered. Defaults to true. |
||
153 | */ |
||
154 | public $enableCookieValidation = true; |
||
155 | /** |
||
156 | * @var string a secret key used for cookie validation. This property must be set if [[enableCookieValidation]] is true. |
||
157 | */ |
||
158 | public $cookieValidationKey; |
||
159 | /** |
||
160 | * @var string the name of the POST parameter that is used to indicate if a request is a PUT, PATCH or DELETE |
||
161 | * request tunneled through POST. Defaults to '_method'. |
||
162 | * @see getMethod() |
||
163 | * @see getParsedBody() |
||
164 | */ |
||
165 | public $methodParam = '_method'; |
||
166 | /** |
||
167 | * @var array the parsers for converting the raw HTTP request body into [[bodyParams]]. |
||
168 | * The array keys are the request `Content-Types`, and the array values are the |
||
169 | * corresponding configurations for [[Yii::createObject|creating the parser objects]]. |
||
170 | * A parser must implement the [[RequestParserInterface]]. |
||
171 | * |
||
172 | * To enable parsing for JSON requests you can use the [[JsonParser]] class like in the following example: |
||
173 | * |
||
174 | * ``` |
||
175 | * [ |
||
176 | * 'application/json' => \yii\web\JsonParser::class, |
||
177 | * ] |
||
178 | * ``` |
||
179 | * |
||
180 | * To register a parser for parsing all request types you can use `'*'` as the array key. |
||
181 | * This one will be used as a fallback in case no other types match. |
||
182 | * |
||
183 | * @see getParsedBody() |
||
184 | */ |
||
185 | public $parsers = []; |
||
186 | /** |
||
187 | * @var string name of the class to be used for uploaded file instantiation. |
||
188 | * This class should implement [[UploadedFileInterface]]. |
||
189 | * @since 2.1.0 |
||
190 | */ |
||
191 | public $uploadedFileClass = UploadedFile::class; |
||
192 | /** |
||
193 | * @var array the configuration for trusted security related headers. |
||
194 | * |
||
195 | * An array key is an IPv4 or IPv6 IP address in CIDR notation for matching a client. |
||
196 | * |
||
197 | * An array value is a list of headers to trust. These will be matched against |
||
198 | * [[secureHeaders]] to determine which headers are allowed to be sent by a specified host. |
||
199 | * The case of the header names must be the same as specified in [[secureHeaders]]. |
||
200 | * |
||
201 | * For example, to trust all headers listed in [[secureHeaders]] for IP addresses |
||
202 | * in range `192.168.0.0-192.168.0.254` write the following: |
||
203 | * |
||
204 | * ```php |
||
205 | * [ |
||
206 | * '192.168.0.0/24', |
||
207 | * ] |
||
208 | * ``` |
||
209 | * |
||
210 | * To trust just the `X-Forwarded-For` header from `10.0.0.1`, use: |
||
211 | * |
||
212 | * ``` |
||
213 | * [ |
||
214 | * '10.0.0.1' => ['X-Forwarded-For'] |
||
215 | * ] |
||
216 | * ``` |
||
217 | * |
||
218 | * Default is to trust all headers except those listed in [[secureHeaders]] from all hosts. |
||
219 | * Matches are tried in order and searching is stopped when IP matches. |
||
220 | * |
||
221 | * > Info: Matching is performed using [[IpValidator]]. |
||
222 | * See [[IpValidator::::setRanges()|IpValidator::setRanges()]] |
||
223 | * and [[IpValidator::networks]] for advanced matching. |
||
224 | * |
||
225 | * @see $secureHeaders |
||
226 | * @since 2.0.13 |
||
227 | */ |
||
228 | public $trustedHosts = []; |
||
229 | /** |
||
230 | * @var array lists of headers that are, by default, subject to the trusted host configuration. |
||
231 | * These headers will be filtered unless explicitly allowed in [[trustedHosts]]. |
||
232 | * The match of header names is case-insensitive. |
||
233 | * @see https://en.wikipedia.org/wiki/List_of_HTTP_header_fields |
||
234 | * @see $trustedHosts |
||
235 | * @since 2.0.13 |
||
236 | */ |
||
237 | public $secureHeaders = [ |
||
238 | // Common: |
||
239 | 'X-Forwarded-For', |
||
240 | 'X-Forwarded-Host', |
||
241 | 'X-Forwarded-Proto', |
||
242 | |||
243 | // Microsoft: |
||
244 | 'Front-End-Https', |
||
245 | 'X-Rewrite-Url', |
||
246 | ]; |
||
247 | /** |
||
248 | * @var string[] List of headers where proxies store the real client IP. |
||
249 | * It's not advisable to put insecure headers here. |
||
250 | * The match of header names is case-insensitive. |
||
251 | * @see $trustedHosts |
||
252 | * @see $secureHeaders |
||
253 | * @since 2.0.13 |
||
254 | */ |
||
255 | public $ipHeaders = [ |
||
256 | 'X-Forwarded-For', // Common |
||
257 | ]; |
||
258 | /** |
||
259 | * @var array list of headers to check for determining whether the connection is made via HTTPS. |
||
260 | * The array keys are header names and the array value is a list of header values that indicate a secure connection. |
||
261 | * The match of header names and values is case-insensitive. |
||
262 | * It's not advisable to put insecure headers here. |
||
263 | * @see $trustedHosts |
||
264 | * @see $secureHeaders |
||
265 | * @since 2.0.13 |
||
266 | */ |
||
267 | public $secureProtocolHeaders = [ |
||
268 | 'X-Forwarded-Proto' => ['https'], // Common |
||
269 | 'Front-End-Https' => ['on'], // Microsoft |
||
270 | ]; |
||
271 | |||
272 | /** |
||
273 | * @var array attributes derived from the request. |
||
274 | * @since 2.1.0 |
||
275 | */ |
||
276 | private $_attributes; |
||
277 | /** |
||
278 | * @var array server parameters. |
||
279 | * @since 2.1.0 |
||
280 | */ |
||
281 | private $_serverParams; |
||
282 | /** |
||
283 | * @var array the cookies sent by the client to the server. |
||
284 | * @since 2.1.0 |
||
285 | */ |
||
286 | private $_cookieParams; |
||
287 | /** |
||
288 | * @var CookieCollection Collection of request cookies. |
||
289 | */ |
||
290 | private $_cookies; |
||
291 | /** |
||
292 | * @var string the HTTP method of the request. |
||
293 | */ |
||
294 | private $_method; |
||
295 | /** |
||
296 | * @var UriInterface the URI instance associated with request. |
||
297 | */ |
||
298 | private $_uri; |
||
299 | /** |
||
300 | * @var mixed the message's request target. |
||
301 | */ |
||
302 | private $_requestTarget; |
||
303 | /** |
||
304 | * @var array uploaded files. |
||
305 | * @since 2.1.0 |
||
306 | */ |
||
307 | private $_uploadedFiles; |
||
308 | |||
309 | |||
310 | /** |
||
311 | * Resolves the current request into a route and the associated parameters. |
||
312 | * @return array the first element is the route, and the second is the associated parameters. |
||
313 | * @throws NotFoundHttpException if the request cannot be resolved. |
||
314 | */ |
||
315 | 1 | public function resolve() |
|
331 | |||
332 | /** |
||
333 | * Filters headers according to the [[trustedHosts]]. |
||
334 | * @param array $rawHeaders |
||
335 | * @return array filtered headers |
||
336 | * @since 2.0.13 |
||
337 | */ |
||
338 | 142 | protected function filterHeaders($rawHeaders) |
|
371 | |||
372 | /** |
||
373 | * Creates instance of [[IpValidator]]. |
||
374 | * You can override this method to adjust validator or implement different matching strategy. |
||
375 | * |
||
376 | * @return IpValidator |
||
377 | * @since 2.0.13 |
||
378 | */ |
||
379 | 24 | protected function getIpValidator() |
|
383 | |||
384 | /** |
||
385 | * Returns default message's headers, which should be present once [[headerCollection]] is instantiated. |
||
386 | * @return string[][] an associative array of the message's headers. |
||
387 | */ |
||
388 | 142 | protected function defaultHeaders() |
|
406 | |||
407 | /** |
||
408 | * {@inheritdoc} |
||
409 | * @since 2.1.0 |
||
410 | */ |
||
411 | public function getRequestTarget() |
||
418 | |||
419 | /** |
||
420 | * Specifies the message's request target |
||
421 | * @param mixed $requestTarget the message's request target. |
||
422 | * @since 2.1.0 |
||
423 | */ |
||
424 | public function setRequestTarget($requestTarget) |
||
428 | |||
429 | /** |
||
430 | * {@inheritdoc} |
||
431 | * @since 2.1.0 |
||
432 | */ |
||
433 | public function withRequestTarget($requestTarget) |
||
443 | |||
444 | /** |
||
445 | * {@inheritdoc} |
||
446 | */ |
||
447 | 50 | public function getMethod() |
|
460 | |||
461 | /** |
||
462 | * Specifies request HTTP method. |
||
463 | * @param string $method case-sensitive HTTP method. |
||
464 | * @since 2.1.0 |
||
465 | */ |
||
466 | 11 | public function setMethod($method) |
|
470 | |||
471 | /** |
||
472 | * {@inheritdoc} |
||
473 | * @since 2.1.0 |
||
474 | */ |
||
475 | 1 | public function withMethod($method) |
|
485 | |||
486 | /** |
||
487 | * {@inheritdoc} |
||
488 | * @since 2.1.0 |
||
489 | */ |
||
490 | public function getUri() |
||
505 | |||
506 | /** |
||
507 | * Specifies the URI instance. |
||
508 | * @param UriInterface|\Closure|array $uri URI instance or its DI compatible configuration. |
||
509 | * @since 2.1.0 |
||
510 | */ |
||
511 | public function setUri($uri) |
||
515 | |||
516 | /** |
||
517 | * {@inheritdoc} |
||
518 | * @since 2.1.0 |
||
519 | */ |
||
520 | public function withUri(UriInterface $uri, $preserveHost = false) |
||
534 | |||
535 | /** |
||
536 | * Returns whether this is a GET request. |
||
537 | * @return bool whether this is a GET request. |
||
538 | */ |
||
539 | 2 | public function getIsGet() |
|
543 | |||
544 | /** |
||
545 | * Returns whether this is an OPTIONS request. |
||
546 | * @return bool whether this is a OPTIONS request. |
||
547 | */ |
||
548 | 1 | public function getIsOptions() |
|
552 | |||
553 | /** |
||
554 | * Returns whether this is a HEAD request. |
||
555 | * @return bool whether this is a HEAD request. |
||
556 | */ |
||
557 | public function getIsHead() |
||
558 | { |
||
559 | return $this->getMethod() === 'HEAD'; |
||
560 | } |
||
561 | |||
562 | /** |
||
563 | * Returns whether this is a POST request. |
||
564 | * @return bool whether this is a POST request. |
||
565 | */ |
||
566 | public function getIsPost() |
||
570 | |||
571 | /** |
||
572 | * Returns whether this is a DELETE request. |
||
573 | * @return bool whether this is a DELETE request. |
||
574 | */ |
||
575 | public function getIsDelete() |
||
579 | |||
580 | /** |
||
581 | * Returns whether this is a PUT request. |
||
582 | * @return bool whether this is a PUT request. |
||
583 | */ |
||
584 | public function getIsPut() |
||
588 | |||
589 | /** |
||
590 | * Returns whether this is a PATCH request. |
||
591 | * @return bool whether this is a PATCH request. |
||
592 | */ |
||
593 | public function getIsPatch() |
||
597 | |||
598 | /** |
||
599 | * Returns whether this is an AJAX (XMLHttpRequest) request. |
||
600 | * |
||
601 | * Note that jQuery doesn't set the header in case of cross domain |
||
602 | * requests: https://stackoverflow.com/questions/8163703/cross-domain-ajax-doesnt-send-x-requested-with-header |
||
603 | * |
||
604 | * @return bool whether this is an AJAX (XMLHttpRequest) request. |
||
605 | */ |
||
606 | 15 | public function getIsAjax() |
|
610 | |||
611 | /** |
||
612 | * Returns whether this is a PJAX request |
||
613 | * @return bool whether this is a PJAX request |
||
614 | */ |
||
615 | 3 | public function getIsPjax() |
|
619 | |||
620 | /** |
||
621 | * Returns whether this is an Adobe Flash or Flex request. |
||
622 | * @return bool whether this is an Adobe Flash or Adobe Flex request. |
||
623 | */ |
||
624 | public function getIsFlash() |
||
632 | |||
633 | /** |
||
634 | * Returns default message body to be used in case it is not explicitly set. |
||
635 | * @return StreamInterface default body instance. |
||
636 | */ |
||
637 | protected function defaultBody() |
||
644 | |||
645 | /** |
||
646 | * Returns the raw HTTP request body. |
||
647 | * @return string the request body |
||
648 | */ |
||
649 | public function getRawBody() |
||
653 | |||
654 | /** |
||
655 | * Sets the raw HTTP request body, this method is mainly used by test scripts to simulate raw HTTP requests. |
||
656 | * @param string $rawBody the request body |
||
657 | */ |
||
658 | 6 | public function setRawBody($rawBody) |
|
664 | |||
665 | private $_parsedBody; |
||
666 | |||
667 | /** |
||
668 | * Returns the request parameters given in the request body. |
||
669 | * |
||
670 | * Request parameters are determined using the parsers configured in [[parsers]] property. |
||
671 | * If no parsers are configured for the current [[contentType]] it uses the PHP function `mb_parse_str()` |
||
672 | * to parse the [[rawBody|request body]]. |
||
673 | * |
||
674 | * Since 2.1.0 body params also include result of [[getUploadedFiles()]]. |
||
675 | * |
||
676 | * @return array the request parameters given in the request body. |
||
677 | * @throws InvalidConfigException if a registered parser does not implement the [[RequestParserInterface]]. |
||
678 | * @throws UnsupportedMediaTypeHttpException if unable to parse raw body. |
||
679 | * @see getMethod() |
||
680 | * @see getParsedBodyParam() |
||
681 | * @see setParsedBody() |
||
682 | */ |
||
683 | 12 | public function getParsedBody() |
|
731 | |||
732 | /** |
||
733 | * Sets the request body parameters. |
||
734 | * @param array $values the request body parameters (name-value pairs) |
||
735 | * @see getParsedBodyParam() |
||
736 | * @see getParsedBody() |
||
737 | */ |
||
738 | 4 | public function setParsedBody($values) |
|
742 | |||
743 | /** |
||
744 | * {@inheritdoc} |
||
745 | * @since 2.1.0 |
||
746 | */ |
||
747 | public function withParsedBody($data) |
||
753 | |||
754 | /** |
||
755 | * Returns the named request body parameter value. |
||
756 | * If the parameter does not exist, the second parameter passed to this method will be returned. |
||
757 | * @param string $name the parameter name |
||
758 | * @param mixed $defaultValue the default parameter value if the parameter does not exist. |
||
759 | * @return mixed the parameter value |
||
760 | * @see getParsedBody() |
||
761 | * @see setParsedBody() |
||
762 | */ |
||
763 | 5 | public function getParsedBodyParam($name, $defaultValue = null) |
|
778 | |||
779 | /** |
||
780 | * Returns POST parameter with a given name. If name isn't specified, returns an array of all POST parameters. |
||
781 | * |
||
782 | * @param string $name the parameter name |
||
783 | * @param mixed $defaultValue the default parameter value if the parameter does not exist. |
||
784 | * @return array|mixed |
||
785 | */ |
||
786 | public function post($name = null, $defaultValue = null) |
||
794 | |||
795 | private $_queryParams; |
||
796 | |||
797 | /** |
||
798 | * Returns the request parameters given in the [[queryString]]. |
||
799 | * |
||
800 | * This method will return the contents of `$_GET` if params where not explicitly set. |
||
801 | * @return array the request GET parameter values. |
||
802 | * @see setQueryParams() |
||
803 | */ |
||
804 | 18 | public function getQueryParams() |
|
812 | |||
813 | /** |
||
814 | * Sets the request [[queryString]] parameters. |
||
815 | * @param array $values the request query parameters (name-value pairs) |
||
816 | * @see getQueryParam() |
||
817 | * @see getQueryParams() |
||
818 | */ |
||
819 | 5 | public function setQueryParams($values) |
|
823 | |||
824 | /** |
||
825 | * {@inheritdoc} |
||
826 | */ |
||
827 | public function withQueryParams(array $query) |
||
837 | |||
838 | /** |
||
839 | * Returns GET parameter with a given name. If name isn't specified, returns an array of all GET parameters. |
||
840 | * |
||
841 | * @param string $name the parameter name |
||
842 | * @param mixed $defaultValue the default parameter value if the parameter does not exist. |
||
843 | * @return array|mixed |
||
844 | */ |
||
845 | 6 | public function get($name = null, $defaultValue = null) |
|
853 | |||
854 | /** |
||
855 | * Returns the named GET parameter value. |
||
856 | * If the GET parameter does not exist, the second parameter passed to this method will be returned. |
||
857 | * @param string $name the GET parameter name. |
||
858 | * @param mixed $defaultValue the default parameter value if the GET parameter does not exist. |
||
859 | * @return mixed the GET parameter value |
||
860 | * @see getParsedBodyParam() |
||
861 | */ |
||
862 | 9 | public function getQueryParam($name, $defaultValue = null) |
|
868 | |||
869 | /** |
||
870 | * Sets the data related to the incoming request environment. |
||
871 | * @param array $serverParams server parameters. |
||
872 | * @since 2.1.0 |
||
873 | */ |
||
874 | 4 | public function setServerParams(array $serverParams) |
|
878 | |||
879 | /** |
||
880 | * {@inheritdoc} |
||
881 | * @since 2.1.0 |
||
882 | */ |
||
883 | 122 | public function getServerParams() |
|
890 | |||
891 | /** |
||
892 | * Return the server environment parameter by name. |
||
893 | * @param string $name parameter name. |
||
894 | * @param mixed $default default value to return if the parameter does not exist. |
||
895 | * @return mixed parameter value. |
||
896 | * @since 2.1.0 |
||
897 | */ |
||
898 | 122 | public function getServerParam($name, $default = null) |
|
906 | |||
907 | /** |
||
908 | * Specifies cookies. |
||
909 | * @param array $cookies array of key/value pairs representing cookies. |
||
910 | * @since 2.1.0 |
||
911 | */ |
||
912 | public function setCookieParams(array $cookies) |
||
917 | |||
918 | /** |
||
919 | * {@inheritdoc} |
||
920 | * @since 2.1.0 |
||
921 | */ |
||
922 | 44 | public function getCookieParams() |
|
929 | |||
930 | /** |
||
931 | * {@inheritdoc} |
||
932 | * @since 2.1.0 |
||
933 | */ |
||
934 | public function withCookieParams(array $cookies) |
||
944 | |||
945 | private $_hostInfo; |
||
946 | private $_hostName; |
||
947 | |||
948 | /** |
||
949 | * Returns the schema and host part of the current request URL. |
||
950 | * |
||
951 | * The returned URL does not have an ending slash. |
||
952 | * |
||
953 | * By default this value is based on the user request information. This method will |
||
954 | * return the value of `$_SERVER['HTTP_HOST']` if it is available or `$_SERVER['SERVER_NAME']` if not. |
||
955 | * You may want to check out the [PHP documentation](http://php.net/manual/en/reserved.variables.server.php) |
||
956 | * for more information on these variables. |
||
957 | * |
||
958 | * You may explicitly specify it by setting the [[setHostInfo()|hostInfo]] property. |
||
959 | * |
||
960 | * > Warning: Dependent on the server configuration this information may not be |
||
961 | * > reliable and [may be faked by the user sending the HTTP request](https://www.acunetix.com/vulnerabilities/web/host-header-attack). |
||
962 | * > If the webserver is configured to serve the same site independent of the value of |
||
963 | * > the `Host` header, this value is not reliable. In such situations you should either |
||
964 | * > fix your webserver configuration or explicitly set the value by setting the [[setHostInfo()|hostInfo]] property. |
||
965 | * > If you don't have access to the server configuration, you can setup [[\yii\filters\HostControl]] filter at |
||
966 | * > application level in order to protect against such kind of attack. |
||
967 | * |
||
968 | * @property string|null schema and hostname part (with port number if needed) of the request URL |
||
969 | * (e.g. `http://www.yiiframework.com`), null if can't be obtained from `$_SERVER` and wasn't set. |
||
970 | * See [[getHostInfo()]] for security related notes on this property. |
||
971 | * @return string|null schema and hostname part (with port number if needed) of the request URL |
||
972 | * (e.g. `http://www.yiiframework.com`), null if can't be obtained from `$_SERVER` and wasn't set. |
||
973 | * @see setHostInfo() |
||
974 | */ |
||
975 | 23 | public function getHostInfo() |
|
996 | |||
997 | /** |
||
998 | * Sets the schema and host part of the application URL. |
||
999 | * This setter is provided in case the schema and hostname cannot be determined |
||
1000 | * on certain Web servers. |
||
1001 | * @param string|null $value the schema and host part of the application URL. The trailing slashes will be removed. |
||
1002 | * @see getHostInfo() for security related notes on this property. |
||
1003 | */ |
||
1004 | 47 | public function setHostInfo($value) |
|
1009 | |||
1010 | /** |
||
1011 | * Returns the host part of the current request URL. |
||
1012 | * Value is calculated from current [[getHostInfo()|hostInfo]] property. |
||
1013 | * |
||
1014 | * > Warning: The content of this value may not be reliable, dependent on the server |
||
1015 | * > configuration. Please refer to [[getHostInfo()]] for more information. |
||
1016 | * |
||
1017 | * @return string|null hostname part of the request URL (e.g. `www.yiiframework.com`) |
||
1018 | * @see getHostInfo() |
||
1019 | * @since 2.0.10 |
||
1020 | */ |
||
1021 | 16 | public function getHostName() |
|
1029 | |||
1030 | private $_baseUrl; |
||
1031 | |||
1032 | /** |
||
1033 | * Returns the relative URL for the application. |
||
1034 | * This is similar to [[scriptUrl]] except that it does not include the script file name, |
||
1035 | * and the ending slashes are removed. |
||
1036 | * @return string the relative URL for the application |
||
1037 | * @see setScriptUrl() |
||
1038 | */ |
||
1039 | 254 | public function getBaseUrl() |
|
1047 | |||
1048 | /** |
||
1049 | * Sets the relative URL for the application. |
||
1050 | * By default the URL is determined based on the entry script URL. |
||
1051 | * This setter is provided in case you want to change this behavior. |
||
1052 | * @param string $value the relative URL for the application |
||
1053 | */ |
||
1054 | 1 | public function setBaseUrl($value) |
|
1058 | |||
1059 | private $_scriptUrl; |
||
1060 | |||
1061 | /** |
||
1062 | * Returns the relative URL of the entry script. |
||
1063 | * The implementation of this method referenced Zend_Controller_Request_Http in Zend Framework. |
||
1064 | * @return string the relative URL of the entry script. |
||
1065 | * @throws InvalidConfigException if unable to determine the entry script URL |
||
1066 | */ |
||
1067 | 255 | public function getScriptUrl() |
|
1090 | |||
1091 | /** |
||
1092 | * Sets the relative URL for the application entry script. |
||
1093 | * This setter is provided in case the entry script URL cannot be determined |
||
1094 | * on certain Web servers. |
||
1095 | * @param string $value the relative URL for the application entry script. |
||
1096 | */ |
||
1097 | 265 | public function setScriptUrl($value) |
|
1101 | |||
1102 | private $_scriptFile; |
||
1103 | |||
1104 | /** |
||
1105 | * Returns the entry script file path. |
||
1106 | * The default implementation will simply return `$_SERVER['SCRIPT_FILENAME']`. |
||
1107 | * @return string the entry script file path |
||
1108 | * @throws InvalidConfigException |
||
1109 | */ |
||
1110 | 256 | public function getScriptFile() |
|
1122 | |||
1123 | /** |
||
1124 | * Sets the entry script file path. |
||
1125 | * The entry script file path normally can be obtained from `$_SERVER['SCRIPT_FILENAME']`. |
||
1126 | * If your server configuration does not return the correct value, you may configure |
||
1127 | * this property to make it right. |
||
1128 | * @param string $value the entry script file path. |
||
1129 | */ |
||
1130 | 244 | public function setScriptFile($value) |
|
1134 | |||
1135 | private $_pathInfo; |
||
1136 | |||
1137 | /** |
||
1138 | * Returns the path info of the currently requested URL. |
||
1139 | * A path info refers to the part that is after the entry script and before the question mark (query string). |
||
1140 | * The starting and ending slashes are both removed. |
||
1141 | * @return string part of the request URL that is after the entry script and before the question mark. |
||
1142 | * Note, the returned path info is already URL-decoded. |
||
1143 | * @throws InvalidConfigException if the path info cannot be determined due to unexpected server configuration |
||
1144 | */ |
||
1145 | 17 | public function getPathInfo() |
|
1153 | |||
1154 | /** |
||
1155 | * Sets the path info of the current request. |
||
1156 | * This method is mainly provided for testing purpose. |
||
1157 | * @param string $value the path info of the current request |
||
1158 | */ |
||
1159 | 18 | public function setPathInfo($value) |
|
1163 | |||
1164 | /** |
||
1165 | * Resolves the path info part of the currently requested URL. |
||
1166 | * A path info refers to the part that is after the entry script and before the question mark (query string). |
||
1167 | * The starting slashes are both removed (ending slashes will be kept). |
||
1168 | * @return string part of the request URL that is after the entry script and before the question mark. |
||
1169 | * Note, the returned path info is decoded. |
||
1170 | * @throws InvalidConfigException if the path info cannot be determined due to unexpected server configuration |
||
1171 | */ |
||
1172 | protected function resolvePathInfo() |
||
1216 | |||
1217 | /** |
||
1218 | * Returns the currently requested absolute URL. |
||
1219 | * This is a shortcut to the concatenation of [[hostInfo]] and [[url]]. |
||
1220 | * @return string the currently requested absolute URL. |
||
1221 | */ |
||
1222 | public function getAbsoluteUrl() |
||
1226 | |||
1227 | private $_url; |
||
1228 | |||
1229 | /** |
||
1230 | * Returns the currently requested relative URL. |
||
1231 | * This refers to the portion of the URL that is after the [[hostInfo]] part. |
||
1232 | * It includes the [[queryString]] part if any. |
||
1233 | * @return string the currently requested relative URL. Note that the URI returned may be URL-encoded depending on the client. |
||
1234 | * @throws InvalidConfigException if the URL cannot be determined due to unusual server configuration |
||
1235 | */ |
||
1236 | 9 | public function getUrl() |
|
1244 | |||
1245 | /** |
||
1246 | * Sets the currently requested relative URL. |
||
1247 | * The URI must refer to the portion that is after [[hostInfo]]. |
||
1248 | * Note that the URI should be URL-encoded. |
||
1249 | * @param string $value the request URI to be set |
||
1250 | */ |
||
1251 | 24 | public function setUrl($value) |
|
1255 | |||
1256 | /** |
||
1257 | * Resolves the request URI portion for the currently requested URL. |
||
1258 | * This refers to the portion that is after the [[hostInfo]] part. It includes the [[queryString]] part if any. |
||
1259 | * The implementation of this method referenced Zend_Controller_Request_Http in Zend Framework. |
||
1260 | * @return string|bool the request URI portion for the currently requested URL. |
||
1261 | * Note that the URI returned may be URL-encoded depending on the client. |
||
1262 | * @throws InvalidConfigException if the request URI cannot be determined due to unusual server configuration |
||
1263 | */ |
||
1264 | 2 | protected function resolveRequestUri() |
|
1286 | |||
1287 | /** |
||
1288 | * Returns part of the request URL that is after the question mark. |
||
1289 | * @return string part of the request URL that is after the question mark |
||
1290 | */ |
||
1291 | public function getQueryString() |
||
1295 | |||
1296 | /** |
||
1297 | * Return if the request is sent via secure channel (https). |
||
1298 | * @return bool if the request is sent via secure channel (https) |
||
1299 | */ |
||
1300 | 36 | public function getIsSecureConnection() |
|
1318 | |||
1319 | /** |
||
1320 | * Returns the server name. |
||
1321 | * @return string server name, null if not available |
||
1322 | */ |
||
1323 | 1 | public function getServerName() |
|
1327 | |||
1328 | /** |
||
1329 | * Returns the server port number. |
||
1330 | * @return int|null server port number, null if not available |
||
1331 | */ |
||
1332 | 2 | public function getServerPort() |
|
1337 | |||
1338 | /** |
||
1339 | * Returns the URL referrer. |
||
1340 | * @return string|null URL referrer, null if not available |
||
1341 | */ |
||
1342 | public function getReferrer() |
||
1349 | |||
1350 | /** |
||
1351 | * Returns the URL origin of a CORS request. |
||
1352 | * |
||
1353 | * The return value is taken from the `Origin` [[getHeaders()|header]] sent by the browser. |
||
1354 | * |
||
1355 | * Note that the origin request header indicates where a fetch originates from. |
||
1356 | * It doesn't include any path information, but only the server name. |
||
1357 | * It is sent with a CORS requests, as well as with POST requests. |
||
1358 | * It is similar to the referer header, but, unlike this header, it doesn't disclose the whole path. |
||
1359 | * Please refer to <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin> for more information. |
||
1360 | * |
||
1361 | * @return string|null URL origin of a CORS request, `null` if not available. |
||
1362 | * @see getHeaders() |
||
1363 | * @since 2.0.13 |
||
1364 | */ |
||
1365 | 1 | public function getOrigin() |
|
1369 | |||
1370 | /** |
||
1371 | * Returns the user agent. |
||
1372 | * @return string|null user agent, null if not available |
||
1373 | */ |
||
1374 | public function getUserAgent() |
||
1381 | |||
1382 | /** |
||
1383 | * Returns the user IP address. |
||
1384 | * The IP is determined using headers and / or `$_SERVER` variables. |
||
1385 | * @return string|null user IP address, null if not available |
||
1386 | */ |
||
1387 | 37 | public function getUserIP() |
|
1397 | |||
1398 | /** |
||
1399 | * Returns the user host name. |
||
1400 | * The HOST is determined using headers and / or `$_SERVER` variables. |
||
1401 | * @return string|null user host name, null if not available |
||
1402 | */ |
||
1403 | public function getUserHost() |
||
1413 | |||
1414 | /** |
||
1415 | * Returns the IP on the other end of this connection. |
||
1416 | * This is always the next hop, any headers are ignored. |
||
1417 | * @return string|null remote IP address, `null` if not available. |
||
1418 | * @since 2.0.13 |
||
1419 | */ |
||
1420 | 57 | public function getRemoteIP() |
|
1424 | |||
1425 | /** |
||
1426 | * Returns the host name of the other end of this connection. |
||
1427 | * This is always the next hop, any headers are ignored. |
||
1428 | * @return string|null remote host name, `null` if not available |
||
1429 | * @see getUserHost() |
||
1430 | * @see getRemoteIP() |
||
1431 | * @since 2.0.13 |
||
1432 | */ |
||
1433 | public function getRemoteHost() |
||
1437 | |||
1438 | /** |
||
1439 | * @return string|null the username sent via HTTP authentication, `null` if the username is not given |
||
1440 | * @see getAuthCredentials() to get both username and password in one call |
||
1441 | */ |
||
1442 | 9 | public function getAuthUser() |
|
1446 | |||
1447 | /** |
||
1448 | * @return string|null the password sent via HTTP authentication, `null` if the password is not given |
||
1449 | * @see getAuthCredentials() to get both username and password in one call |
||
1450 | */ |
||
1451 | 9 | public function getAuthPassword() |
|
1455 | |||
1456 | /** |
||
1457 | * @return array that contains exactly two elements: |
||
1458 | * - 0: the username sent via HTTP authentication, `null` if the username is not given |
||
1459 | * - 1: the password sent via HTTP authentication, `null` if the password is not given |
||
1460 | * @see getAuthUser() to get only username |
||
1461 | * @see getAuthPassword() to get only password |
||
1462 | * @since 2.0.13 |
||
1463 | */ |
||
1464 | 19 | public function getAuthCredentials() |
|
1493 | |||
1494 | private $_port; |
||
1495 | |||
1496 | /** |
||
1497 | * Returns the port to use for insecure requests. |
||
1498 | * Defaults to 80, or the port specified by the server if the current |
||
1499 | * request is insecure. |
||
1500 | * @return int port number for insecure requests. |
||
1501 | * @see setPort() |
||
1502 | */ |
||
1503 | 1 | public function getPort() |
|
1512 | |||
1513 | /** |
||
1514 | * Sets the port to use for insecure requests. |
||
1515 | * This setter is provided in case a custom port is necessary for certain |
||
1516 | * server configurations. |
||
1517 | * @param int $value port number. |
||
1518 | */ |
||
1519 | public function setPort($value) |
||
1526 | |||
1527 | private $_securePort; |
||
1528 | |||
1529 | /** |
||
1530 | * Returns the port to use for secure requests. |
||
1531 | * Defaults to 443, or the port specified by the server if the current |
||
1532 | * request is secure. |
||
1533 | * @return int port number for secure requests. |
||
1534 | * @see setSecurePort() |
||
1535 | */ |
||
1536 | public function getSecurePort() |
||
1545 | |||
1546 | /** |
||
1547 | * Sets the port to use for secure requests. |
||
1548 | * This setter is provided in case a custom port is necessary for certain |
||
1549 | * server configurations. |
||
1550 | * @param int $value port number. |
||
1551 | */ |
||
1552 | public function setSecurePort($value) |
||
1559 | |||
1560 | private $_contentTypes; |
||
1561 | |||
1562 | /** |
||
1563 | * Returns the content types acceptable by the end user. |
||
1564 | * |
||
1565 | * This is determined by the `Accept` HTTP header. For example, |
||
1566 | * |
||
1567 | * ```php |
||
1568 | * $_SERVER['HTTP_ACCEPT'] = 'text/plain; q=0.5, application/json; version=1.0, application/xml; version=2.0;'; |
||
1569 | * $types = $request->getAcceptableContentTypes(); |
||
1570 | * print_r($types); |
||
1571 | * // displays: |
||
1572 | * // [ |
||
1573 | * // 'application/json' => ['q' => 1, 'version' => '1.0'], |
||
1574 | * // 'application/xml' => ['q' => 1, 'version' => '2.0'], |
||
1575 | * // 'text/plain' => ['q' => 0.5], |
||
1576 | * // ] |
||
1577 | * ``` |
||
1578 | * |
||
1579 | * @return array the content types ordered by the quality score. Types with the highest scores |
||
1580 | * will be returned first. The array keys are the content types, while the array values |
||
1581 | * are the corresponding quality score and other parameters as given in the header. |
||
1582 | */ |
||
1583 | 3 | public function getAcceptableContentTypes() |
|
1595 | |||
1596 | /** |
||
1597 | * Sets the acceptable content types. |
||
1598 | * Please refer to [[getAcceptableContentTypes()]] on the format of the parameter. |
||
1599 | * @param array $value the content types that are acceptable by the end user. They should |
||
1600 | * be ordered by the preference level. |
||
1601 | * @see getAcceptableContentTypes() |
||
1602 | * @see parseAcceptHeader() |
||
1603 | */ |
||
1604 | 1 | public function setAcceptableContentTypes($value) |
|
1608 | |||
1609 | /** |
||
1610 | * Returns request content-type |
||
1611 | * The Content-Type header field indicates the MIME type of the data |
||
1612 | * contained in [[getBody()]] or, in the case of the HEAD method, the |
||
1613 | * media type that would have been sent had the request been a GET. |
||
1614 | * For the MIME-types the user expects in response, see [[acceptableContentTypes]]. |
||
1615 | * @return string request content-type. Empty string is returned if this information is not available. |
||
1616 | * @link https://tools.ietf.org/html/rfc2616#section-14.17 |
||
1617 | * HTTP 1.1 header field definitions |
||
1618 | */ |
||
1619 | 12 | public function getContentType() |
|
1623 | |||
1624 | private $_languages; |
||
1625 | |||
1626 | /** |
||
1627 | * Returns the languages acceptable by the end user. |
||
1628 | * This is determined by the `Accept-Language` HTTP header. |
||
1629 | * @return array the languages ordered by the preference level. The first element |
||
1630 | * represents the most preferred language. |
||
1631 | */ |
||
1632 | 1 | public function getAcceptableLanguages() |
|
1644 | |||
1645 | /** |
||
1646 | * @param array $value the languages that are acceptable by the end user. They should |
||
1647 | * be ordered by the preference level. |
||
1648 | */ |
||
1649 | 1 | public function setAcceptableLanguages($value) |
|
1653 | |||
1654 | /** |
||
1655 | * Parses the given `Accept` (or `Accept-Language`) header. |
||
1656 | * |
||
1657 | * This method will return the acceptable values with their quality scores and the corresponding parameters |
||
1658 | * as specified in the given `Accept` header. The array keys of the return value are the acceptable values, |
||
1659 | * while the array values consisting of the corresponding quality scores and parameters. The acceptable |
||
1660 | * values with the highest quality scores will be returned first. For example, |
||
1661 | * |
||
1662 | * ```php |
||
1663 | * $header = 'text/plain; q=0.5, application/json; version=1.0, application/xml; version=2.0;'; |
||
1664 | * $accepts = $request->parseAcceptHeader($header); |
||
1665 | * print_r($accepts); |
||
1666 | * // displays: |
||
1667 | * // [ |
||
1668 | * // 'application/json' => ['q' => 1, 'version' => '1.0'], |
||
1669 | * // 'application/xml' => ['q' => 1, 'version' => '2.0'], |
||
1670 | * // 'text/plain' => ['q' => 0.5], |
||
1671 | * // ] |
||
1672 | * ``` |
||
1673 | * |
||
1674 | * @param string $header the header to be parsed |
||
1675 | * @return array the acceptable values ordered by their quality score. The values with the highest scores |
||
1676 | * will be returned first. |
||
1677 | */ |
||
1678 | 3 | public function parseAcceptHeader($header) |
|
1745 | |||
1746 | /** |
||
1747 | * Returns the user-preferred language that should be used by this application. |
||
1748 | * The language resolution is based on the user preferred languages and the languages |
||
1749 | * supported by the application. The method will try to find the best match. |
||
1750 | * @param array $languages a list of the languages supported by the application. If this is empty, the current |
||
1751 | * application language will be returned without further processing. |
||
1752 | * @return string the language that the application should use. |
||
1753 | */ |
||
1754 | 1 | public function getPreferredLanguage(array $languages = []) |
|
1776 | |||
1777 | /** |
||
1778 | * Gets the Etags. |
||
1779 | * |
||
1780 | * @return array The entity tags |
||
1781 | */ |
||
1782 | public function getETags() |
||
1790 | |||
1791 | /** |
||
1792 | * Returns the cookie collection. |
||
1793 | * |
||
1794 | * Through the returned cookie collection, you may access a cookie using the following syntax: |
||
1795 | * |
||
1796 | * ```php |
||
1797 | * $cookie = $request->cookies['name'] |
||
1798 | * if ($cookie !== null) { |
||
1799 | * $value = $cookie->value; |
||
1800 | * } |
||
1801 | * |
||
1802 | * // alternatively |
||
1803 | * $value = $request->cookies->getValue('name'); |
||
1804 | * ``` |
||
1805 | * |
||
1806 | * @return CookieCollection the cookie collection. |
||
1807 | */ |
||
1808 | 45 | public function getCookies() |
|
1818 | |||
1819 | /** |
||
1820 | * Converts [[cookieParams]] into an array of [[Cookie]]. |
||
1821 | * @return array the cookies obtained from request |
||
1822 | * @throws InvalidConfigException if [[cookieValidationKey]] is not set when [[enableCookieValidation]] is true |
||
1823 | */ |
||
1824 | 45 | protected function loadCookies() |
|
1862 | |||
1863 | /** |
||
1864 | * {@inheritdoc} |
||
1865 | * @since 2.1.0 |
||
1866 | */ |
||
1867 | 12 | public function getUploadedFiles() |
|
1877 | |||
1878 | /** |
||
1879 | * Sets uploaded files for this request. |
||
1880 | * Data structure for the uploaded files should follow [PSR-7 Uploaded Files specs](http://www.php-fig.org/psr/psr-7/#16-uploaded-files). |
||
1881 | * @param array|null $uploadedFiles uploaded files. |
||
1882 | * @since 2.1.0 |
||
1883 | */ |
||
1884 | 6 | public function setUploadedFiles($uploadedFiles) |
|
1888 | |||
1889 | /** |
||
1890 | * {@inheritdoc} |
||
1891 | * @since 2.1.0 |
||
1892 | */ |
||
1893 | public function withUploadedFiles(array $uploadedFiles) |
||
1899 | |||
1900 | /** |
||
1901 | * Initializes default uploaded files data structure parsing super-global $_FILES. |
||
1902 | * @see http://www.php-fig.org/psr/psr-7/#16-uploaded-files |
||
1903 | * @return array uploaded files. |
||
1904 | * @since 2.1.0 |
||
1905 | */ |
||
1906 | 6 | protected function defaultUploadedFiles() |
|
1916 | |||
1917 | /** |
||
1918 | * Populates uploaded files array from $_FILE data structure recursively. |
||
1919 | * @param array $files uploaded files array to be populated. |
||
1920 | * @param mixed $names file names provided by PHP |
||
1921 | * @param mixed $tempNames temporary file names provided by PHP |
||
1922 | * @param mixed $types file types provided by PHP |
||
1923 | * @param mixed $sizes file sizes provided by PHP |
||
1924 | * @param mixed $errors uploading issues provided by PHP |
||
1925 | * @since 2.1.0 |
||
1926 | */ |
||
1927 | 3 | private function populateUploadedFileRecursive(&$files, $names, $tempNames, $types, $sizes, $errors) |
|
1945 | |||
1946 | /** |
||
1947 | * Returns an uploaded file according to the given name. |
||
1948 | * Name can be either a string HTML form input name, e.g. 'Item[file]' or array path, e.g. `['Item', 'file']`. |
||
1949 | * Note: this method returns `null` in case given name matches multiple files. |
||
1950 | * @param string|array $name HTML form input name or array path. |
||
1951 | * @return UploadedFileInterface|null uploaded file instance, `null` - if not found. |
||
1952 | * @since 2.1.0 |
||
1953 | */ |
||
1954 | 1 | public function getUploadedFileByName($name) |
|
1962 | |||
1963 | /** |
||
1964 | * Returns the list of uploaded file instances according to the given name. |
||
1965 | * Name can be either a string HTML form input name, e.g. 'Item[file]' or array path, e.g. `['Item', 'file']`. |
||
1966 | * Note: this method does NOT preserve uploaded files structure - it returns instances in single-level array (list), |
||
1967 | * even if they are set by nested keys. |
||
1968 | * @param string|array $name HTML form input name or array path. |
||
1969 | * @return UploadedFileInterface[] list of uploaded file instances. |
||
1970 | * @since 2.1.0 |
||
1971 | */ |
||
1972 | 1 | public function getUploadedFilesByName($name) |
|
1983 | |||
1984 | /** |
||
1985 | * Finds the uploaded file or set of uploaded files inside [[$uploadedFiles]] according to given name. |
||
1986 | * Name can be either a string HTML form input name, e.g. 'Item[file]' or array path, e.g. `['Item', 'file']`. |
||
1987 | * @param string|array $name HTML form input name or array path. |
||
1988 | * @return UploadedFileInterface|array|null |
||
1989 | * @since 2.1.0 |
||
1990 | */ |
||
1991 | 2 | private function findUploadedFiles($name) |
|
1998 | |||
1999 | /** |
||
2000 | * Reduces complex uploaded files structure to the single-level array (list). |
||
2001 | * @param array $uploadedFiles raw set of the uploaded files. |
||
2002 | * @return UploadedFileInterface[] list of uploaded files. |
||
2003 | * @since 2.1.0 |
||
2004 | */ |
||
2005 | private function reduceUploadedFiles($uploadedFiles) |
||
2016 | |||
2017 | private $_csrfToken; |
||
2018 | |||
2019 | /** |
||
2020 | * Returns the token used to perform CSRF validation. |
||
2021 | * |
||
2022 | * This token is generated in a way to prevent [BREACH attacks](http://breachattack.com/). It may be passed |
||
2023 | * along via a hidden field of an HTML form or an HTTP header value to support CSRF validation. |
||
2024 | * @param bool $regenerate whether to regenerate CSRF token. When this parameter is true, each time |
||
2025 | * this method is called, a new CSRF token will be generated and persisted (in session or cookie). |
||
2026 | * @return string the token used to perform CSRF validation. |
||
2027 | */ |
||
2028 | 51 | public function getCsrfToken($regenerate = false) |
|
2040 | |||
2041 | /** |
||
2042 | * Loads the CSRF token from cookie or session. |
||
2043 | * @return string the CSRF token loaded from cookie or session. Null is returned if the cookie or session |
||
2044 | * does not have CSRF token. |
||
2045 | */ |
||
2046 | 51 | protected function loadCsrfToken() |
|
2054 | |||
2055 | /** |
||
2056 | * Generates an unmasked random token used to perform CSRF validation. |
||
2057 | * @return string the random token for CSRF validation. |
||
2058 | */ |
||
2059 | 47 | protected function generateCsrfToken() |
|
2071 | |||
2072 | /** |
||
2073 | * @return string the CSRF token sent via [[CSRF_HEADER]] by browser. Null is returned if no such header is sent. |
||
2074 | */ |
||
2075 | 3 | public function getCsrfTokenFromHeader() |
|
2079 | |||
2080 | /** |
||
2081 | * Creates a cookie with a randomly generated CSRF token. |
||
2082 | * Initial values specified in [[csrfCookie]] will be applied to the generated cookie. |
||
2083 | * @param string $token the CSRF token |
||
2084 | * @return Cookie the generated cookie |
||
2085 | * @see enableCsrfValidation |
||
2086 | */ |
||
2087 | 46 | protected function createCsrfCookie($token) |
|
2096 | |||
2097 | /** |
||
2098 | * Performs the CSRF validation. |
||
2099 | * |
||
2100 | * This method will validate the user-provided CSRF token by comparing it with the one stored in cookie or session. |
||
2101 | * This method is mainly called in [[Controller::beforeAction()]]. |
||
2102 | * |
||
2103 | * Note that the method will NOT perform CSRF validation if [[enableCsrfValidation]] is false or the HTTP method |
||
2104 | * is among GET, HEAD or OPTIONS. |
||
2105 | * |
||
2106 | * @param string $clientSuppliedToken the user-provided CSRF token to be validated. If null, the token will be retrieved from |
||
2107 | * the [[csrfParam]] POST field or HTTP header. |
||
2108 | * This parameter is available since version 2.0.4. |
||
2109 | * @return bool whether CSRF token is valid. If [[enableCsrfValidation]] is false, this method will return true. |
||
2110 | */ |
||
2111 | 36 | public function validateCsrfToken($clientSuppliedToken = null) |
|
2128 | |||
2129 | /** |
||
2130 | * Validates CSRF token. |
||
2131 | * |
||
2132 | * @param string $clientSuppliedToken The masked client-supplied token. |
||
2133 | * @param string $trueToken The masked true token. |
||
2134 | * @return bool |
||
2135 | */ |
||
2136 | 4 | private function validateCsrfTokenInternal($clientSuppliedToken, $trueToken) |
|
2146 | |||
2147 | /** |
||
2148 | * {@inheritdoc} |
||
2149 | * @since 2.1.0 |
||
2150 | */ |
||
2151 | 3 | public function getAttributes() |
|
2158 | |||
2159 | /** |
||
2160 | * @param array $attributes attributes derived from the request. |
||
2161 | */ |
||
2162 | 3 | public function setAttributes(array $attributes) |
|
2166 | |||
2167 | /** |
||
2168 | * {@inheritdoc} |
||
2169 | * @since 2.1.0 |
||
2170 | */ |
||
2171 | 1 | public function getAttribute($name, $default = null) |
|
2180 | |||
2181 | /** |
||
2182 | * {@inheritdoc} |
||
2183 | * @since 2.1.0 |
||
2184 | */ |
||
2185 | 1 | public function withAttribute($name, $value) |
|
2198 | |||
2199 | /** |
||
2200 | * {@inheritdoc} |
||
2201 | * @since 2.1.0 |
||
2202 | */ |
||
2203 | 1 | public function withoutAttribute($name) |
|
2216 | |||
2217 | /** |
||
2218 | * Returns default server request attributes to be used in case they are not explicitly set. |
||
2219 | * @return array attributes derived from the request. |
||
2220 | * @since 2.1.0 |
||
2221 | */ |
||
2222 | protected function defaultAttributes() |
||
2226 | |||
2227 | /** |
||
2228 | * {@inheritdoc} |
||
2229 | */ |
||
2230 | 3 | public function __clone() |
|
2240 | } |
||
2241 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.