Skip to content

Commit d2694a7

Browse files
authored
docs: [skip ci] improve documentation (#11)
1 parent a1b35f4 commit d2694a7

File tree

3 files changed

+77
-6
lines changed

3 files changed

+77
-6
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ It contains the following methods:
5757
First, you need to replace the `request` component in the configuration:
5858

5959
```php
60-
<?php
61-
6260
use MSpirkov\Yii2\Web\Request;
6361

6462
return [

src/CookieManager.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,26 @@
1212
/**
1313
* A utility class for managing cookies.
1414
*
15-
* This class encapsulates the logic for adding, removing, checking existence, and
16-
* retrieving cookies, using the {@see Request} and {@see Response}
17-
* objects. It simplifies working with cookies by abstracting implementation details
18-
* and providing more convenient methods.
15+
* This class encapsulates the logic for adding, removing, checking existence, and retrieving cookies,
16+
* using the {@see Request} and {@see Response} objects. It simplifies working with cookies by
17+
* abstracting implementation details and providing more convenient methods.
18+
*
19+
* It contains the following methods:
20+
*
21+
* - {@see CookieManager::has()} - checks if a cookie with the specified name exists.
22+
* - {@see CookieManager::get()} - returns the cookie with the specified name.
23+
* - {@see CookieManager::add()} - adds a cookie to the response.
24+
* - {@see CookieManager::remove()} - removes a cookie.
25+
* - {@see CookieManager::removeAll()} - removes all cookies.
26+
*
27+
* Usage example:
28+
*
29+
* ```
30+
* $this->cookieManager->add([
31+
* 'name' => 'someCookieName',
32+
* 'value' => 'someCookieValue',
33+
* ]);
34+
* ```
1935
*
2036
* @author Maksim Spirkov <spirkov.2001@mail.ru>
2137
*

src/Request.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,63 @@
1010
/**
1111
* A wrapper for {@see BaseRequest} for easier handling of GET and POST parameters.
1212
*
13+
* It contains the following methods:
14+
*
15+
* - {@see Request::getGetInt()} - gets the value of a **GET** parameter by its name and tries to
16+
* convert it to an integer.
17+
* - {@see Request::getGetFloat()} - gets the value of the **GET** parameter by its name and tries to
18+
* convert it to a floating-point number.
19+
* - {@see Request::getGetBool()} - gets the value of the **GET** parameter by its name and tries to
20+
* convert it to a boolean.
21+
* - {@see Request::getGetString()} - gets the value of the **GET** parameter by its name and tries to
22+
* convert it to a string.
23+
* - {@see Request::getGetArray()} - gets the value of the **GET** parameter by its name and tries to
24+
* convert it to an array.
25+
* - {@see Request::getPostInt()} - gets the value of a **POST** parameter by its name and tries to
26+
* convert it to an integer.
27+
* - {@see Request::getPostFloat()} - gets the value of the **POST** parameter by its name and tries to
28+
* convert it to a floating-point number.
29+
* - {@see Request::getPostBool()} - gets the value of the **POST** parameter by its name and tries to
30+
* convert it to a boolean.
31+
* - {@see Request::getPostString()} - gets the value of the **POST** parameter by its name and tries to
32+
* convert it to a string.
33+
* - {@see Request::getPostArray()} - gets the value of the **POST** parameter by its name and checks that
34+
* the value is an array.
35+
*
36+
* To use it, you need to replace the `request` component in the configuration:
37+
38+
* ```
39+
* use MSpirkov\Yii2\Web\Request;
40+
*
41+
* return [
42+
* ...
43+
* 'components' => [
44+
* 'request' => [
45+
* 'class' => Request::class,
46+
* ...
47+
* ],
48+
* ...
49+
* ],
50+
* ];
51+
* ```
52+
*
53+
* Usage example:
54+
*
55+
* ```
56+
* use yii\web\Controller;
57+
*
58+
* class ProductController extends Controller
59+
* {
60+
* public function actionDelete(): array
61+
* {
62+
* $id = $this->request->getPostInt('id');
63+
*
64+
* // There's some logic here. For example, calling a service class method to delete
65+
* // a product with the parameter `$id`.
66+
* }
67+
* }
68+
* ```
69+
*
1370
* @author Maksim Spirkov <spirkov.2001@mail.ru>
1471
*/
1572
class Request extends BaseRequest

0 commit comments

Comments
 (0)