PHPackages                             leocavalcante/shape - 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. leocavalcante/shape

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

leocavalcante/shape
===================

Run-time type checks against plain old PHP arrays

1393.5k↓42.8%22PHPCI failing

Since Feb 14Pushed 6y ago1 watchersCompare

[ Source](https://github.com/leocavalcante/shape)[ Packagist](https://packagist.org/packages/leocavalcante/shape)[ RSS](/packages/leocavalcante-shape/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (2)

shape [![CircleCI](https://camo.githubusercontent.com/5c9ecd619450f64d59ad1063ad3c7f5ff95bef860717ca9052310a33460417e8/68747470733a2f2f636972636c6563692e636f6d2f67682f6c656f636176616c63616e74652f73686170652e7376673f7374796c653d737667)](https://circleci.com/gh/leocavalcante/shape)
========================================================================================================================================================================================================================================================================================

[](#shape-)

Run-time type checks against plain old PHP arrays.

```
composer require leocavalcante/shape dev-master
```

Why
---

[](#why)

### Validate basic data structures

[](#validate-basic-data-structures)

```
use function Shape\shape;
use const Shape\int;

$pointShape = shape([
    'x' => int,
    'y' => int,
]);

$validPoint = ['x' => 1, 'y' => 2];

$pointShape($validPoint); // Shape

$invalidPoint = ['x' => 1, 'y' => 'two'];

$pointShape($invalidPoint); // TypeError: Key y passed to shape() must be of the type integer, string given
```

### Mimic tuples

[](#mimic-tuples)

```
use const Shape\string;
use const Shape\int;
use function Shape\shape;

function string_int_tuple(array $tuple)
{
    // assert it is a (String, Int) tuple
    shape([string, int])($tuple);

    return true;
}

var_dump(string_int_tuple(['one', 1])); // bool(true)

var_dump(string_int_tuple(['one', 'two'])); // TypeError: Key 1 passed to shape() must be of the type integer, string given
```

### `shape()` function returns a Closure, so you can easily use it to assert vector arrays

[](#shape-function-returns-a-closure-so-you-can-easily-use-it-to-assert-vector-arrays)

```
use const Shape\int;
use function Shape\shape;

$points = [
    ['x' => 1, 'y' => 2],
    ['x' => 3, 'y' => 4],
];

array_map(shape(['x' => int, 'y' => int]), $points);
```

Inspiration
-----------

[](#inspiration)

- [Hack / HHVM Shapes](https://docs.hhvm.com/hack/shapes/introduction)
- [Extremely Defensive PHP - Marco Pivetta](https://www.youtube.com/watch?v=8d2AtAGJPno)

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 90% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/940717934113da7abe00589e87cfde6f34496f039bcd3fc6ce4a33f5f415d4ac?d=identicon)[leocavalcante](/maintainers/leocavalcante)

---

Top Contributors

[![leocavalcante](https://avatars.githubusercontent.com/u/183722?v=4)](https://github.com/leocavalcante "leocavalcante (18 commits)")[![cmrafifar](https://avatars.githubusercontent.com/u/26392294?v=4)](https://github.com/cmrafifar "cmrafifar (2 commits)")

### Embed Badge

![Health badge](/badges/leocavalcante-shape/health.svg)

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

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