PHPackages                             atomsk/polyprops - 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. atomsk/polyprops

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

atomsk/polyprops
================

A lightweight library for property validation and object-to-array/JSON conversion using Symfony Validator and traits.

v1.0.0(3mo ago)1137MITPHPPHP ^8.3

Since Feb 12Pushed 3mo agoCompare

[ Source](https://github.com/JoseAntonioCadavalBueno/Polyprops)[ Packagist](https://packagist.org/packages/atomsk/polyprops)[ RSS](/packages/atomsk-polyprops/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

Polyprops
=========

[](#polyprops)

[![PHP](https://camo.githubusercontent.com/c8d8dad6beb757a2b8acba331d16140813699543b88a37af0a81f20bd35f61de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d626c7565)](https://camo.githubusercontent.com/c8d8dad6beb757a2b8acba331d16140813699543b88a37af0a81f20bd35f61de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d626c7565)[![Pipeline Status](https://camo.githubusercontent.com/0467f7923fd7b65c5e5a9c37da8a06471e15f7683d7e4c6fa91f5146f1b25fe9/68747470733a2f2f6769746c61622e636f6d2f6a6361646176616c6275656e6f2f706f6c7970726f70732f6261646765732f6d61696e2f706970656c696e652e737667)](https://camo.githubusercontent.com/0467f7923fd7b65c5e5a9c37da8a06471e15f7683d7e4c6fa91f5146f1b25fe9/68747470733a2f2f6769746c61622e636f6d2f6a6361646176616c6275656e6f2f706f6c7970726f70732f6261646765732f6d61696e2f706970656c696e652e737667)[![Downloads](https://camo.githubusercontent.com/bcf7b92bb414a4c4a95cf010ffe01870379ec98568ab9559ec5315f6b09b47aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61746f6d736b2f706f6c7970726f7073)](https://camo.githubusercontent.com/bcf7b92bb414a4c4a95cf010ffe01870379ec98568ab9559ec5315f6b09b47aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61746f6d736b2f706f6c7970726f7073)[![Latest Version](https://camo.githubusercontent.com/242159c9e9408d520e14946e5dce894a2996021da28a7a26aa414342874f257e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61746f6d736b2f706f6c7970726f7073)](https://camo.githubusercontent.com/242159c9e9408d520e14946e5dce894a2996021da28a7a26aa414342874f257e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61746f6d736b2f706f6c7970726f7073)

How to install
--------------

[](#how-to-install)

```
composer require atomsk/polyprops
```

Configuration
-------------

[](#configuration)

Polyprops uses [Symfony Validator](https://symfony.com/doc/current/validation.html) under the hood. It works out of the box with PHP attributes for validation constraints.

> ⚠️ IMPORTANT
>
> For optimal performance and security:
>
> - Use **protected properties** for your data. The `Validates` trait uses `__set` to trigger validation automatically when a protected property is modified from outside (via magic setter).
> - **Public properties** are only validated during factory creation (`fromArray`, `fromJson`). If you modify a public property directly after the object is created, no automatic validation will occur.
> - Avoid overriding `__set` unless you manually call `$this->validate()` within it, as it may break the automatic validation mechanism.

Example
-------

[](#example)

### Basic Usage

[](#basic-usage)

```
