{"id":19450881,"url":"https://github.com/morning-train/data-transfer-object-casters","last_synced_at":"2025-08-15T20:52:12.544Z","repository":{"id":43843530,"uuid":"429706236","full_name":"Morning-Train/data-transfer-object-casters","owner":"Morning-Train","description":"Casters for spatie/data-transfer-object","archived":false,"fork":false,"pushed_at":"2023-03-24T08:56:55.000Z","size":34,"stargazers_count":4,"open_issues_count":2,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-15T00:22:48.724Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://morningtrain.dk/en/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Morning-Train.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"morningtrain"}},"created_at":"2021-11-19T07:26:14.000Z","updated_at":"2023-03-16T11:52:01.000Z","dependencies_parsed_at":"2024-11-10T16:40:49.613Z","dependency_job_id":null,"html_url":"https://github.com/Morning-Train/data-transfer-object-casters","commit_stats":{"total_commits":9,"total_committers":3,"mean_commits":3.0,"dds":0.5555555555555556,"last_synced_commit":"7963e58ce47274db8d1d5eb9dd5aeec7cb942ccd"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2Fdata-transfer-object-casters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2Fdata-transfer-object-casters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2Fdata-transfer-object-casters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2Fdata-transfer-object-casters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Morning-Train","download_url":"https://codeload.github.com/Morning-Train/data-transfer-object-casters/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250748101,"owners_count":21480778,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T16:39:20.596Z","updated_at":"2025-04-25T03:32:09.387Z","avatar_url":"https://github.com/Morning-Train.png","language":"PHP","funding_links":["https://github.com/sponsors/morningtrain"],"categories":[],"sub_categories":[],"readme":"# A package containing DTO casters\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/morningtrain/data-transfer-object-casters.svg?style=flat-square)](https://packagist.org/packages/morningtrain/data-transfer-object-casters)\n![GitHub Tests Action Status](https://github.com/Morning-Train/data-transfer-object-casters/workflows/Tests/badge.svg)\n[![Code style](https://img.shields.io/github/workflow/status/Morning-Train/data-transfer-object-casters/Check%20\u0026%20fix%20styling?label=code%20style)](https://github.com/SimonJnsson/data-transfer-object-casters/actions/workflows/php-cs-fixer.yml/badge.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/morningtrain/data-transfer-object-casters.svg?style=flat-square)](https://packagist.org/packages/morningtrain/data-transfer-object-casters)\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require morningtrain/data-transfer-object-casters\n```\n\n## Usage\n\nTo use the provided casters, add an attribute CastWith, to the property you want to cast.\n\n```php\nclass DTO extends DataTransferObject\n{\n    #[CastWith(BoolCaster::class)]\n    public bool $bool;\n}\n```\n\n### Bool\n\nThe Boolean caster is used to cast the provided value to a boolean.\n\nIt uses FILTER_VALIDATE_BOOL, see the [php docs](https://www.php.net/manual/en/filter.filters.validate.php) for more\ninformation\n\n### Date\n\nThe DateCaster will attempt to cast the provided value into a Carbon instance, using the provided format.\n\nIf no format is specified 'd.m.Y H:i:s' will be used.\n\n```php\nuse Morningtrain\\DataTransferObjectCasters\\Casters\\DateCaster;\n\nclass DTO extends DataTransferObject\n{\n    #[CastWith(DateCaster::class, format: 'Y-m-d')]\n    public Carbon $date;\n}\n```\n\n### Int\n\nThe IntCaster casts the provided value to an integer using (int) cast.\n\n### Trim\n\nThe TrimCaster will trim the provided value, so no whitespace remains around the value.\n\n### UppercaseFirst\n\nThe UppercaseFirstCaster will uppercase the first letter of the provided value, similar to\nphp's [ucfirst function](https://www.php.net/manual/en/function.ucfirst.php).\n\nOptionally, the caster can lowercase the rest of the string, like so.\n\n```php\nuse Morningtrain\\DataTransferObjectCasters\\Casters\\UppercaseFirstCaster;\n\nclass DTO extends DataTransferObject\n{\n    #[CastWith(UppercaseFirstCaster::class, lower: true)]\n    public string $ucFirstString;\n}\n```\n\nIf the provided value is not a string, it will return the provided value.\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [SimonJnsson](https://github.com/SimonJnsson)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorning-train%2Fdata-transfer-object-casters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorning-train%2Fdata-transfer-object-casters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorning-train%2Fdata-transfer-object-casters/lists"}