PHPackages                             ems/xtype - 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. ems/xtype

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

ems/xtype
=========

Semantic types for PHP

v0.3.1(1y ago)07.2k↑13.3%2MITPHPPHP &gt;=8.2.0

Since Nov 20Pushed 1y ago1 watchersCompare

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

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

xtype
=====

[](#xtype)

Semantic atomic types for PHP

Usage
-----

[](#usage)

XType classifies datatypes. They are mainly used to scaffold forms and get centralized string formatting.

Instead of saying:

```
echo number_format($myObject->price,2,'.');
```

with xtype you can write:

```
class MyObject{

    public $price;

    public function getType(){
        return NamedFieldType::create()
           ->set('price', UnitType::create()->setUnit('$')->setDecimals(2));
    }
}

// Then in you're view:

$myObject = new MyObject();
echo $myObject->getType('price')->valueToString($myObject->price);
```

Where this seems to be very clumsy it offers its powers in big applications or big data centric applications. Imagine you have a class customer:

```
   class Customer{

       public $id;
       public $doubts;
       public $lastLogin;
       public $taxes;

       public function getType(){
           $type = NamedField::create();
           $type->set('id', NumberType::create()->setNativeType('int'))
           $type->set('doubts', CurrencyType::create()->setCurrency('€'));
           $type->set('lastLogin', TemporalType::create();
           $type->set('taxes', PercentageType::create());
           return $type;
       }
   }

   $c = new Customer();

   foreach($c->getType() as $key=>$type){
       echo "\n$key=>".$type->valueToString($c->{$key});
   }
```

And in every part of youre application you can just forget any string formatting. But string formatting isn't the only usage of xtype. (i know about SOLID...)

Its on the other hand extremly useful to describe types. So you can build a database scheme of xtypes.

Another possibility is to scaffold forms with xtype.

Factory
-------

[](#factory)

To simply create an XType you can use XType\\TemplateFactory::create($native) which creates a AbstractType by a native php variable.

Caution
-------

[](#caution)

This lib is in beta quality. The classes don't do much so it's not that dangerous to use em. So no docs or at this time

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity70

Established project with proven stability

 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 ~598 days

Recently: every ~850 days

Total

7

Last Release

607d ago

PHP version history (2 changes)v0.1PHP &gt;=5.3.0

v0.3.0PHP &gt;=8.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/99acf76522a71f6ac363efaab2bec34dce2f74d3d82f1cb4680049dc4ef37cb7?d=identicon)[mtils](/maintainers/mtils)

---

Top Contributors

[![mtils](https://avatars.githubusercontent.com/u/2744124?v=4)](https://github.com/mtils "mtils (16 commits)")

---

Tags

validationscaffoldingmvc

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ems-xtype/health.svg)

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

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k489.6M672](/packages/composer-semver)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k148.7M416](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

64736.9M186](/packages/opis-json-schema)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

8912.9M47](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

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