{"id":23774457,"url":"https://github.com/nuxtifyts/php-dto","last_synced_at":"2026-04-04T05:30:16.869Z","repository":{"id":269344116,"uuid":"907118457","full_name":"nuxtifyts/php-dto","owner":"nuxtifyts","description":"A Data objects library simplifies data transfer, ensuring structure, validation, and separation of concerns.","archived":false,"fork":false,"pushed_at":"2025-02-04T18:39:15.000Z","size":430,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-02-04T19:37:26.997Z","etag":null,"topics":["data-deserialization","data-serialization","data-transfer-object","php84"],"latest_commit_sha":null,"homepage":"","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/nuxtifyts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"docs/SupportedTypes.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-22T21:24:20.000Z","updated_at":"2025-02-04T18:39:18.000Z","dependencies_parsed_at":"2025-01-28T00:22:26.464Z","dependency_job_id":"5d59f659-4c11-468c-af64-a439d9319e88","html_url":"https://github.com/nuxtifyts/php-dto","commit_stats":null,"previous_names":["nuxtifyts/php-dto"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxtifyts%2Fphp-dto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxtifyts%2Fphp-dto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxtifyts%2Fphp-dto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxtifyts%2Fphp-dto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nuxtifyts","download_url":"https://codeload.github.com/nuxtifyts/php-dto/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239964514,"owners_count":19725952,"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":["data-deserialization","data-serialization","data-transfer-object","php84"],"created_at":"2025-01-01T06:14:32.625Z","updated_at":"2026-04-04T05:30:16.811Z","avatar_url":"https://github.com/nuxtifyts.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Pure Data objects\n\n![GitHub License](https://img.shields.io/github/license/nuxtifyts/php-dto)\n![Packagist Version](https://img.shields.io/packagist/v/nuxtifyts/php-dto)\n![PhpStan Level](https://img.shields.io/badge/PHPStan-level%2010-brightgreen.svg)\n[![PHPStan Checks](https://github.com/nuxtifyts/php-dto/actions/workflows/phpstan-tests.yml/badge.svg)](https://github.com/nuxtifyts/php-dto/actions/workflows/phpstan-tests.yml)\n[![CI Tests](https://github.com/nuxtifyts/php-dto/actions/workflows/php-tests.yml/badge.svg)](https://github.com/nuxtifyts/php-dto/actions/workflows/php-tests.yml)\n[![Test Coverage](https://raw.githubusercontent.com/nuxtifyts/php-dto/main/badge-coverage.svg)](https://packagist.org/packages/nuxtifyts/phpdto)\n\nThis package enabled the creation of data objects which can be used in various ways. \nUsing modern PHP syntax, it allows you to hydrate data from arrays, objects, and other data sources.\nAs well as carrying out the data, type validation and serialize the data for any purpose.\n\nTo create a `data` class, you will need to declare a `readonly` class that extends `Data` class.\nThen you can define the properties of the class and their types.\n\n```php\nuse Nuxtifyts\\PhpDto\\Data;\nuse Nuxtifyts\\PhpDto\\Attributes\\Property\\Aliases;\nuse Nuxtifyts\\PhpDto\\Attributes\\Property\\Computed;\n\nfinal readonly class UserData extends Data\n{\n    #[Computed]\n    public string $fullName;\n\n    public function __construct(\n        public string $firstName,\n        #[Aliases('familyName')]\n        public string $lastName\n    ) {\n        $this-\u003efullName = \"$this-\u003efirstName $this-\u003elastName\";\n    }\n}\n```\n\nYou can then create an instance of the class from a mixed value. The DTO will then attempt to hydrate the object with the given data.\n\n```php\n$data = [\n    'firstName' =\u003e 'John',\n    'lastName' =\u003e 'Doe',\n];\n\n$user = UserData::from($data);\n```\n\nDTOs can also be serialized to an array:\n\n```php\n\n$user = new UserData('John', 'Doe');\n\n$userData = $user-\u003etoArray();\n\n// Or transform to a JSON string\n\n$userData = $user-\u003etoJson();\n\n```\n\nCheck out the [Quick start](https://github.com/nuxtifyts/php-dto/blob/main/docs/Quickstart.md) guide for more information.\n\n### Note\n\nThis package was inspired from the [spatie/data-transfer-object](https://github.com/spatie/laravel-data) package.\nThe main thing that I tried to focus on when creating this package is to make it outside of Laravel ecosystem, \nmeaning: no dependency on [illuminate/support](https://github.com/illuminate/support).\n\n### Requirements\n\n- PHP 8.4 or higher\n- That's it!\n\n### Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require nuxtifyts/php-dto\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuxtifyts%2Fphp-dto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuxtifyts%2Fphp-dto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuxtifyts%2Fphp-dto/lists"}