adapterap / data-transfer-object
该软件包最新版本(2.0.5)没有可用的许可证信息。
将数组转换为类的库
该软件包的官方仓库似乎已消失,因此该软件包已被冻结。
2.0.5
2021-10-26 07:17 UTC
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' => ..., // ];
待办事项
- 在
toArray()
中添加用于最终日期格式的属性 - 添加用于更改属性名称的属性(在 snack、camel、custom 中)