{"id":17035662,"url":"https://github.com/prinsfrank/php-validated-properties","last_synced_at":"2025-04-12T12:52:22.576Z","repository":{"id":43668384,"uuid":"451984776","full_name":"PrinsFrank/php-validated-properties","owner":"PrinsFrank","description":"Validated properties in PHP8.1 and above using attribute rules","archived":false,"fork":false,"pushed_at":"2022-07-10T21:04:47.000Z","size":141,"stargazers_count":24,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T07:36:34.451Z","etag":null,"topics":["attributes","composer-package","php","property","validation","validation-library"],"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/PrinsFrank.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":"SECURITY.md","support":null}},"created_at":"2022-01-25T17:55:44.000Z","updated_at":"2025-02-08T16:22:40.000Z","dependencies_parsed_at":"2022-09-17T00:00:43.582Z","dependency_job_id":null,"html_url":"https://github.com/PrinsFrank/php-validated-properties","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrinsFrank%2Fphp-validated-properties","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrinsFrank%2Fphp-validated-properties/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrinsFrank%2Fphp-validated-properties/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrinsFrank%2Fphp-validated-properties/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PrinsFrank","download_url":"https://codeload.github.com/PrinsFrank/php-validated-properties/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571604,"owners_count":21126519,"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":["attributes","composer-package","php","property","validation","validation-library"],"created_at":"2024-10-14T08:47:41.264Z","updated_at":"2025-04-12T12:52:22.555Z","avatar_url":"https://github.com/PrinsFrank.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Banner](docs/images/banner.png)\n\n# PHP Validated Properties\n\n![GitHub](https://img.shields.io/github/license/prinsfrank/php-validated-properties)\n[![Build Status](https://scrutinizer-ci.com/g/PrinsFrank/php-validated-properties/badges/build.png?b=main)](https://scrutinizer-ci.com/g/PrinsFrank/php-validated-properties/build-status/main)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/PrinsFrank/php-validated-properties/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/PrinsFrank/php-validated-properties/?branch=main)\n[![Code Coverage](https://scrutinizer-ci.com/g/PrinsFrank/php-validated-properties/badges/coverage.png?b=main)](https://scrutinizer-ci.com/g/PrinsFrank/php-validated-properties/?branch=main)\n![PHP Version Support](https://img.shields.io/packagist/php-v/prinsfrank/php-validated-properties)\n\n**Add Rule attributes to your model properties to make sure they are valid.**\n\n## Why this package?\n\nWhen validating external data coming from either a Request, an import or an API, common PHP packages allow you to validate that incoming data and give you that data back in an unstructured way. With this package you can directly add validation rules to your structured models instead;\n\n```php\n#[Url]\nprotected string $url;\n\n#[Between(1, 100)]\nprotected int $nrOfItems;\n\n#[Email]\nprotected string $email;\n```\n\nWhen a property is set to a value that doesn't adhere to these rules, a ValidationException will be thrown. (Which can be handled application specifically)\n\n## Setup\n\nTo get up and running, simply run;\n\n```shell\ncomposer require prinsfrank/php-validated-properties\n```\n\n## Creating a validated model \nAnd extend the base model in ```PrinsFrank\\PhpStrictModels\\Model```;\n```php\n\u003c?php\n\nuse PrinsFrank\\PhpStrictModels\\Model;\n\nclass ValidatedModel extends Model {\n\n}\n```\n\n\n\u003cdetails\u003e\n    \u003csummary\u003eIf your models already extend another base model, you can also use the WithValidatedProperties trait instead\u003c/summary\u003e\n\n```php\n\u003c?php\n\nuse PrinsFrank\\PhpStrictModels\\WithValidatedProperties;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass ValidatedModel extends Model {\n    use WithValidatedProperties;\n}\n```\n\u003c/details\u003e\n\n## Adding validated properties\n\nTo add validation rules to properties, add them as attributes to protected and private properties:\n\n```php\n\u003c?php\n\nuse PrinsFrank\\PhpStrictModels\\Model;\nuse PrinsFrank\\PhpStrictModels\\Rule\\Between;\nuse PrinsFrank\\PhpStrictModels\\Rule\\Url;\n\nclass ValidatedModel extends Model {\n    #[Between(1,5)]\n    protected int $nrOfItems;\n    \n    #[Url]\n    protected string $url;\n}\n```\n\nDue [to how PHP works internally](https://www.php.net/manual/en/language.oop5.overloading.php#object.set), it is not possible to validate public properties, so models extending the validated model or using the WithValidatedProperties trait will throw an exception when they contain public properties with Rule attributes.\n\n## PHPStan support\n\nTo let PHPStan understand this package and to enable it to prevent any errors that can be detected using static analysis, a PHPStan plugin is provided in ```prinsfrank/php-validated-properties-phpstan```. To add it to your phpstan.neon, simply run the command below;\n\n```\ncomposer require prinsfrank/php-validated-properties-phpstan --dev\n```\n\nAnd add the following line to your includes section in your phpstan.neon file:\n\n```neon\nincludes:\n    - vendor/prinsfrank/php-validated-properties/development/PHPStan/extension.neon\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprinsfrank%2Fphp-validated-properties","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprinsfrank%2Fphp-validated-properties","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprinsfrank%2Fphp-validated-properties/lists"}