adapterap / data-transfer-object
Библиотека для конвертации массива в класс
Installs: 21 499
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 7
Forks: 0
Open Issues: 2
Requires
- php: >=7.4
- illuminate/container: ^7.0|^8.0
- illuminate/database: ^7.0|^8.0
- illuminate/support: ^7.0|^8.0
- myclabs/php-enum: ^1.8
Requires (Dev)
- phpunit/phpunit: ^9.2
- dev-versions/1.x
- dev-master
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.15.0
- 1.14.0
- 1.13.5
- 1.13.4
- 1.13.3
- 1.13.2
- 1.13.1
- 1.13.0
- 1.12.0
- 1.11.0
- 1.10.8
- 1.10.6
- 1.10.5
- 1.10.4
- 1.10.3
- 1.10.2
- 1.10.0
- 1.9.0
- 1.8.0
- 1.7.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.9
- 1.1.8
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.0
- dev-feature/support-laravel-10
- dev-feature/property-exception
- dev-feature/next
- dev-hotfix/enum
- dev-feature/date-time-format-from-master
- dev-feature/date-time-format
- dev-feature/ar-2192-enums
- dev-feature/laravel9
- dev-staging
- dev-bugfix/load-empty-collection-relation
- dev-versions/1.5.x
- dev-versions/1.4.x
- dev-feature/AR-1540-add-logger-when-map
- dev-feature/old_refactoring
- dev-master_archive
This package is auto-updated.
Last update: 2023-04-04 06:29:44 UTC
README
Библиотека предоставляет возможность конвертировать массивы в объекты для дальнейшего использования типизации
Пример использования
use Adapterap\DataTransferObject\Attributes\EntityPropertyIsLazy; use Adapterap\DataTransferObject\Attributes\EntityPropertyIsNotRequired; use Adapterap\DataTransferObject\Attributes\EntityPropertyExcludedFromArray; use Adapterap\DataTransferObject\Entity; class SomeEntity extends Entity { /** * Поле, обязательное для заполнения. * * @var int */ public int $requiredValue; /** * Не обязательное поле со значением по умолчанию. * * @var int */ public int $defaultValue = 0; /** * Не обязательное поле. * * @var int */ #[EntityPropertyIsNotRequired] public int $notRequiredValue; /** * Поле, которое можно не заполнять сразу, и заполнить позднее. * * @var int */ #[EntityPropertyIsLazy] public int $lazyValue; /** * Поле, которое не будет включено в результирующий массив. * * @var int */ #[EntityPropertyExcludedFromArray] public int $excludedValue; } $entity = new SomeEntity([ 'requiredValue' => 1, ]); if ($entity->exists('notRequiredValue')) { // Поле $entity->notRequiredValue заполнено } // Динамическое заполнение $entity->defaultValue = 1; // или $entity->fill(['defaultValue' => 1]); $entity->toArray(); // [ // 'requiredValue' => ..., // 'defaultValue' => ..., // 'notRequiredValue' => ..., // 'lazyValue' => ..., // ];
TODO
- Добавить атрибут для финального формата даты в
toArray()
- Добавить атрибут для изменения наименования атрибута (в snack, в camel, в custom)