{"id":31768955,"url":"https://github.com/czproject/type-system","last_synced_at":"2026-01-20T16:26:36.400Z","repository":{"id":311202605,"uuid":"888963355","full_name":"czproject/type-system","owner":"czproject","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-22T10:45:04.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-10T02:25:00.437Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/czproject.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"license.md","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},"funding":{"custom":"https://www.janpecha.cz/donate/"}},"created_at":"2024-11-15T10:44:22.000Z","updated_at":"2025-08-22T10:37:23.000Z","dependencies_parsed_at":"2025-08-22T20:17:36.377Z","dependency_job_id":"900deff0-296f-49f1-8385-ce227c81be2d","html_url":"https://github.com/czproject/type-system","commit_stats":null,"previous_names":["czproject/type-system"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/czproject/type-system","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czproject%2Ftype-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czproject%2Ftype-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czproject%2Ftype-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czproject%2Ftype-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/czproject","download_url":"https://codeload.github.com/czproject/type-system/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czproject%2Ftype-system/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28607032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T16:10:39.856Z","status":"ssl_error","status_checked_at":"2026-01-20T16:10:39.493Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2025-10-10T02:24:19.531Z","updated_at":"2026-01-20T16:26:36.374Z","avatar_url":"https://github.com/czproject.png","language":"PHP","funding_links":["https://www.janpecha.cz/donate/"],"categories":[],"sub_categories":[],"readme":"# CzProject\\TypeSystem\n\n[![Build Status](https://github.com/czproject/type-system/workflows/Build/badge.svg)](https://github.com/czproject/type-system/actions)\n[![Downloads this Month](https://img.shields.io/packagist/dm/czproject/type-system.svg)](https://packagist.org/packages/czproject/type-system)\n[![Latest Stable Version](https://poser.pugx.org/czproject/type-system/v/stable)](https://github.com/czproject/type-system/releases)\n[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/czproject/type-system/blob/master/license.md)\n\nAbstraction for PHP type system.\n\n\u003ca href=\"https://www.janpecha.cz/donate/\"\u003e\u003cimg src=\"https://buymecoffee.intm.org/img/donate-banner.v1.svg\" alt=\"Donate\" height=\"100\"\u003e\u003c/a\u003e\n\n\n## Installation\n\n[Download a latest package](https://github.com/czproject/type-system/releases) or use [Composer](http://getcomposer.org/):\n\n```\ncomposer require czproject/type-system\n```\n\nCzProject\\TypeSystem requires PHP 7.4 or later.\n\n\n## Usage\n\n``` php\nuse CzProject\\TypeSystem\\Types;\n\nTypes::scalar();\nTypes::integer();\nTypes::float();\nTypes::string();\nTypes::nonEmptyString();\nTypes::bool();\nTypes::true();\nTypes::false();\nTypes::null();\nTypes::object(\\DateTimeImmutable::class);\nTypes::union(Types::string(), Types::integer(), Types::bool());\nTypes::nullable(Types::string());\nTypes::listOf(Types::string());\n```\n\nAll types implement interface `Type`.\n\n\n### Casting\n\n```php\nuse CzProject\\TypeSystem\\Types;\n\n$castedValue = Types::scalar()-\u003ecastValue($value);\n$castedValue = Types::integer()-\u003ecastValue($value);\n$castedValue = Types::float()-\u003ecastValue($value);\n$castedValue = Types::string()-\u003ecastValue($value);\n$castedValue = Types::nonEmptyString()-\u003ecastValue($value);\n$castedValue = Types::bool()-\u003ecastValue($value);\n$castedValue = Types::true()-\u003ecastValue($value);\n$castedValue = Types::false()-\u003ecastValue($value);\n$castedValue = Types::null()-\u003ecastValue($value);\n$castedValue = Types::object(\\DateTimeImmutable::class)-\u003ecastValue($value);\n$castedValue = Types::union(Types::string(), Types::integer(), Types::bool())-\u003ecastValue($value);\n$castedValue = Types::nullable(Types::string())-\u003ecastValue($value);\n$castedValue = Types::listOf(Types::string())-\u003ecastValue($value);\n```\n\nOr you can use simplified casting helper:\n\n```php\nuse CzProject\\TypeSystem\\Cast;\n\n$castedValue = Cast::scalar($value);\n$castedValue = Cast::integer($value);\n$castedValue = Cast::integerOrNull($value);\n$castedValue = Cast::float($value);\n$castedValue = Cast::floatOrNull($value);\n$castedValue = Cast::string($value);\n$castedValue = Cast::stringOrNull($value);\n$castedValue = Cast::nonEmptyString($value);\n$castedValue = Cast::nonEmptyStringOrNull($value);\n$castedValue = Cast::bool($value);\n$castedValue = Cast::boolOrNull($value);\n```\n\nEvery type throws `SorryNonConvertableValue` exception for non convertable values.\n\n```php\n\ttry {\n\t\tTypes::string()-\u003ecastValue($value); // or Cast::string($value)\n\n\t} catch (CzProject\\TypeSystem\\SorryNonConvertableValue $e) {\n\t\tvar_dump($e-\u003egetValue());\n\t\tvar_dump($e-\u003egetType());\n\t}\n```\n\n\n### Value validation\n\nChecks if value is exactly of specific type.\n\n\n```php\nuse CzProject\\TypeSystem\\Types;\n\n$isValid = Types::scalar()-\u003eisValueValid($value);\n$isValid = Types::integer()-\u003eisValueValid($value);\n$isValid = Types::float()-\u003eisValueValid($value);\n$isValid = Types::string()-\u003eisValueValid($value);\n$isValid = Types::nonEmptyString()-\u003eisValueValid($value);\n$isValid = Types::bool()-\u003eisValueValid($value);\n$isValid = Types::true()-\u003eisValueValid($value);\n$isValid = Types::false()-\u003eisValueValid($value);\n$isValid = Types::null()-\u003eisValueValid($value);\n$isValid = Types::object(\\DateTimeImmutable::class)-\u003eisValueValid($value);\n$isValid = Types::union(Types::string(), Types::integer(), Types::bool())-\u003eisValueValid($value);\n$isValid = Types::nullable(Types::string())-\u003eisValueValid($value);\n$isValid = Types::listOf(Types::string())-\u003eisValueValid($value);\n```\n\n------------------------------\n\nLicense: [New BSD License](license.md)\n\u003cbr\u003eAuthor: Jan Pecha, https://www.janpecha.cz/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fczproject%2Ftype-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fczproject%2Ftype-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fczproject%2Ftype-system/lists"}