Download the PHP package itmedia/data-transformer without Composer
On this page you can find all versions of the php package itmedia/data-transformer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download itmedia/data-transformer
More information about itmedia/data-transformer
Files in itmedia/data-transformer
Package data-transformer
Short Description DataTransformer
License MIT
Homepage https://github.com/by25/DataTransformer
Informations about the package data-transformer
DataTransformer
Библиотека для трансформации данных в массивы, на основании предопределенной схемы (Transformer).
Install
Пример использования
Трансформеры:
Трансформер должен быть отнаследован от Itmedia\DataTransformer\Transformer\Transformer
и реализован метод map($resource)
:
Можно строить карту трансформации как массивов, так и объектов.
Трансформация данных:
Результат:
Опции и варианты трансформации
Трансформеры могут в себя включать другие трансформеры.
Где:
-
$property
- Свойство, по которому будет происходить выборка значения для последующей трансформации. Может быть как ключем массива, так и названием метода объекта (default: null) $mapping
- Опции маппинга (склеивания в выходной массив).
Доступные опции маппинга:
-
field
Название ключа массива, на который будет присвоен результат трансформации (default: null):- string - название ключа;
- null - автоматически вычислить. Если коллекция, то значение $property иначе объединиться с корневым масивом;
- false - объединение с корневым масивом.
-
required
- Проверить существования данных по $property (выкидывается исключение) (default: false).$options
- Опции трансформации. Может использоваться для управления преобразования данных, например для скрытия каких-либо полей. Описываются доступные опции трансформации в Transformer::defaultOptions(). Пример -Itmedia\DataTransformer\Tests\Stub\Transformer\ArrayGroupTransformer
Трансформация данных:
Опции:
root_key
- Обернуть возвращаемый массив в ключ root_key. (default: null)
Трансформация одного элемента:
Трансформация коллекции элементов: