{"id":26237633,"url":"https://github.com/rahimi-ali/php-dto","last_synced_at":"2025-10-11T14:08:28.601Z","repository":{"id":191274832,"uuid":"601333290","full_name":"rahimi-ali/php-dto","owner":"rahimi-ali","description":"DTOs for PHP","archived":false,"fork":false,"pushed_at":"2023-12-31T04:31:42.000Z","size":73,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-11T14:08:24.288Z","etag":null,"topics":["backend","foundation","php"],"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/rahimi-ali.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":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-13T21:05:16.000Z","updated_at":"2025-08-21T10:53:57.000Z","dependencies_parsed_at":"2023-08-29T05:40:05.856Z","dependency_job_id":"cdb461d0-de6b-4a19-856f-6c0dc76121e3","html_url":"https://github.com/rahimi-ali/php-dto","commit_stats":null,"previous_names":["rahimi-ali/php-dto"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rahimi-ali/php-dto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahimi-ali%2Fphp-dto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahimi-ali%2Fphp-dto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahimi-ali%2Fphp-dto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahimi-ali%2Fphp-dto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rahimi-ali","download_url":"https://codeload.github.com/rahimi-ali/php-dto/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahimi-ali%2Fphp-dto/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007487,"owners_count":26084313,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["backend","foundation","php"],"created_at":"2025-03-13T05:28:50.462Z","updated_at":"2025-10-11T14:08:28.569Z","avatar_url":"https://github.com/rahimi-ali.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP-DTO\n## DTOs for PHP!\n\nDTOs can be used to transform Incoming Psr7 server requests, json and random arrays to typed classes with validation built in.\n\nDoes not use reflection and handles everything with good old classes and methods!\n\n### Install\n```sh\ncomposer require rahimi-ali/php-dto\n```\n\n### Types\n- `int(bool $strict = false): IntType`\n- `float(bool $strict = false): FloatType`\n- `string(bool $strict = false): StringType`\n- `bool(bool $strict = false): BoolType`\n- `datetime(string $format = DateTimeInterface::ATOM, string|null $timezone = null, bool $immutable = true): DateTimeType`\n- `embedded(string $class): EmbeddedType`\n- `dynamicEmbedded(string|Closure $discriminator, array $types = []): DynamicEmbeddedType`\n- `collection(TypeInterface $type): CollectionType`\n\n### Rules\n- `int(bool $strict = false): IntRule` Automatically added when declaring a field with IntType\n- `float(bool $strict = false): FloatRule` Automatically added when declaring a field with FloatType\n- `string(bool $strict = false): StringRule` Automatically added when declaring a field with StringType\n- `bool(bool $strict = false): BoolRule` Automatically added when declaring a field with BoolType\n- `array(): ArrayRule` Should be an array with sequential int keys\n- `object(): ObjectRule` Should be an object or an array with string keys or non-sequential int keys\n- `min(int $min, bool $strict = false): MinRule`\n- `max(int $max, bool $strict = false): MaxRule`\n- `minLength(int $length, bool $strict = false): MinLengthRule`\n- `maxLength(int $length, bool $strict = false): MaxLengthRule`\n- `in(array $values, bool $strict = false): InRule`\n- `notIn(array $values, bool $strict = false): NotInRule`\n- `equals(mixed $value, bool $strict = false): EqualsRule`\n- `notEqual(mixed $value, bool $strict = false): NotEqual`\n\n### Example\n```php\nclass AddressDto extends Dto\n{\n    private string $city;\n    private string $street;\n    private int $number;\n    \n    public static function fields(array $data): array\n    {\n        return [\n            'city' =\u003e new Field('city', Type::string(true), rules: [Rule::in(['London', 'Paris', 'New York'])]),\n            'street' =\u003e new Field('street', Type::string(true), rules: [Rule::min(5)]),\n            'number' =\u003e new Field('number', Type::int(true), rules: [Rule::min(1), Rule::max(100)]),\n        ];\n    }\n    \n    public function getCity(): string\n    {\n        return $this-\u003ecity;\n    }\n    \n    public function getStreet(): string\n    {\n        return $this-\u003estreet;\n    }\n    \n    public function getNumber(): int\n    {\n        return $this-\u003enumber;\n    }\n}\n\nclass UserDto extends Dto\n{\n    private string $name;\n    private int $age;\n    private AddressDto $address;\n    \n    public static function fields(array $data): array\n    {\n        return [\n            'name' =\u003e new Field('name', Type::string(true), rules: [Rule::min(5)]),\n            'age' =\u003e new Field('age', Type::int(true), rules: [Rule::min(18)]),\n            'address' =\u003e new Field('address', Type::embedded(AddressDto::class)),\n        ];\n    }\n    \n    public function getName(): string\n    {\n        return $this-\u003ename;\n    }\n    \n    public function getAge(): int\n    {\n        return $this-\u003eage;\n    }\n    \n    public function getAddress(): AddressDto\n    {\n        return $this-\u003eaddress;\n    }\n}\n```\n\n### Notes\n- Because reflection and magic methods were not used private and readonly properties\ncannot be used because the parent class cannot access them by default. If you really want private and readonly\nproperties, override the `setProperty` method in you DTO:\n```php\nprotected function setProperty(string $property, mixed $value): void\n{\n    $this-\u003e{$property} = $value;\n}\n```\n\n### Standards\n- Code Coverage: 100%\n- PHPStan Level: 9\n- Infection MSI: 94%\n\n### License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frahimi-ali%2Fphp-dto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frahimi-ali%2Fphp-dto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frahimi-ali%2Fphp-dto/lists"}