{"id":33978009,"url":"https://github.com/fortuneglobe/types","last_synced_at":"2026-05-29T08:02:48.695Z","repository":{"id":26622363,"uuid":"108009068","full_name":"fortuneglobe/types","owner":"fortuneglobe","description":"Basic type classes wrapping scalar values","archived":false,"fork":false,"pushed_at":"2025-02-24T12:29:36.000Z","size":440,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2026-02-25T15:36:49.424Z","etag":null,"topics":["library","typesystem","valueobject"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fortuneglobe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-10-23T16:32:28.000Z","updated_at":"2025-02-24T12:29:13.000Z","dependencies_parsed_at":"2025-12-13T05:02:15.457Z","dependency_job_id":null,"html_url":"https://github.com/fortuneglobe/types","commit_stats":{"total_commits":81,"total_committers":3,"mean_commits":27.0,"dds":"0.49382716049382713","last_synced_commit":"aa955024f0b8139a0231055d1e6ee359046fcb0f"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/fortuneglobe/types","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortuneglobe%2Ftypes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortuneglobe%2Ftypes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortuneglobe%2Ftypes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortuneglobe%2Ftypes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fortuneglobe","download_url":"https://codeload.github.com/fortuneglobe/types/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortuneglobe%2Ftypes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33642318,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-29T02:00:06.066Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","typesystem","valueobject"],"created_at":"2025-12-13T02:40:47.894Z","updated_at":"2026-05-29T08:02:48.669Z","avatar_url":"https://github.com/fortuneglobe.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Types\n[![CircleCI](https://dl.circleci.com/status-badge/img/gh/fortuneglobe/types/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/fortuneglobe/types/tree/master)\n![Last Commit](https://badgen.net/github/last-commit/fortuneglobe/types)\n![Dependencies](https://badgen.net/github/dependents-repo/fortuneglobe/types)\n![Latest release](https://badgen.net/github/release/fortuneglobe/types)\n![Code Coverage](https://img.shields.io/static/v1?label=coverage\u0026message=92.53%\u0026color=green)\n\n\n## Beschreibung\n\nBasistypen, die skalare Typen, aber wie bei DateType auch andere Typen aus der PHP Bibliothek wrappen, um Typen in Anwendungen zu erstellen.\n\nFür jeden Typen (ausgenommen Uuid4) gibt es ein Interface und einen Trait, welcher bereits die meisten Interface-Methoden implementiert.\n\nDie Typen können auch von den abstrakten Klassen abgeleitet werden. Diese implementieren alle Interface-Methoden und stellen zu dem eine automatische Validierung bereit.\n\nDie abstrakten Klassen sind immutable.\n\nBis auf AbstractDateType haben alle abstrakten Typ Klassen eine `transform` Methode, welche im Konstruktor nach der Validierung (durch `isValid`) aufgerufen wird. \nDiese Methode verändert den Wert standardmäßig nicht. Sie kann vollständig überschrieben werden, falls der Wert verändert werden soll. \n\n## Anwendungsbeispiele\n\n### Strings\n\n````PHP\nclass ClientId extends AbstractStringType\n{\n    public static function isValid( string $value ): bool\n    {\n        return $value !== '';\n    }\n}\nclass ChannelId extends AbstractStringType\n{\n    public static function isValid( string $value ): bool\n    {\n        return $value !== '';\n    }\n}\n$clientId           = new ClientId( 'gmo' );\n$anotherClientId    = new ClientId( 'gmo' );\n$yetAnotherClientId = new ClientId( 'maerz' );\n$channelId          = new ChannelId( 'gmo' );\n$anotherChannelId   = new ChannelId( 'zalando' );\n\n$clientId-\u003eequals( $anotherClientId ) //true\n$clientId-\u003eequals( $yetAnotherClientId ) //false\n$clientId-\u003eequals( $channelId ) //false\n$clientId-\u003eequalsValue( $channelId ) //true\n$clientId-\u003eequalsValue( 'gmo' ) //true\n\n$newClientId = ClientId::fromStringType( $anotherChannelId );\nget_class( $newClientId ); //ClientId\n$newClientId-\u003etoString(); //zalando\n(string)$newClientId; //zalando\n````\n\n### Integers\n\n````PHP\nclass Quantity extends AbstractStringType\n{\n    public static function isValid( int $value ): bool\n    {\n        return $value \u003e 0;\n    }\n}\n$quantityOfFirstItem  = new Quantity( 2 );\n$quantityOfSecondItem = new Quantity( 5 );\n\n$totalQuantity = $quantityOfFirstItem-\u003eadd( $quantityOfSecondItem ); //7\n$difference    = $quantityOfFirstItem-\u003esubtract( $quantityOfSecondItem ); //throws ValidationException\n$difference    = $quantityOfSecondItem-\u003esubtract( $quantityOfFirstItem ); //3\n\n$incrementedQuantity = $quantityOfFirstItem-\u003eincrement( $quantityOfSecondItem ); //7\n````\n\nMan kann auch mit primitiven Datentypen rechnen.\n\n````PHP\n$quantity  = new Quantity( 2 );\n\n$totalQuantity = $quantity-\u003eadd( 5 ); //7\n$difference    = $quantity-\u003esubtract( 5 ); //-3\n\n$incrementedQuantity = $quantity-\u003eincrement( 10 ); //12\n````\n\n### Eigene Uuid4-Typen\n\n````PHP\nclass FulfillmentId extends Uuid4\n{\n}\n\n$fulfillmentId        = FulfillmentId::generate(); //some UUID4\n$anotherFulfillmentId = new FulfillmentId( '9b856c0e-610a-4e38-9ea6-b9ac63cfb521' ); \n````\n\n### Uuid4\n\n````PHP\n$uuid4 = (string)Uuid4::generate();\n````\n\n### Additional methods provided by trait RepresentingStringType and so also by AbstractStringType\n\n* `getLength`\n* `contains`\n* `split`\n* `splitRaw`\n* `matchRegularExpression`\n\n### Additional methods provided by AbstractStringType\n\n* `trim`\n* `replace`\n* `substring`\n* `toLowerCase`\n* `toUpperCase`\n* `capitalizeFirst`\n* `deCapitalizeFirst`\n* `toKebabCase`\n* `toSnakeCase`\n* `toUpperCamelCase`\n* `toLowerCamelCase`\n\n### DateType\n\n````PHP\nclass UpdatedOn extends AbstractDateType\n{\n    public static function isValid( \\DateTimeInterface $value ): bool\n    {\n        return true;\n    }\n}\n\n$updatedOn = new UpdatedOn('2023-07-07 08:01:20', new \\DateTimeZone( '+0200' ) ))-\u003etoString() ); //some UUID4\n$updatedOn-\u003ehasExpired(); //Checks if current date time is greater than date time of UpdatedOn. Returns boolean\n$updatedOn-\u003ehasExpired( new \\DateInterval('PT15M') ); //Checks if current date time is greater than date time of UpdatedOn and added \\DateInterval. Returns boolean\n````\n### RepresentsDateType extends following interfaces\n\n* `\\Stringable`\n* `\\JsonSerializable`\n\n### Methods provided by RepresentsDateType\n\n* `equals`\n* `equalsValue`\n* `toDateTime`\n* `sub`\n* `add`\n* `diff`\n* `isLessThan`\n* `isGreaterThan`\n* `isGreaterThanOrEqual`\n* `isLessThanOrEqual`\n* `hasExpired`\n* `format`\n* `getOffset`\n* `getTimestamp`\n* `getTimezone`\n* `toString`\n\n## Helpers\n\n`TypesToArrayHelper` kann benutzt werden, um aus Arrays, bestehend aus StringTypes, FloatTypes, IntTypes oder ArrayTypes, Arrays mit primitiven Datentypen zu bauen.\n\nBeispiel:\n\n````PHP\n$types = [\n    new AnyStringType( 'one' ),\n    new AnyStringType( 'two' ),\n    new AnotherStringType( 'three' ),\n];\n\nTypesToArrayHelper::toStringArray( $types ); // [ 'one', 'two', 'three' ]\n````\n\n## Json\n\nAlle Typen implementieren `\\JsonSerializable` und können damit mit `json_encode` serialisiert werden.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffortuneglobe%2Ftypes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffortuneglobe%2Ftypes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffortuneglobe%2Ftypes/lists"}