PHPackages                             pre/prop-types - 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. pre/prop-types

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

pre/prop-types
==============

Prop type validators for Phpx components

0.2.1(7y ago)437[1 issues](https://github.com/preprocess/pre-prop-types/issues)[1 PRs](https://github.com/preprocess/pre-prop-types/pulls)MITPHP

Since Mar 14Pushed 3y agoCompare

[ Source](https://github.com/preprocess/pre-prop-types)[ Packagist](https://packagist.org/packages/pre/prop-types)[ RSS](/packages/pre-prop-types/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (3)Dependencies (1)Versions (5)Used By (0)

Prop Types
==========

[](#prop-types)

[![Support on Gitstore](https://camo.githubusercontent.com/14664ba3f37203710d4be3003b0b2ad4285a62b6358ed73ca8034c8e4abb4341/68747470733a2f2f656e6a6f792e67697473746f72652e6170702f7265706f7369746f726965732f62616467652d70726570726f636573732f7072652d70726f702d74797065732e737667)](https://enjoy.gitstore.app/repositories/preprocess/pre-prop-types)

This is a PHP take on the ReactJS Prop Types checking. I made it because I wanted an easier way to validate the type and presence of properties in Phpx components.

Getting started
---------------

[](#getting-started)

```
git clone git@github.com:preprocess/pre-prop-types.git
cd pre-prop-types
composer install
composer test

```

Defining types
--------------

[](#defining-types)

We support most of the built-in types:

```
use App\Profile;
use Pre\PropTypes;

$profile = Profile::find(1);

$definitions = [
    "name" => PropTypes::string()->isRequired(),
    "age" => PropTypes::int(),
    "rating" => PropTypes::float(),
    "permissions" => PropTypes::arrayOf(PropTypes::string()),
    "thumbnail" => PropTypes::either(
        PropTypes::string(), // uri
        PropTypes::resource(), // file handle
    ),
    "profile" => PropTypes::objectOf(Profile::class)->isRequired(),
    "onMessage" => PropTypes::closure()->isRequired(),
    "isAdmin" => PropTypes::bool()->isRequired(),
];

$properties = [
    "name" => "Joe",
    "profile" => $profile,
    "onMessage" => function($message) use ($profile) {
        $profile->notify($message);
    },
    "isAdmin" => false,
];

try {
    PropTypes::validate($definitions, $properties);
} catch (InvalidArgumentException $e) {
    // ...handle the error
}
```

- `isRequired` will ensure the value is present in the accompanying properties array
- `either` allows one or more types (preferably two distinct types) for comparison

There are also variations on these:

- `PropTypes::array()` expects any array values, without a specific type
- `PropTypes::boolean()` is the same as `PropTypes::bool()`
- `PropTypes::integer()` is the same as `PropTypes::int()`
- `PropTypes::double()` expects double values
- `PropTypes::iterable()` expects any iterable values
- `PropTypes::numeric()` expects any numeric values
- `PropTypes::object()` expects any object values, without a specific type

Validating types
----------------

[](#validating-types)

We don't automatically validate props – this must be done by the consumer. And example Phpx render method demonstrates this:

```
use Pre\PropTypes;
use function Pre\Phpx\Html\render as renderHTML;

function render($type, $props = [])
{
    $props = (array) $props;

    if (class_exists($type)) {
        if (method_exists($type, "propTypes")) {
            PropTypes::validate($type::propTypes(), $props);
        }

        if (method_exists($type, "defaultProps")) {
            $props = array_merge($type::defaultProps(), $props);
        }
    }

    return renderHTML($type, $props);
}

render("App\\Custom\\Component");
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

3

Last Release

2613d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/00089084814b5b79cd35b9f501bcc48d74c5afb2cb4703562a82e081f31c843c?d=identicon)[assertchris](/maintainers/assertchris)

---

Top Contributors

[![assertchris](https://avatars.githubusercontent.com/u/200609?v=4)](https://github.com/assertchris "assertchris (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pre-prop-types/health.svg)

```
[![Health](https://phpackages.com/badges/pre-prop-types/health.svg)](https://phpackages.com/packages/pre-prop-types)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
