{"id":25553916,"url":"https://github.com/prezly/prop-types-php","last_synced_at":"2025-04-11T22:51:12.736Z","repository":{"id":57044573,"uuid":"199718101","full_name":"prezly/prop-types-php","owner":"prezly","description":"Complete PHP port of React PropTypes","archived":false,"fork":false,"pushed_at":"2023-10-05T13:37:35.000Z","size":75,"stargazers_count":7,"open_issues_count":2,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-11T22:09:55.364Z","etag":null,"topics":["php","prop-types","prop-types-php","type-check","validation"],"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/prezly.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-07-30T19:54:06.000Z","updated_at":"2023-10-09T01:04:22.000Z","dependencies_parsed_at":"2022-08-24T04:11:15.276Z","dependency_job_id":"3ed54612-de2b-4171-bcb4-859715137001","html_url":"https://github.com/prezly/prop-types-php","commit_stats":{"total_commits":80,"total_committers":4,"mean_commits":20.0,"dds":0.09999999999999998,"last_synced_commit":"943c919907b1dfac7a3641b84e5f74da4f48d70a"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prezly%2Fprop-types-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prezly%2Fprop-types-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prezly%2Fprop-types-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prezly%2Fprop-types-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prezly","download_url":"https://codeload.github.com/prezly/prop-types-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248492986,"owners_count":21113161,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["php","prop-types","prop-types-php","type-check","validation"],"created_at":"2025-02-20T12:03:18.788Z","updated_at":"2025-04-11T22:51:12.711Z","avatar_url":"https://github.com/prezly.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PropTypes.php\n\nComplete PHP port of [React PropTypes](https://github.com/facebook/prop-types).\n\nRuntime type checking for complex properties structures.\n\nYou can use prop-types to document the intended types of properties passed into your code. PropTypes will check props passed to your functions against those definitions, and throw an error if they don’t match.\n\n\u003cimg src=\"https://github.com/prezly/prop-types-php/workflows/Test/badge.svg\" alt=\"Build status\"\u003e\n\n## Installation\n\n```\ncomposer require prezly/prop-types\n```\n\n## Usage\n\nPropTypes was originally exposed as part of the React core module, and is commonly used with React components. \nWe've tried to bring the familiarity of React PropTypes into PHP. \n\nYou can call `PropTypes::check()` to validate an array of props, providing it with a props spec as below:\n\n```php\n\u003c?php\n\nuse Prezly\\PropTypes\\Exceptions\\PropTypeException;\nuse Prezly\\PropTypes\\PropTypes;\n\nfunction myFunction(array $options): void\n{\n    PropTypes::check([\n        // You can declare that a prop has a specific type.\n        // By default, these are all required and not nullable.\n        'requiredFoo' =\u003e PropTypes::equals('foo'),\n        'requiredArray' =\u003e PropTypes::array(),\n        'requiredBool' =\u003e PropTypes::bool(),\n        'requiredInteger' =\u003e PropTypes::int(),\n        'requiredFloat' =\u003e PropTypes::float(),\n        'requiredObject' =\u003e PropTypes::object(),\n        'requiredString' =\u003e PropTypes::string(),\n        // You can also declare that a prop is an instance of a class.\n        // This uses `instanceof` operator.\n        'requiredDateTime' =\u003e PropTypes::instanceOf(DateTime::class),\n        // You can ensure that your prop is limited to specific values\n        // by treating it as an enum.\n        'requiredEnum' =\u003e PropTypes::oneOf(['News', 'Photos']),\n        // An object that could be one of many types\n        'requiredUnion' =\u003e PropTypes::oneOfType([\n            PropTypes::string(),\n            PropTypes::int(),\n            PropTypes::instanceOf(DateTime::class),\n        ]),\n        'requiredCallable' =\u003e PropTypes::callable(),\n\n        // An array of a certain type\n        'requiredArrayOf' =\u003e PropTypes::arrayOf(PropTypes::int()),\n\n        // You can chain any of the above with `isOptional()`\n        // to make sure an error is not thrown if the prop isn't provided.\n\n        // An object taking on a particular shape\n        'requiredArrayWithShape' =\u003e PropTypes::shape([\n            'requiredProperty' =\u003e PropTypes::int(),\n            'optionalProperty' =\u003e PropTypes::string()-\u003eisOptional(),\n        ]),\n\n        // An object with errors on extra properties\n        'requiredObjectWithStrictShape' =\u003e PropTypes::exact([\n            'requiredProperty' =\u003e PropTypes::int(),\n            'optionalProperty' =\u003e PropTypes::string()-\u003eisOptional(),\n        ]),\n    \n        // You can chain any of the above with `isNullable()`\n        // to allow passing `null` as a value.\n\n        'requiredNullableString' =\u003e PropTypes::string()-\u003eisNullable(),\n        'optionalNullableString' =\u003e PropTypes::string()-\u003eisNullable()-\u003eisOptional(),\n        \n        // A value of any data type (except null)\n        'requiredAny' =\u003e PropTypes::any(),\n        // A value of any data type (including null)\n        'requiredNullableAny' =\u003e PropTypes::any()-\u003eisNullable(),\n\n        // You can also specify a custom validator.\n        // It should *return* a PropTypeException instance if the validation fails.\n        'customProp' =\u003e PropTypes::callback(\n            function (array $props, string $prop_name, string $prop_full_name): ?PropTypeException {\n                if (! preg_match('/matchme /', $props[$prop_name])) {\n                    return new PropTypeException(\n                        $prop_name,\n                        'Invalid prop `' . $prop_full_name . '` supplied. Validation failed.'\n                    );\n                }\n                return null;\n            }\n        ),\n\n        // You can also supply a custom validator to `arrayOf` and `objectOf`.\n        // It should return an Error object if the validation fails. The validator\n        // will be called for each key in the array or object. The first two\n        // arguments of the validator are the array or object itself, and the\n        // current item's key.\n        'customArrayProp' =\u003e PropTypes::arrayOf(\n            PropTypes::callback(function (array $props, string $prop_name, string $prop_full_name) {\n                if (! preg_match('/matchme /', $props[$prop_name])) {\n                    return new PropTypeException(\n                        $prop_name,\n                        'Invalid prop `' . $prop_full_name . '` supplied. Validation failed.'\n                    );\n                }\n                return null;\n            })\n        ),\n    ], $options);\n}\n```\n\n## Difference from React PropTypes\n\n1. In this package we've split *optional* and *nullabe* checks into different traits:\n   - *Optional* means a property can be omitted from the props object  \n   - *Nullable* means a property value can be set to `null`  \n   \n   React PropTypes has less straightforward logic around required, nulls and undefined.\n   \n2. As opposed to React PropTypes we don't have a separate checker for null (`PropTypes::null()`).\n   Instead any property can become nullable by calling `-\u003eisNullable()` on its checker:\n   \n   ```php\n   [\n      'title' =\u003e PropTypes::string()-\u003eisNullable(),\n   ]\n   ```\n   \n3. Unlike React PropTypes, all properties are *required* by default (meaning they cannot be omitted).\n   Unless `isOptional()` is explicitly called on its type checker. \n\n   This is done this way to closer match native PHP language semantics.\n\n## Changelog\n\nAll notable changes to this project will be documented in the [CHANGELOG](./CHANGELOG) file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n-----------------\n\nBrought to you with :heart: by [Prezly](https://www.prezly.com/?utm_source=github\u0026utm_campaign=prop-types-php).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprezly%2Fprop-types-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprezly%2Fprop-types-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprezly%2Fprop-types-php/lists"}