Skip to content

Commit c9360b8

Browse files
Copilotsamdark
andcommitted
Add CHANGELOG entry and documentation for ToArrayOfIntegers
- Added CHANGELOG entry for new ToArrayOfIntegers parameter attribute - Added English documentation in docs/guide/en/typecasting.md - Added Russian documentation in docs/guide/ru/typecasting.md Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
1 parent c2a3fe1 commit c9360b8

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 1.6.4 under development
44

5-
- no changes in this release.
5+
- New #116: Add `ToArrayOfIntegers` parameter attribute (@samdark)
66

77
## 1.6.3 December 16, 2025
88

docs/guide/en/typecasting.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,21 @@ Attribute parameters:
240240
- `splitResolvedValue` — split resolved value by separator (boolean, default `true`);
241241
- `separator` — the boundary string (default, `\R`), it's a part of regular expression so should be taken into account
242242
or properly escaped with `preg_quote()`.
243+
244+
### `ToArrayOfIntegers`
245+
246+
Use `ToArrayOfIntegers` attribute to cast a value to an array of integers:
247+
248+
```php
249+
use Yiisoft\Hydrator\Attribute\Parameter\ToArrayOfIntegers;
250+
251+
final class Post
252+
{
253+
#[ToArrayOfIntegers]
254+
public array $ratings = [];
255+
}
256+
```
257+
258+
If the resolved value is iterable, each element will be cast to an integer. For example, array `['1', '2', '3']` will be
259+
converted to `[1, 2, 3]`. If the resolved value is not iterable, it will be cast to an integer and wrapped in an array.
260+
For example, string `'42'` will be converted to `[42]`.

docs/guide/ru/typecasting.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,23 @@ final class Post
253253
- `separator` — символ перевода строки (по умолчанию, `\R`). Это часть
254254
регулярного выражения, поэтому ее следует учитывать или правильно
255255
экранировать с помощью `preg_quote()`.
256+
257+
### `ToArrayOfIntegers`
258+
259+
Используйте атрибут `ToArrayOfIntegers` для приведения значения к массиву
260+
целых чисел:
261+
262+
```php
263+
use Yiisoft\Hydrator\Attribute\Parameter\ToArrayOfIntegers;
264+
265+
final class Post
266+
{
267+
#[ToArrayOfIntegers]
268+
public array $ratings = [];
269+
}
270+
```
271+
272+
Если разрешенное значение является итерируемым, каждый элемент будет приведен к целому числу.
273+
Например, массив `['1', '2', '3']` будет преобразован в `[1, 2, 3]`. Если разрешенное значение не
274+
является итерируемым, оно будет приведено к целому числу и обернуто в массив. Например, строка
275+
`'42'` будет преобразована в `[42]`.

0 commit comments

Comments
 (0)