Download the PHP package prinsfrank/php-validated-properties without Composer
On this page you can find all versions of the php package prinsfrank/php-validated-properties. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download prinsfrank/php-validated-properties
More information about prinsfrank/php-validated-properties
Files in prinsfrank/php-validated-properties
Package php-validated-properties
Short Description Validated properties in PHP8.1 and above using attribute rules
License MIT
Informations about the package php-validated-properties
PHP Validated Properties
Add Rule attributes to your model properties to make sure they are valid.
Why this package?
When 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;
When 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)
Setup
To get up and running, simply run;
Creating a validated model
And extend the base model in ;
If your models already extend another base model, you can also use the WithValidatedProperties trait instead
Adding validated properties
To add validation rules to properties, add them as attributes to protected and private properties:
Due to how PHP works internally, 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.
PHPStan support
To 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 . To add it to your phpstan.neon, simply run the command below;
And add the following line to your includes section in your phpstan.neon file: