{"id":36976731,"url":"https://github.com/preprocess/pre-prop-types","last_synced_at":"2026-01-13T22:45:01.684Z","repository":{"id":57044414,"uuid":"175695837","full_name":"preprocess/pre-prop-types","owner":"preprocess","description":"Prop type validators for Phpx components","archived":false,"fork":false,"pushed_at":"2023-04-30T16:11:39.000Z","size":26,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-27T16:21:56.492Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/preprocess.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":"code-of-conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-14T20:39:00.000Z","updated_at":"2020-03-01T03:35:16.000Z","dependencies_parsed_at":"2022-08-24T04:50:19.360Z","dependency_job_id":null,"html_url":"https://github.com/preprocess/pre-prop-types","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/preprocess/pre-prop-types","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preprocess%2Fpre-prop-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preprocess%2Fpre-prop-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preprocess%2Fpre-prop-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preprocess%2Fpre-prop-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/preprocess","download_url":"https://codeload.github.com/preprocess/pre-prop-types/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preprocess%2Fpre-prop-types/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28403331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"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":"2026-01-13T22:45:00.903Z","updated_at":"2026-01-13T22:45:01.672Z","avatar_url":"https://github.com/preprocess.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Prop Types\n\n[![Support on Gitstore](https://enjoy.gitstore.app/repositories/badge-preprocess/pre-prop-types.svg)](https://enjoy.gitstore.app/repositories/preprocess/pre-prop-types)\n\nThis is a PHP take on the ReactJS Prop Types checking. I made it because I wanted an easier way to validate the type and presence of properties in Phpx components.\n\n## Getting started\n\n```\ngit clone git@github.com:preprocess/pre-prop-types.git\ncd pre-prop-types\ncomposer install\ncomposer test\n```\n\n## Defining types\n\nWe support most of the built-in types:\n\n```php\nuse App\\Profile;\nuse Pre\\PropTypes;\n\n$profile = Profile::find(1);\n\n$definitions = [\n    \"name\" =\u003e PropTypes::string()-\u003eisRequired(),\n    \"age\" =\u003e PropTypes::int(),\n    \"rating\" =\u003e PropTypes::float(),\n    \"permissions\" =\u003e PropTypes::arrayOf(PropTypes::string()),\n    \"thumbnail\" =\u003e PropTypes::either(\n        PropTypes::string(), // uri\n        PropTypes::resource(), // file handle\n    ),\n    \"profile\" =\u003e PropTypes::objectOf(Profile::class)-\u003eisRequired(),\n    \"onMessage\" =\u003e PropTypes::closure()-\u003eisRequired(),\n    \"isAdmin\" =\u003e PropTypes::bool()-\u003eisRequired(),\n];\n\n$properties = [\n    \"name\" =\u003e \"Joe\",\n    \"profile\" =\u003e $profile,\n    \"onMessage\" =\u003e function($message) use ($profile) {\n        $profile-\u003enotify($message);\n    },\n    \"isAdmin\" =\u003e false,\n];\n\ntry {\n    PropTypes::validate($definitions, $properties);\n} catch (InvalidArgumentException $e) {\n    // ...handle the error\n}\n```\n\n-   `isRequired` will ensure the value is present in the accompanying properties array\n-   `either` allows one or more types (preferably two distinct types) for comparison\n\nThere are also variations on these:\n\n-   `PropTypes::array()` expects any array values, without a specific type\n-   `PropTypes::boolean()` is the same as `PropTypes::bool()`\n-   `PropTypes::integer()` is the same as `PropTypes::int()`\n-   `PropTypes::double()` expects double values\n-   `PropTypes::iterable()` expects any iterable values\n-   `PropTypes::numeric()` expects any numeric values\n-   `PropTypes::object()` expects any object values, without a specific type\n\n## Validating types\n\nWe don't automatically validate props – this must be done by the consumer. And example Phpx render method demonstrates this:\n\n```php\nuse Pre\\PropTypes;\nuse function Pre\\Phpx\\Html\\render as renderHTML;\n\nfunction render($type, $props = [])\n{\n    $props = (array) $props;\n\n    if (class_exists($type)) {\n        if (method_exists($type, \"propTypes\")) {\n            PropTypes::validate($type::propTypes(), $props);\n        }\n\n        if (method_exists($type, \"defaultProps\")) {\n            $props = array_merge($type::defaultProps(), $props);\n        }\n    }\n\n    return renderHTML($type, $props);\n}\n\nrender(\"App\\\\Custom\\\\Component\");\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpreprocess%2Fpre-prop-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpreprocess%2Fpre-prop-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpreprocess%2Fpre-prop-types/lists"}