PHPackages                             prinsfrank/php-validated-properties - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. prinsfrank/php-validated-properties

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

prinsfrank/php-validated-properties
===================================

Validated properties in PHP8.1 and above using attribute rules

v0.0.2(4y ago)24471[1 issues](https://github.com/PrinsFrank/php-validated-properties/issues)[3 PRs](https://github.com/PrinsFrank/php-validated-properties/pulls)MITPHPPHP ^8.1

Since Feb 2Pushed 3y ago1 watchersCompare

[ Source](https://github.com/PrinsFrank/php-validated-properties)[ Packagist](https://packagist.org/packages/prinsfrank/php-validated-properties)[ RSS](/packages/prinsfrank-php-validated-properties/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

[![Banner](docs/images/banner.png)](docs/images/banner.png)

PHP Validated Properties
========================

[](#php-validated-properties)

[![GitHub](https://camo.githubusercontent.com/68fa949999f49dd94b4f81b94dc37ff843769e6853e036f0d0e89525d457aa1e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7072696e736672616e6b2f7068702d76616c6964617465642d70726f70657274696573)](https://camo.githubusercontent.com/68fa949999f49dd94b4f81b94dc37ff843769e6853e036f0d0e89525d457aa1e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7072696e736672616e6b2f7068702d76616c6964617465642d70726f70657274696573)[![Build Status](https://camo.githubusercontent.com/36be02812a92dc68a09036f6879274ffa9842bbbf2e6f427d39e482e48b73745/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5072696e734672616e6b2f7068702d76616c6964617465642d70726f706572746965732f6261646765732f6275696c642e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/PrinsFrank/php-validated-properties/build-status/main)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1fa7eff2647b7d3cf90f0e4c9741800632a4314aae8ba04d456b206ed4736948/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5072696e734672616e6b2f7068702d76616c6964617465642d70726f706572746965732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/PrinsFrank/php-validated-properties/?branch=main)[![Code Coverage](https://camo.githubusercontent.com/1f4019a2860fabc37f71b2371ec60cae4bca49237f7b1717ca4add65ff9e63dd/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5072696e734672616e6b2f7068702d76616c6964617465642d70726f706572746965732f6261646765732f636f7665726167652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/PrinsFrank/php-validated-properties/?branch=main)[![PHP Version Support](https://camo.githubusercontent.com/b95fc5ace7a2128cf603c7807308355f3d810982ac244a5b32c1a77196d3ba6b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7072696e736672616e6b2f7068702d76616c6964617465642d70726f70657274696573)](https://camo.githubusercontent.com/b95fc5ace7a2128cf603c7807308355f3d810982ac244a5b32c1a77196d3ba6b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7072696e736672616e6b2f7068702d76616c6964617465642d70726f70657274696573)

**Add Rule attributes to your model properties to make sure they are valid.**

Why this package?
-----------------

[](#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;

```
#[Url]
protected string $url;

#[Between(1, 100)]
protected int $nrOfItems;

#[Email]
protected string $email;
```

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
-----

[](#setup)

To get up and running, simply run;

```
composer require prinsfrank/php-validated-properties
```

Creating a validated model
--------------------------

[](#creating-a-validated-model)

And extend the base model in `PrinsFrank\PhpStrictModels\Model`;

```
