PHPackages                             danielz/shape-validator-php - 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. danielz/shape-validator-php

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

danielz/shape-validator-php
===========================

Simple (array) shape validator.

v1.0.0(4y ago)0521apache-2.0PHPPHP ^7.4|^8.0

Since Jan 28Pushed 4y ago1 watchersCompare

[ Source](https://github.com/daniel-zahariev/shape-validator-php)[ Packagist](https://packagist.org/packages/danielz/shape-validator-php)[ RSS](/packages/danielz-shape-validator-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (1)

Simple shape validator
----------------------

[](#simple-shape-validator)

Define ***all*** possible fields for a shape and set rules for them. Any field outside of the defined set will trigger an error.

### Usage:

[](#usage)

```
try {
    $shape = [
        'name' => 'required|string',
        'phone' => 'required|numeric',
        'notes' => 'string',
        'data' => 'any',
    ];
    $shape_validator = new ShapeValidator($shape);
    $shape_validator->validate([
        'name' => 'Hello, world!', // valid
        'extra' => null, // this will trigger an error
    ]);
} catch(ShapeException $exception) {
    // getValidationErrors() returns an array like ['field name' => 'error message']
    log($exception->getValidationErrors());
}
```

### Available rules:

[](#available-rules)

- `required` - the field must be present
- `nullable` - the field can take null values
- `string` - if the field value is set it must be a valid string
- `numeric`- if the field value is set it must have valid numeric value
- `bool` / `boolean` - if the field value is set it must be a valid boolean value (validation is using type comparison `===`)
- `any` - allows any values

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

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

Unknown

Total

1

Last Release

1571d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1534eb273040a078e7d6f0705aafbf243eaae555b04724c0834c36235d9286c3?d=identicon)[danielz](/maintainers/danielz)

---

Top Contributors

[![daniel-zahariev](https://avatars.githubusercontent.com/u/263063?v=4)](https://github.com/daniel-zahariev "daniel-zahariev (2 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/danielz-shape-validator-php/health.svg)

```
[![Health](https://phpackages.com/badges/danielz-shape-validator-php/health.svg)](https://phpackages.com/packages/danielz-shape-validator-php)
```

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