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

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

fortuneglobe/types
==================

Basic type classes wrapping scalar values to create types in applications.

8.1.2(1y ago)19.0k↑166.7%proprietaryPHPPHP &gt;=8.1

Since Oct 23Pushed 1y ago6 watchersCompare

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

READMEChangelog (10)Dependencies (1)Versions (28)Used By (0)

Types
=====

[](#types)

[![CircleCI](https://camo.githubusercontent.com/a9fc2f61117fabf0b18bc66c7905955d3b1abd88e1bafc0f02f0bd6f11740616/68747470733a2f2f646c2e636972636c6563692e636f6d2f7374617475732d62616467652f696d672f67682f666f7274756e65676c6f62652f74797065732f747265652f6d61737465722e7376673f7374796c653d737667)](https://dl.circleci.com/status-badge/redirect/gh/fortuneglobe/types/tree/master)[![Last Commit](https://camo.githubusercontent.com/84447caa11665e7dec91540bfa7f629551990616ae97ce4bd9f22d8f53f0a726/68747470733a2f2f62616467656e2e6e65742f6769746875622f6c6173742d636f6d6d69742f666f7274756e65676c6f62652f7479706573)](https://camo.githubusercontent.com/84447caa11665e7dec91540bfa7f629551990616ae97ce4bd9f22d8f53f0a726/68747470733a2f2f62616467656e2e6e65742f6769746875622f6c6173742d636f6d6d69742f666f7274756e65676c6f62652f7479706573)[![Dependencies](https://camo.githubusercontent.com/b231839c14fb92d7f4747081290e923e596765586b2aed14e367e1809e831b56/68747470733a2f2f62616467656e2e6e65742f6769746875622f646570656e64656e74732d7265706f2f666f7274756e65676c6f62652f7479706573)](https://camo.githubusercontent.com/b231839c14fb92d7f4747081290e923e596765586b2aed14e367e1809e831b56/68747470733a2f2f62616467656e2e6e65742f6769746875622f646570656e64656e74732d7265706f2f666f7274756e65676c6f62652f7479706573)[![Latest release](https://camo.githubusercontent.com/6e3692784da9bc8482d026a8e74f676bbf9ffae61da140e2755bff7dce224756/68747470733a2f2f62616467656e2e6e65742f6769746875622f72656c656173652f666f7274756e65676c6f62652f7479706573)](https://camo.githubusercontent.com/6e3692784da9bc8482d026a8e74f676bbf9ffae61da140e2755bff7dce224756/68747470733a2f2f62616467656e2e6e65742f6769746875622f72656c656173652f666f7274756e65676c6f62652f7479706573)[![Code Coverage](https://camo.githubusercontent.com/9516dd229a88f2b3cb105a735ecfee5e7655a94d502ed780409fa942dcdc2186/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d636f766572616765266d6573736167653d39322e35332526636f6c6f723d677265656e)](https://camo.githubusercontent.com/9516dd229a88f2b3cb105a735ecfee5e7655a94d502ed780409fa942dcdc2186/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d636f766572616765266d6573736167653d39322e35332526636f6c6f723d677265656e)

Beschreibung
------------

[](#beschreibung)

Basistypen, die skalare Typen, aber wie bei DateType auch andere Typen aus der PHP Bibliothek wrappen, um Typen in Anwendungen zu erstellen.

Für jeden Typen (ausgenommen Uuid4) gibt es ein Interface und einen Trait, welcher bereits die meisten Interface-Methoden implementiert.

Die Typen können auch von den abstrakten Klassen abgeleitet werden. Diese implementieren alle Interface-Methoden und stellen zu dem eine automatische Validierung bereit.

Die abstrakten Klassen sind immutable.

Bis auf AbstractDateType haben alle abstrakten Typ Klassen eine `transform` Methode, welche im Konstruktor nach der Validierung (durch `isValid`) aufgerufen wird. Diese Methode verändert den Wert standardmäßig nicht. Sie kann vollständig überschrieben werden, falls der Wert verändert werden soll.

Anwendungsbeispiele
-------------------

[](#anwendungsbeispiele)

### Strings

[](#strings)

```
class ClientId extends AbstractStringType
{
    public static function isValid( string $value ): bool
    {
        return $value !== '';
    }
}
class ChannelId extends AbstractStringType
{
    public static function isValid( string $value ): bool
    {
        return $value !== '';
    }
}
$clientId           = new ClientId( 'gmo' );
$anotherClientId    = new ClientId( 'gmo' );
$yetAnotherClientId = new ClientId( 'maerz' );
$channelId          = new ChannelId( 'gmo' );
$anotherChannelId   = new ChannelId( 'zalando' );

$clientId->equals( $anotherClientId ) //true
$clientId->equals( $yetAnotherClientId ) //false
$clientId->equals( $channelId ) //false
$clientId->equalsValue( $channelId ) //true
$clientId->equalsValue( 'gmo' ) //true

$newClientId = ClientId::fromStringType( $anotherChannelId );
get_class( $newClientId ); //ClientId
$newClientId->toString(); //zalando
(string)$newClientId; //zalando
```

### Integers

[](#integers)

```
class Quantity extends AbstractStringType
{
    public static function isValid( int $value ): bool
    {
        return $value > 0;
    }
}
$quantityOfFirstItem  = new Quantity( 2 );
$quantityOfSecondItem = new Quantity( 5 );

$totalQuantity = $quantityOfFirstItem->add( $quantityOfSecondItem ); //7
$difference    = $quantityOfFirstItem->subtract( $quantityOfSecondItem ); //throws ValidationException
$difference    = $quantityOfSecondItem->subtract( $quantityOfFirstItem ); //3

$incrementedQuantity = $quantityOfFirstItem->increment( $quantityOfSecondItem ); //7
```

Man kann auch mit primitiven Datentypen rechnen.

```
$quantity  = new Quantity( 2 );

$totalQuantity = $quantity->add( 5 ); //7
$difference    = $quantity->subtract( 5 ); //-3

$incrementedQuantity = $quantity->increment( 10 ); //12
```

### Eigene Uuid4-Typen

[](#eigene-uuid4-typen)

```
class FulfillmentId extends Uuid4
{
}

$fulfillmentId        = FulfillmentId::generate(); //some UUID4
$anotherFulfillmentId = new FulfillmentId( '9b856c0e-610a-4e38-9ea6-b9ac63cfb521' );
```

### Uuid4

[](#uuid4)

```
$uuid4 = (string)Uuid4::generate();
```

### Additional methods provided by trait RepresentingStringType and so also by AbstractStringType

[](#additional-methods-provided-by-trait-representingstringtype-and-so-also-by-abstractstringtype)

- `getLength`
- `contains`
- `split`
- `splitRaw`
- `matchRegularExpression`

### Additional methods provided by AbstractStringType

[](#additional-methods-provided-by-abstractstringtype)

- `trim`
- `replace`
- `substring`
- `toLowerCase`
- `toUpperCase`
- `capitalizeFirst`
- `deCapitalizeFirst`
- `toKebabCase`
- `toSnakeCase`
- `toUpperCamelCase`
- `toLowerCamelCase`

### DateType

[](#datetype)

```
class UpdatedOn extends AbstractDateType
{
    public static function isValid( \DateTimeInterface $value ): bool
    {
        return true;
    }
}

$updatedOn = new UpdatedOn('2023-07-07 08:01:20', new \DateTimeZone( '+0200' ) ))->toString() ); //some UUID4
$updatedOn->hasExpired(); //Checks if current date time is greater than date time of UpdatedOn. Returns boolean
$updatedOn->hasExpired( new \DateInterval('PT15M') ); //Checks if current date time is greater than date time of UpdatedOn and added \DateInterval. Returns boolean
```

### RepresentsDateType extends following interfaces

[](#representsdatetype-extends-following-interfaces)

- `\Stringable`
- `\JsonSerializable`

### Methods provided by RepresentsDateType

[](#methods-provided-by-representsdatetype)

- `equals`
- `equalsValue`
- `toDateTime`
- `sub`
- `add`
- `diff`
- `isLessThan`
- `isGreaterThan`
- `isGreaterThanOrEqual`
- `isLessThanOrEqual`
- `hasExpired`
- `format`
- `getOffset`
- `getTimestamp`
- `getTimezone`
- `toString`

Helpers
-------

[](#helpers)

`TypesToArrayHelper` kann benutzt werden, um aus Arrays, bestehend aus StringTypes, FloatTypes, IntTypes oder ArrayTypes, Arrays mit primitiven Datentypen zu bauen.

Beispiel:

```
$types = [
    new AnyStringType( 'one' ),
    new AnyStringType( 'two' ),
    new AnotherStringType( 'three' ),
];

TypesToArrayHelper::toStringArray( $types ); // [ 'one', 'two', 'three' ]
```

Json
----

[](#json)

Alle Typen implementieren `\JsonSerializable` und können damit mit `json_encode` serialisiert werden.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance43

Moderate activity, may be stable

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

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

Recently: every ~122 days

Total

26

Last Release

448d ago

Major Versions

3.1.0 → 4.0.02022-09-29

4.0.0 → 5.0.02022-11-02

5.4.0 → 6.0.02023-03-01

6.0.1 → 7.0.02023-07-07

7.1.0 → 8.0.02023-11-14

PHP version history (4 changes)v0.1.0-alphaPHP &gt;=7.1

2.0.0PHP &gt;=7.4

4.0.0PHP &gt;=8.0

5.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1557839?v=4)[Holger Woltersdorf](/maintainers/hollodotme)[@hollodotme](https://github.com/hollodotme)

---

Top Contributors

[![hollodotme](https://avatars.githubusercontent.com/u/1557839?v=4)](https://github.com/hollodotme "hollodotme (28 commits)")

---

Tags

librarytypesystemvalueobject

### Embed Badge

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

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

PHPackages © 2026

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