PHPackages                             czproject/type-system - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. czproject/type-system

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

czproject/type-system
=====================

Abstraction for PHP type system.

v1.0.0(9mo ago)01BSD-3-ClausePHPPHP 7.4 - 8.4CI passing

Since Aug 22Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/czproject/type-system)[ Packagist](https://packagist.org/packages/czproject/type-system)[ Fund](https://www.janpecha.cz/donate/)[ RSS](/packages/czproject-type-system/feed)WikiDiscussions master Synced 1mo ago

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

CzProject\\TypeSystem
=====================

[](#czprojecttypesystem)

[![Build Status](https://github.com/czproject/type-system/workflows/Build/badge.svg)](https://github.com/czproject/type-system/actions)[![Downloads this Month](https://camo.githubusercontent.com/730acbfce5e0652506d554422f2192bcf630f31da4bcc7be03a6f91ed6688aac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f637a70726f6a6563742f747970652d73797374656d2e737667)](https://packagist.org/packages/czproject/type-system)[![Latest Stable Version](https://camo.githubusercontent.com/b757fc5c432532109cabaf0c353c9b51a8f4a6c64e9ce33290801a16ecd8f304/68747470733a2f2f706f7365722e707567782e6f72672f637a70726f6a6563742f747970652d73797374656d2f762f737461626c65)](https://github.com/czproject/type-system/releases)[![License](https://camo.githubusercontent.com/fa7d5fcf2c84b580327af52da95dd751703af65f079dc3c5a0081beac0789718/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4e65772532304253442d626c75652e737667)](https://github.com/czproject/type-system/blob/master/license.md)

Abstraction for PHP type system.

[![Donate](https://camo.githubusercontent.com/101b981194f1dafbf9c42e19c3034fe2d724e75be972cef0f4477074997834db/68747470733a2f2f6275796d65636f666665652e696e746d2e6f72672f696d672f646f6e6174652d62616e6e65722e76312e737667)](https://www.janpecha.cz/donate/)

Installation
------------

[](#installation)

[Download a latest package](https://github.com/czproject/type-system/releases) or use [Composer](http://getcomposer.org/):

```
composer require czproject/type-system

```

CzProject\\TypeSystem requires PHP 7.4 or later.

Usage
-----

[](#usage)

```
use CzProject\TypeSystem\Types;

Types::scalar();
Types::integer();
Types::float();
Types::string();
Types::nonEmptyString();
Types::bool();
Types::true();
Types::false();
Types::null();
Types::object(\DateTimeImmutable::class);
Types::union(Types::string(), Types::integer(), Types::bool());
Types::nullable(Types::string());
Types::listOf(Types::string());
```

All types implement interface `Type`.

### Casting

[](#casting)

```
use CzProject\TypeSystem\Types;

$castedValue = Types::scalar()->castValue($value);
$castedValue = Types::integer()->castValue($value);
$castedValue = Types::float()->castValue($value);
$castedValue = Types::string()->castValue($value);
$castedValue = Types::nonEmptyString()->castValue($value);
$castedValue = Types::bool()->castValue($value);
$castedValue = Types::true()->castValue($value);
$castedValue = Types::false()->castValue($value);
$castedValue = Types::null()->castValue($value);
$castedValue = Types::object(\DateTimeImmutable::class)->castValue($value);
$castedValue = Types::union(Types::string(), Types::integer(), Types::bool())->castValue($value);
$castedValue = Types::nullable(Types::string())->castValue($value);
$castedValue = Types::listOf(Types::string())->castValue($value);
```

Or you can use simplified casting helper:

```
use CzProject\TypeSystem\Cast;

$castedValue = Cast::scalar($value);
$castedValue = Cast::integer($value);
$castedValue = Cast::integerOrNull($value);
$castedValue = Cast::float($value);
$castedValue = Cast::floatOrNull($value);
$castedValue = Cast::string($value);
$castedValue = Cast::stringOrNull($value);
$castedValue = Cast::nonEmptyString($value);
$castedValue = Cast::nonEmptyStringOrNull($value);
$castedValue = Cast::bool($value);
$castedValue = Cast::boolOrNull($value);
```

Every type throws `SorryNonConvertableValue` exception for non convertable values.

```
	try {
		Types::string()->castValue($value); // or Cast::string($value)

	} catch (CzProject\TypeSystem\SorryNonConvertableValue $e) {
		var_dump($e->getValue());
		var_dump($e->getType());
	}
```

### Value validation

[](#value-validation)

Checks if value is exactly of specific type.

```
use CzProject\TypeSystem\Types;

$isValid = Types::scalar()->isValueValid($value);
$isValid = Types::integer()->isValueValid($value);
$isValid = Types::float()->isValueValid($value);
$isValid = Types::string()->isValueValid($value);
$isValid = Types::nonEmptyString()->isValueValid($value);
$isValid = Types::bool()->isValueValid($value);
$isValid = Types::true()->isValueValid($value);
$isValid = Types::false()->isValueValid($value);
$isValid = Types::null()->isValueValid($value);
$isValid = Types::object(\DateTimeImmutable::class)->isValueValid($value);
$isValid = Types::union(Types::string(), Types::integer(), Types::bool())->isValueValid($value);
$isValid = Types::nullable(Types::string())->isValueValid($value);
$isValid = Types::listOf(Types::string())->isValueValid($value);
```

---

License: [New BSD License](license.md)
Author: Jan Pecha,

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance58

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community7

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

Unknown

Total

1

Last Release

270d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c980b1511b4a0350442dc23d89c99d4d9a2411b7e765d52c133ccacf616968b?d=identicon)[janpecha](/maintainers/janpecha)

---

Top Contributors

[![janpecha](https://avatars.githubusercontent.com/u/637719?v=4)](https://github.com/janpecha "janpecha (1 commits)")

### Embed Badge

![Health badge](/badges/czproject-type-system/health.svg)

```
[![Health](https://phpackages.com/badges/czproject-type-system/health.svg)](https://phpackages.com/packages/czproject-type-system)
```

###  Alternatives

[producer/producer

Tools for releasing library packages; supports Git, Mercurial, Github, Gitlab, and Bitbucket.

10418.7k2](/packages/producer-producer)[fabianmichael/kirby-meta

Your all-in-one powerhouse for any SEO and metadata needs imaginable.

6910.7k1](/packages/fabianmichael-kirby-meta)[n98/headless-guillotine

Frontend routing whitelist configurations for headless setups.

2627.2k](/packages/n98-headless-guillotine)[silverstripe/multiuser-editing-alert

A module that indicates when people are editing the same page in the CMS

1530.7k1](/packages/silverstripe-multiuser-editing-alert)[evilfreelancer/openvpn-php

OpenVPN config generator writen on PHP

304.7k](/packages/evilfreelancer-openvpn-php)[lucapuddu/php-provably-fair

PhpProvablyFair is a library that generates and verifies provably fair games.

154.9k](/packages/lucapuddu-php-provably-fair)

PHPackages © 2026

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